-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Improve docs with examples on custom agentchat agents with model clients and serialization #5468
base: main
Are you sure you want to change the base?
Conversation
…and serialization #5450
…ogen into custom_agentchat_update_vd
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5468 +/- ##
==========================================
+ Coverage 78.32% 78.33% +0.01%
==========================================
Files 165 165
Lines 9800 9800
==========================================
+ Hits 7676 7677 +1
+ Misses 2124 2123 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -111,11 +111,13 @@ tutorial/state | |||
:hidden: | |||
:caption: Advanced | |||
tutorial/custom-agents |
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.
we can move the location of custom-agents.ipynb
to the parent folder. Then add a new redirect entry in the conf.py: https://github.com/microsoft/autogen/blob/main/python/packages/autogen-core/docs/src/conf.py#L175-L176
" ):\n", | ||
" super().__init__(name=name, description=description)\n", | ||
" self._model_context = UnboundedChatCompletionContext()\n", | ||
" self._model_client = genai.Client(api_key=api_key)\n", |
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 generally it is a good idea to pass the gemini client through the constructor. This is the convention we use for other agents, also it allows the client to be shared.
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.
Also we need to update the uv.lock file as now the notebook depends on the google package.
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 generally it is a good idea to pass the gemini client through the constructor. This is the convention we use for other agents, also it allows the client to be shared.
Oh I see, you did this because the gemini client isn't serializable... I guess it's fine then.
" async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:\n", | ||
" async for message in self.on_messages_stream(messages, cancellation_token):\n", | ||
" if isinstance(message, Response):\n", | ||
" return message\n", |
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.
Returnning within the generator can cause the generator itself not properly closed -- it has async tasks associated with it. Let the generator context close first then return the result.
" await self._model_context.add_message(UserMessage(content=msg.content, source=msg.source))\n", | ||
"\n", | ||
" # Get conversation history\n", | ||
" history = [\n", |
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 Gemini supports chat messages right? https://ai.google.dev/gemini-api/docs/text-generation?lang=python#chat
For this example we don't necessarly need to use model context here. If Gemini can manage the context -- it's 1M token, we can just simplify and use the Gemini's chat feature directly.
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.
We can write in Next Step to encourage reader to try creating a custom client with function calling capability following the Gemini's API doc: https://ai.google.dev/gemini-api/docs/function-calling
This PR improves documentation on custom agents
Why are these changes needed?
Related issue number
Closes #5450
Checks