-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: Add sample on how to share a thread between agents in a workflow #3405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Python: Add sample on how to share a thread between agents in a workflow #3405
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also please add this new sample to the workflows/README.md.
|
|
||
| shared_thread = writer.get_new_thread() | ||
| # Set the message store to store messages in memory. | ||
| shared_thread.message_store = ChatMessageStore() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better way would be to initialize it via chat_message_store_factory. I noticed that this parameter exists in BaseChatClient.as_agent method, but not in AzureAIProjectAgentProvider. We can add this parameter to provider, pass it to the place where we create ChatAgent, and then in this example, when invoking create_agent, we could also pass chat_message_store_factory=ChatMessageStore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern feels a bit weird indeed. A thread is a parallel concept to agent but the chat message store live in the agent.
When I was creating the sample, my first impression was that I could pass in the message store when I call get_new_thread(). Have we considered it?
Also, the fact that we have to also set store to False to have message to actually be stored in the message store is also great.
| print(f"User: {query1}") | ||
| result1 = await agent.run(query1, thread=thread, store=False) | ||
| result1 = await agent.run( | ||
| query1, thread=thread, options=OpenAIResponsesOptions(store=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's focus on showing to avoid unnecessary concepts:
| query1, thread=thread, options=OpenAIResponsesOptions(store=False) | |
| query1, thread=thread, options={"store": False} |
|
|
||
| workflow = ( | ||
| WorkflowBuilder() | ||
| .register_agent(lambda: writer, "writer", agent_thread=shared_thread) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add some parameter names, because I have no clue what I'm reading here, when I looked up the definition it made a bit more sense, but plain reading this is hard!
| "Write a tagline for a budget-friendly eBike.", | ||
| # Keyword arguments will be passed to each agent call. | ||
| # Setting store=False to avoid storing messages in the service for this example. | ||
| options=OpenAIResponsesOptions(store=False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
Motivation and Context
Part of #761
Description
python/samples/getting_started/agents/azure_ai/azure_ai_with_thread.pywherestore=Falseno longer has effects.Contribution Checklist