feat(go): added experimental ways to define tools, interrupts, and streaming#4797
feat(go): added experimental ways to define tools, interrupts, and streaming#4797apascal07 wants to merge 8 commits intoap/go-session-flowfrom
Conversation
Summary of ChangesHello @apascal07, 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 introduces experimental features to the Genkit Go SDK, focusing on enhancing the flexibility and control over tool definitions and their execution. It provides developers with more streamlined function signatures for tools, the ability to produce multipart responses, and a robust mechanism for interrupting and resuming tool execution, particularly useful for interactive scenarios requiring user input or confirmation. These changes aim to simplify tool development and enable more complex agent behaviors. 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. Changelog
Activity
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.
Code Review
This pull request introduces an excellent experimental feature for defining tools with simplified signatures and interrupt capabilities. The new tool and aix packages are well-designed, and the sample application effectively demonstrates the new functionality. My review includes suggestions to enhance error handling, improve maintainability in the sample code, and correct a documentation example. Overall, this is a valuable addition to the library.
Adds experimental tool definition APIs (
ai/x) with simplified function signatures, typed interrupt/resume, and a runtime helper package for use inside tool functions.These APIs are designed to replace the existing
DefineToolandDefineMultipartToolin a future major release. The current implementation wraps the existing tool infrastructure for backwards compatibility, but the intent is to invert this -- the new APIs will become the primary implementation and the old ones will be removed.Examples
Simple Tools
The new
DefineTool(experimentally asDefineXTool) replaces bothDefineToolandDefineMultipartToolwith a single API. The function receives a plaincontext.Contextinstead ofai.ToolContext, making tool functions easier to write and test. Multipart responses are handled viatool.AttachPartsrather than requiring a separate function signature:Use
tool.AttachPartsto return additional content (images, media) without changing the function signature:Partial Tool Responses (Streaming Progress)
Tools can stream partial responses during execution for client-side display (e.g., progress indicators). Use
tool.SendPartialinside any tool function -- it's best-effort and no-ops when streaming isn't available.Define a status type shared between the tool and client:
Send partial responses from the tool:
On the client side, partial tool responses arrive as
ModelResponseChunks during streaming. UsePart.IsPartial()to distinguish progress updates from final tool results:Interruptible Tools
DefineInterruptibleTooladds typed interrupt/resume for human-in-the-loop workflows. The function receives a*Resparameter that is non-nil when the tool is being re-executed after an interrupt. LikeDefineXTool, multipart responses are supported viatool.AttachParts:Handle the interrupt on the caller side. Use
transferTool.Resumefor typed, compile-time-checked resume data:Or respond with a pre-computed result instead of re-executing the tool:
When the caller does not have access to the tool definition (e.g., in a generic interrupt handler), use the definition-free helpers
tool.Resumeandtool.Respond:Agent Flows with Interrupts
Interruptible tools integrate naturally with
DefinePromptAgent. The agent streams interrupts to the client, and the client handles user interaction and sends resume data back:API Reference
Runtime Helpers (
ai/x/tool-- experimental)The
toolpackage provides functions for use inside tool functions:Partial Tool Response Helpers (
aipackage)Tool Definitions (
ai/x-- experimental)Define & Register
Create Without Registering
Genkit Convenience Functions
Function Signatures
InterruptibleTool[In, Out, Res]
Tool[In, Out]
Implements
ai.Tool-- usable anywhere a tool is accepted (ai.WithTools, etc.).