-
Notifications
You must be signed in to change notification settings - Fork 714
feat(go): add DefineSessionFlow and DefineSessionFlowFromPrompt
#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
51
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.
Open
Changes from all commits
Commits
Show all changes
51 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 aca712c
renamed agent flow et al to session flow
apascal07 9c0d629
Update genkit-schema.json
apascal07 668fc31
renamed files
apascal07 000b300
Update agent.ts
apascal07 d82c1a8
Update schemas.config
apascal07 8e0a8d6
Merge ap/go-bidi and refactor session flow for new type params
apascal07 b6f5dc0
refactored order of type params
apascal07 c298aca
Update action.go
apascal07 aabe1ad
Update session_flow_test.go
apascal07 e3f6c42
refactored EndTurn bool into TurnEnd struct
apascal07 434a8d3
fix python
apascal07 c9fbc31
regenerate genkit-schema.json
apascal07 57a29d0
regenerate Python schema typing
apascal07 8709bb0
Update session_flow.go
apascal07 1761f81
Merge branch 'ap/go-bidi' into ap/go-session-flow
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,139 @@ | ||
| /** | ||
| * 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 session flows that require input variables. */ | ||
| inputVariables: z.any().optional(), | ||
| }); | ||
| export type SessionState = z.infer<typeof SessionStateSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for session flow input (per-turn). | ||
| */ | ||
| export const SessionFlowInputSchema = 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 SessionFlowInput = z.infer<typeof SessionFlowInputSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for session flow initialization. | ||
| */ | ||
| export const SessionFlowInitSchema = 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 SessionFlowInit = z.infer<typeof SessionFlowInitSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for session flow result. | ||
| */ | ||
| export const SessionFlowResultSchema = z.object({ | ||
| /** Last model response message from the conversation. */ | ||
| message: MessageSchema.optional(), | ||
| /** Artifacts produced during the session. */ | ||
| artifacts: z.array(ArtifactSchema).optional(), | ||
| }); | ||
| export type SessionFlowResult = z.infer<typeof SessionFlowResultSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for session flow output. | ||
| */ | ||
| export const SessionFlowOutputSchema = 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 SessionFlowOutput = z.infer<typeof SessionFlowOutputSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for the turn-end signal emitted by a session flow. | ||
| * | ||
| * A TurnEnd value is emitted exactly once per turn, regardless of whether a | ||
| * snapshot was persisted. Grouping all turn-end signals here lets callers | ||
| * detect turn boundaries with a single field check and leaves room for | ||
| * additional turn-end metadata in the future. | ||
| */ | ||
| export const TurnEndSchema = z.object({ | ||
| /** | ||
| * ID of the snapshot persisted at the end of this turn. Empty if no | ||
| * snapshot was created (callback returned false or no store configured). | ||
| */ | ||
| snapshotId: z.string().optional(), | ||
| }); | ||
| export type TurnEnd = z.infer<typeof TurnEndSchema>; | ||
|
|
||
| /** | ||
| * Zod schema for session flow stream chunk. | ||
| */ | ||
| export const SessionFlowStreamChunkSchema = 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(), | ||
| /** | ||
| * Non-null when the session flow has finished processing the current | ||
| * input. Groups all turn-end signals; the client should stop iterating and | ||
| * may send the next input. | ||
| */ | ||
| turnEnd: TurnEndSchema.optional(), | ||
| }); | ||
| export type SessionFlowStreamChunk = z.infer< | ||
| typeof SessionFlowStreamChunkSchema | ||
| >; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.