-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix #906: Add websocket tool response examples and documentation #1075
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?
Fix #906: Add websocket tool response examples and documentation #1075
Conversation
…entation - Add complete working example: Websocket_Tool_Call_Response_Example.py - Add comprehensive documentation: WEBSOCKET_TOOL_RESPONSE_FIX.md - Document two working formats for tool responses via websockets - Clarify BidiGenerateContentToolResponse confusion - Include examples for function calling with websockets - Add error handling and multiple function call examples Resolves google-gemini#906
Summary of ChangesHello @Solventerritory, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves issue #906 by providing clear, actionable guidance and working examples for handling function/tool call responses with the Gemini Live API over websockets. It addresses the previous lack of explicit documentation on the correct message formats, which often led to connection issues. The changes include a new Markdown document detailing two effective response methods and a comprehensive Python example that can be run directly to illustrate the solution. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request is a great addition, providing much-needed documentation and a working example for using websockets with tool calling. The Python script is clear and the markdown file is very helpful. I've added a few suggestions to improve the script's maintainability and robustness, and to align the documentation with the repository's style guide.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Change all headings to sentence case per style guide - Make model name a command-line argument with --model flag - Add default value of gemini-2.0-flash-live-001 - Update function signatures to pass model parameter
Hey! This fixes issue #906.
I ran into the same problem many others reported: the docs mention
BidiGenerateContentToolResponse, but they don’t clearly show how to format a tool response when using WebSockets. I tried several approaches, but the WebSocket kept closing unexpectedly.WHAT I ADDED
Two files to make WebSocket function calling actually usable end-to-end:
A complete, runnable example. You just need to add your API key.
It shows:
A practical guide covering:
THE ACTUAL SOLUTION
There are two formats that work for sending tool responses over WebSockets.
OPTION 1 (used in the cookbook examples)
OPTION 2 (based on @nmfisher’s workaround in the issue)
Both formats work reliably. I’ve been using Option 1 since it matches the cookbook examples.
WHAT DOES NOT WORK
The following consistently caused failures or WebSocket closures:
TESTED SCENARIOS
Tested with: