-
Notifications
You must be signed in to change notification settings - Fork 645
RFC: [Go] BidiAction, BidiFlow, BidiModel, and Agent
#4184
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?
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 a detailed design document for enhancing Genkit Go with robust bidirectional streaming capabilities. It proposes three new core primitives: 'BidiAction' for fundamental streaming operations, 'BidiFlow' for observable streaming, and 'SessionFlow' for managing stateful, multi-turn interactions with automatic persistence. The document comprehensively covers the API surface, integration with existing tracing and session management infrastructure, and provides concrete examples to guide implementation and usage, aiming to facilitate the development of advanced conversational agents and streaming applications. 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 introduces a comprehensive design document for new bidirectional streaming features in Genkit Go, including BidiAction, BidiFlow, and SessionFlow. The document is well-structured and detailed. My review focuses on ensuring the clarity and consistency of the proposed design. I've identified a significant contradiction in the description of the Stream() method's behavior which could lead to implementation errors. I've also suggested a clarification in one of the code examples to improve understanding of the multi-turn flow. Overall, this is a solid design that will be even stronger with these clarifications.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
BidiAction, BidiFlow, and SessionFlowBidiAction, BidiFlow, and SessionFlow
BidiAction, BidiFlow, and SessionFlowBidiAction, BidiFlow, and SessionFlow
docs/go-bidi-design.md
Outdated
| } | ||
|
|
||
| // SessionFlowOutput wraps the output with session info for persistence. | ||
| type SessionFlowOutput[State, Out any] struct { |
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.
Let's define these as common schemas (in genkit-tools/common/src/types) standardized across runtimes.
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 tend to agree but we haven't been doing the core concepts (action, etc) as generated types because they have type parameters and they're just "core" to the runtime and sometimes implemented differently. But Artifact I 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.
In Go, we only generate types for the ai package. Not for any technical reason but that's just been the use case since they tend to be POD structs.
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 mean, we literally must define these types in genkit-tools/common/src/types because we will be building Dev UI agent playground. So, not only we need zod types for the Dev UI, we also need those types to be the same across languages (which generation ensures). So, I guess I don't have a strong opinion if you want to maintain these types by hand in Go, up to you, but they need to be treated as "source of truth is in genkit-tools/common".
BidiAction, BidiFlow, and SessionFlowBidiAction, BidiFlow, and Agent in Go
xavidop
left a comment
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.
Overall, while this design introduces useful primitives for bidirectional flows and persistence, it does not yet align with the agentic patterns seen in modern frameworks like LangChain or LlamaIndex. The current approach feels closer to a single, persistent agent rather than a true agent system where agents can call, delegate to, or coordinate with other agents.
A key limitation is the lack of clear multi-agent orchestration. Modern agent frameworks treat agents as composable units that can collaborate, delegate tasks, or be orchestrated in workflows.
Additionally, the API surface feels too low-level for end users. Concepts like bidirectional flows and actions require developers to manage execution mechanics explicitly. Many of these concerns should be handled by the framework itself, exposing a cleaner and more minimal interface that is easier to read, reason about, and scale over time.
This contrasts with existing patterns in Genkit JS and ADK, where agent definitions are more declarative and focused on intent rather than wiring. For reference, Genkit JS chat agents provide a much simpler mental model: https://genkit.dev/docs/tutorials/chat-with-pdf/#6-implement-the-ui, and ADK’s Go agent definitions show a clearer agent-first abstraction: https://google.github.io/adk-docs/get-started/go/#define-the-agent-code.
|
related to bidi flows: That RFC is heading in a good direction, but I wonder if we can simplify the API further. Introducing defineBidiFlow adds another concept that users need to learn and distinguish from defineFlow, which may increase cognitive load without providing a clearly different mental model. Would it be possible to support this functionality by extending defineFlow with a configuration option instead? For example, using defineFlow with a specific config to indicate bidirectional or streaming behavior would keep the API surface smaller and make it easier for users to understand what’s going on without having to learn a parallel set of abstractions. From a usability perspective, having a single defineFlow entry point feels cleaner and more consistent. |
There's not much we can do given the large differences in both flow inputs but also return type. They're distinctly different. Go is especially not flexible enough to handle things like this. |
What would you like to see here?
ADK's agent concept is closer (or almost identical) to our concept of a prompt. It doesn't provide meaningful control beyond the generation and tool calling, which we do automatically as part of either prompt or generate APIs. Agent here is more about the automatic state management, turn-based streaming chats, revertible snapshots, and more while still giving you control over being able to do anything you'd like during its lifecycle. It is meant to be lower level than other "agent" abstractions given that those map to our "prompt" abstraction. |
Thanks for the clarification, that helps, and I think we’re generally aligned on the intent of this abstraction being lower-level. My main point isn’t about whether this primitive should exist, but about how easy it is to build more agentic patterns on top of it. With the current pattern, it’s somewhat hard to express agents where the agent itself decides which sub-agent or capability should run next (for example, supervisor, router, or planner-style agents). While this is definitely possible, it tends to require a fair amount of additional orchestration code, which can make these patterns less straightforward to implement and reason about. One of the things I really appreciate about Genkit is that it’s clean, easy to use, and largely self-explainable. From experience working on teams that build AI agents in production, I’ve often seen that when users need to write a lot of glue code to express common patterns, they either look at other frameworks or end up building their own abstractions on top. What I’d love to see here is a slightly cleaner way to express common agentic patterns where delegation and routing are easier to model. Even if this remains a low-level abstraction, having some framework-supported patterns or helpers could reduce boilerplate and make these use cases more approachable. Overall, I think this is a useful direction, and with a bit more support for agent-driven orchestration, it could fit very nicely with Genkit’s philosophy and developer experience. |
BidiAction, BidiFlow, and Agent in GoBidiAction, BidiFlow, BidiModel, and Agent
No description provided.