-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Decouple model_context from AssistantAgent #4681
base: main
Are you sure you want to change the base?
Conversation
@microsoft-github-policy-service agree |
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 reviewed 1 out of 1 changed files in this pull request and generated no suggestions.
Comments skipped due to low confidence (1)
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py:317
- The error message 'No tools are available.' could be more descriptive. Consider changing it to 'No tools or handoff tools are available for execution.'
raise ValueError("No tools are available.")
@@ -215,12 +227,14 @@ def __init__( | |||
self, | |||
name: str, | |||
model_client: ChatCompletionClient, | |||
model_context: ChatCompletionContext = BufferedChatCompletionContext(0), |
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.
To match previous behavior you want an unbounded buffered context, this change has a buffer size of zero
We can either add the ability for the buffer to be unbounded or we can add a new impl that supports this.
@ekzhu thoughts?
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 the default setting should be None. And for default we create a buffered context that is unbounded. But I am up for alternative ideas as well such as toke-limited context, using the context size information from model client.
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.
if I understand correctly, setting up buffer_size to 0 will make the BufferedChatCompletionContext to be unbounded since the only time it's being used is in
messages = self._messages[-self._buffer_size :]
is my understanding correct? or it's just better to create a different class for unbounded?
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.
Interesting, I think that's a bug in the model context since the documented contract is that that parameter is the buffer size. Ie number of messages contained in the buffer
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 created a different class for unbounded. Could you please have a look when you have time?
|
||
async def save_state(self) -> Mapping[str, Any]: | ||
"""Save the current state of the assistant agent.""" | ||
return AssistantAgentState(llm_messages=self._model_context.copy()).model_dump() | ||
return AssistantAgentState(llm_messages=await self._model_context.get_messages()).model_dump() |
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.
The get_messages method won't return all the messages. Here we should be using the model context's save and load state methods.
If we don't have them we should create them.
…ntext behaviour on AssistantAgent
Why are these changes needed?
This is to decouple model_context from AssistantAgent to provide flexibility in augmenting incoming message to the agent. This could be useful when we have a specific template for an agent that is a part of a GroupChat, discussion here: #4668
Related issue number
Checks