@@ -242,6 +242,100 @@ async def code_interpreter_example():
242242 print (result.text)
243243```
244244
245+ ### File Search
246+
247+ Enable your assistant to search through uploaded documents:
248+
249+ ``` python
250+ from agent_framework import HostedFileSearchTool, HostedVectorStoreContent
251+
252+ async def file_search_example ():
253+ client = OpenAIAssistantsClient()
254+
255+ # Create a vector store with documents
256+ file = await client.client.files.create(
257+ file = (" knowledge.txt" , b " The weather today is sunny with a high of 75F." ),
258+ purpose = " user_data"
259+ )
260+ vector_store = await client.client.vector_stores.create(
261+ name = " knowledge_base" ,
262+ expires_after = {" anchor" : " last_active_at" , " days" : 1 },
263+ )
264+ await client.client.vector_stores.files.create_and_poll(
265+ vector_store_id = vector_store.id,
266+ file_id = file .id
267+ )
268+
269+ try :
270+ async with client.create_agent(
271+ name = " KnowledgeBot" ,
272+ instructions = " You are a helpful assistant that searches files in a knowledge base." ,
273+ tools = HostedFileSearchTool(
274+ vector_stores = [HostedVectorStoreContent(vector_store_id = vector_store.id)]
275+ ),
276+ ) as agent:
277+ result = await agent.run(" What does the document say about weather?" )
278+ print (result.text)
279+ finally :
280+ # Cleanup
281+ await client.client.vector_stores.delete(vector_store.id)
282+ await client.client.files.delete(file .id)
283+ ```
284+
285+ ### Thread Management
286+
287+ Maintain conversation context across multiple interactions:
288+
289+ ``` python
290+ from agent_framework import AgentThread
291+
292+ async def thread_example ():
293+ async with OpenAIAssistantsClient().create_agent(
294+ name = " Assistant" ,
295+ instructions = " You are a helpful assistant." ,
296+ ) as agent:
297+ # Create a persistent thread for conversation context
298+ async with AgentThread() as thread:
299+ # First interaction
300+ result1 = await agent.run(" My name is Alice" , thread = thread)
301+ print (f " Agent: { result1.text} " )
302+
303+ # Second interaction - agent remembers the context
304+ result2 = await agent.run(" What's my name?" , thread = thread)
305+ print (f " Agent: { result2.text} " ) # Should remember "Alice"
306+ ```
307+
308+ ### Working with Existing Assistants
309+
310+ You can reuse existing OpenAI assistants by providing their IDs:
311+
312+ ``` python
313+ from openai import AsyncOpenAI
314+
315+ async def existing_assistant_example ():
316+ # Create OpenAI client directly
317+ client = AsyncOpenAI()
318+
319+ # Create or get an existing assistant
320+ assistant = await client.beta.assistants.create(
321+ model = " gpt-4o-mini" ,
322+ name = " WeatherAssistant" ,
323+ instructions = " You are a weather forecasting assistant."
324+ )
325+
326+ try :
327+ # Use the existing assistant with Agent Framework
328+ async with OpenAIAssistantsClient(
329+ async_client = client,
330+ assistant_id = assistant.id
331+ ).create_agent() as agent:
332+ result = await agent.run(" What's the weather like in Seattle?" )
333+ print (result.text)
334+ finally :
335+ # Clean up the assistant
336+ await client.beta.assistants.delete(assistant.id)
337+ ```
338+
245339### Streaming Responses
246340
247341Get responses as they are generated for better user experience:
0 commit comments