-
Notifications
You must be signed in to change notification settings - Fork 673
feat(go): added DefineCustomAgent and DefinePromptAgent
#4462
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
Open
apascal07
wants to merge
36
commits into
ap/go-bidi
Choose a base branch
from
ap/go-session-flow
base: ap/go-bidi
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,896
−41
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
1382035
added `SessionFlow` and related
apascal07 fe91d76
Update main.go
apascal07 ad323d2
Update main.go
apascal07 3913771
moved files
apascal07 15880f5
added `DefineSessionFlowFromPrompt`
apascal07 e94bca1
removed stream type param
apascal07 a77fa33
updates
apascal07 e83af30
cleaned up API naming and behavior
apascal07 db37102
Update action.go
apascal07 f4c4ec1
added stream capturing to output
apascal07 08b09e4
stream out interrupt chunks
apascal07 c2f55ab
Update genkit.go
apascal07 30b4afd
Update agent_flow.go
apascal07 22be814
removed get snapshot action
apascal07 a009a1b
tagged prompt messages and excluded them
apascal07 ea742d9
fixed PromptInput -> InputVariables
apascal07 2ae4bb8
added AgentFlowResult to output final artifacts
apascal07 787f61a
Update agent_flow.go
apascal07 d1281d5
removed turn index from snapshot
apascal07 d6cae44
exposed InputCh and TurnIndex on AgentSession
apascal07 10bbd03
improvements to API
apascal07 a687eb6
minor fixes
apascal07 7c535c4
Update session.go
apascal07 26f8f7d
added shared schemas for agent types
apascal07 d9c335a
Update typing.py
apascal07 fb7f254
various renames
apascal07 971b668
helper for input variables conversion
apascal07 3491761
DefinePromptAgent takes in prompt name instead of resolved prompt
apascal07 b46acce
fixed interrupts streaming
apascal07 6676882
Update genkit.go
apascal07 8d99639
added `SetMessages`
apascal07 3cbec28
added `AgentSession.Result()`
apascal07 6ac5510
moved from `ai/x` to `ai/exp`
apascal07 ac39ef9
Update agent.go
apascal07 5a671bb
added `AgentFlow.Run()` and `AgentFlow.RunText()`
apascal07 49a19eb
dedupe consecutive identical snapshots
apascal07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { z } from 'zod'; | ||
| import { MessageSchema, ModelResponseChunkSchema } from './model'; | ||
| import { PartSchema } from './parts'; | ||
|
|
||
| /** | ||
| * Zod schema for an artifact produced during a session. | ||
| */ | ||
| export const ArtifactSchema = z.object({ | ||
| /** Name identifies the artifact (e.g., "generated_code.go", "diagram.png"). */ | ||
| name: z.string().optional(), | ||
| /** Parts contains the artifact content (text, media, etc.). */ | ||
| parts: z.array(PartSchema), | ||
| /** Metadata contains additional artifact-specific data. */ | ||
| metadata: z.record(z.any()).optional(), | ||
| }); | ||
| export type Artifact = z.infer<typeof ArtifactSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for snapshot event. | ||
| */ | ||
| export const SnapshotEventSchema = z.enum(['turnEnd', 'invocationEnd']); | ||
| export type SnapshotEvent = z.infer<typeof SnapshotEventSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for session state. | ||
| */ | ||
| export const SessionStateSchema = z.object({ | ||
| /** Conversation history (user/model exchanges). */ | ||
| messages: z.array(MessageSchema).optional(), | ||
| /** User-defined state associated with this conversation. */ | ||
| custom: z.any().optional(), | ||
| /** Named collections of parts produced during the conversation. */ | ||
| artifacts: z.array(ArtifactSchema).optional(), | ||
| /** Input used for agent flows that require input variables. */ | ||
| inputVariables: z.any().optional(), | ||
| }); | ||
| export type SessionState = z.infer<typeof SessionStateSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for agent flow input (per-turn). | ||
| */ | ||
| export const AgentFlowInputSchema = z.object({ | ||
| /** User's input messages for this turn. */ | ||
| messages: z.array(MessageSchema).optional(), | ||
| /** Tool request parts to re-execute interrupted tools. */ | ||
| toolRestarts: z.array(PartSchema).optional(), | ||
| }); | ||
| export type AgentFlowInput = z.infer<typeof AgentFlowInputSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for agent flow initialization. | ||
| */ | ||
| export const AgentFlowInitSchema = z.object({ | ||
| /** Loads state from a persisted snapshot. Mutually exclusive with state. */ | ||
| snapshotId: z.string().optional(), | ||
| /** Direct state for the invocation. Mutually exclusive with snapshotId. */ | ||
| state: SessionStateSchema.optional(), | ||
| }); | ||
| export type AgentFlowInit = z.infer<typeof AgentFlowInitSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for agent flow result. | ||
| */ | ||
| export const AgentFlowResultSchema = z.object({ | ||
| /** Last model response message from the conversation. */ | ||
| message: MessageSchema.optional(), | ||
| /** Artifacts produced during the session. */ | ||
| artifacts: z.array(ArtifactSchema).optional(), | ||
| }); | ||
| export type AgentFlowResult = z.infer<typeof AgentFlowResultSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for agent flow output. | ||
| */ | ||
| export const AgentFlowOutputSchema = z.object({ | ||
| /** ID of the snapshot created at the end of this invocation. */ | ||
| snapshotId: z.string().optional(), | ||
| /** Final conversation state (only when client-managed). */ | ||
| state: SessionStateSchema.optional(), | ||
| /** Last model response message from the conversation. */ | ||
| message: MessageSchema.optional(), | ||
| /** Artifacts produced during the session. */ | ||
| artifacts: z.array(ArtifactSchema).optional(), | ||
| }); | ||
| export type AgentFlowOutput = z.infer<typeof AgentFlowOutputSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for agent flow stream chunk. | ||
| */ | ||
| export const AgentFlowStreamChunkSchema = z.object({ | ||
| /** Generation tokens from the model. */ | ||
| modelChunk: ModelResponseChunkSchema.optional(), | ||
| /** User-defined structured status information. */ | ||
| status: z.any().optional(), | ||
| /** A newly produced artifact. */ | ||
| artifact: ArtifactSchema.optional(), | ||
| /** ID of a snapshot that was just persisted. */ | ||
| snapshotId: z.string().optional(), | ||
| /** Signals that the agent flow has finished processing the current input. */ | ||
| endTurn: z.boolean().optional(), | ||
| }); | ||
| export type AgentFlowStreamChunk = z.infer<typeof AgentFlowStreamChunkSchema>; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does this need to be in the shared schemas?
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 do have existing enums defined in shared schemas, probably doesn't hurt, but I don't know if we have a specific need for it in Dev UI at the moment. Do you want me to take it out?
Uh oh!
There was an error while loading. Please reload this page.
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 define things here only if we expect things to be consistent across languages. If it's something that can be language specific... then I'd say leave it out.