Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

akurniawan
Copy link

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

@akurniawan
Copy link
Author

@akurniawan please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@rysweet rysweet requested review from ekzhu and Copilot December 12, 2024 16:22

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.")
@rysweet rysweet requested a review from jackgerrits December 12, 2024 16:25
@@ -215,12 +227,14 @@ def __init__(
self,
name: str,
model_client: ChatCompletionClient,
model_context: ChatCompletionContext = BufferedChatCompletionContext(0),
Copy link
Member

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?

Copy link
Collaborator

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.

Copy link
Author

@akurniawan akurniawan Dec 13, 2024

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?

Copy link
Member

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

Copy link
Author

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()
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants