Skip to content

Commit 0fcf075

Browse files
authored
Python: Add sample on how to share a thread between agents in a workflow (#3405)
* Add sample on how to share a thread between agents in a workflow * Fix sample * Fix formatting * Comments * comment
1 parent ff7041b commit 0fcf075

3 files changed

Lines changed: 206 additions & 94 deletions

File tree

python/samples/getting_started/agents/azure_ai/azure_ai_with_thread.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
"""
1818

1919

20-
# NOTE: approval_mode="never_require" is for sample brevity. Use "always_require" in production; see samples/getting_started/tools/function_tool_with_approval.py and samples/getting_started/tools/function_tool_with_approval_and_threads.py.
20+
# NOTE: approval_mode="never_require" is for sample brevity. Use "always_require" in production
21+
# See:
22+
# samples/getting_started/tools/function_tool_with_approval.py
23+
# samples/getting_started/tools/function_tool_with_approval_and_threads.py.
2124
@tool(approval_mode="never_require")
2225
def get_weather(
2326
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -78,19 +81,19 @@ async def example_with_thread_persistence_in_memory() -> None:
7881
# First conversation
7982
query1 = "What's the weather like in Tokyo?"
8083
print(f"User: {query1}")
81-
result1 = await agent.run(query1, thread=thread, store=False)
84+
result1 = await agent.run(query1, thread=thread, options={"store": False})
8285
print(f"Agent: {result1.text}")
8386

8487
# Second conversation using the same thread - maintains context
8588
query2 = "How about London?"
8689
print(f"\nUser: {query2}")
87-
result2 = await agent.run(query2, thread=thread, store=False)
90+
result2 = await agent.run(query2, thread=thread, options={"store": False})
8891
print(f"Agent: {result2.text}")
8992

9093
# Third conversation - agent should remember both previous cities
9194
query3 = "Which of the cities I asked about has better weather?"
9295
print(f"\nUser: {query3}")
93-
result3 = await agent.run(query3, thread=thread, store=False)
96+
result3 = await agent.run(query3, thread=thread, options={"store": False})
9497
print(f"Agent: {result3.text}")
9598
print("Note: The agent remembers context from previous messages in the same thread.\n")
9699

0 commit comments

Comments
 (0)