Skip to content
Open
Show file tree
Hide file tree
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 Feb 6, 2026
fe91d76
Update main.go
apascal07 Feb 6, 2026
ad323d2
Update main.go
apascal07 Feb 6, 2026
3913771
moved files
apascal07 Feb 6, 2026
15880f5
added `DefineSessionFlowFromPrompt`
apascal07 Feb 6, 2026
e94bca1
removed stream type param
apascal07 Feb 6, 2026
a77fa33
updates
apascal07 Feb 9, 2026
e83af30
cleaned up API naming and behavior
apascal07 Feb 17, 2026
db37102
Update action.go
apascal07 Feb 17, 2026
f4c4ec1
added stream capturing to output
apascal07 Feb 18, 2026
08b09e4
stream out interrupt chunks
apascal07 Feb 18, 2026
c2f55ab
Update genkit.go
apascal07 Feb 18, 2026
30b4afd
Update agent_flow.go
apascal07 Feb 18, 2026
22be814
removed get snapshot action
apascal07 Feb 18, 2026
a009a1b
tagged prompt messages and excluded them
apascal07 Feb 18, 2026
ea742d9
fixed PromptInput -> InputVariables
apascal07 Feb 18, 2026
2ae4bb8
added AgentFlowResult to output final artifacts
apascal07 Feb 18, 2026
787f61a
Update agent_flow.go
apascal07 Feb 18, 2026
d1281d5
removed turn index from snapshot
apascal07 Feb 18, 2026
d6cae44
exposed InputCh and TurnIndex on AgentSession
apascal07 Feb 18, 2026
10bbd03
improvements to API
apascal07 Feb 18, 2026
a687eb6
minor fixes
apascal07 Feb 18, 2026
7c535c4
Update session.go
apascal07 Feb 18, 2026
26f8f7d
added shared schemas for agent types
apascal07 Feb 18, 2026
d9c335a
Update typing.py
apascal07 Feb 18, 2026
fb7f254
various renames
apascal07 Feb 18, 2026
971b668
helper for input variables conversion
apascal07 Feb 19, 2026
3491761
DefinePromptAgent takes in prompt name instead of resolved prompt
apascal07 Feb 19, 2026
b46acce
fixed interrupts streaming
apascal07 Feb 21, 2026
6676882
Update genkit.go
apascal07 Feb 21, 2026
8d99639
added `SetMessages`
apascal07 Feb 21, 2026
3cbec28
added `AgentSession.Result()`
apascal07 Feb 25, 2026
6ac5510
moved from `ai/x` to `ai/exp`
apascal07 Feb 25, 2026
ac39ef9
Update agent.go
apascal07 Feb 25, 2026
5a671bb
added `AgentFlow.Run()` and `AgentFlow.RunText()`
apascal07 Feb 25, 2026
49a19eb
dedupe consecutive identical snapshots
apascal07 Feb 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions genkit-tools/common/src/types/agent.ts
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']);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

@pavelgj pavelgj Feb 25, 2026

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.

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>;
134 changes: 134 additions & 0 deletions genkit-tools/genkit-schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,140 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$defs": {
"AgentFlowInit": {
"type": "object",
"properties": {
"snapshotId": {
"type": "string"
},
"state": {
"$ref": "#/$defs/SessionState"
}
},
"additionalProperties": false
},
"AgentFlowInput": {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"$ref": "#/$defs/Message"
}
},
"toolRestarts": {
"type": "array",
"items": {
"$ref": "#/$defs/Part"
}
}
},
"additionalProperties": false
},
"AgentFlowOutput": {
"type": "object",
"properties": {
"snapshotId": {
"type": "string"
},
"state": {
"$ref": "#/$defs/SessionState"
},
"message": {
"$ref": "#/$defs/Message"
},
"artifacts": {
"type": "array",
"items": {
"$ref": "#/$defs/Artifact"
}
}
},
"additionalProperties": false
},
"AgentFlowResult": {
"type": "object",
"properties": {
"message": {
"$ref": "#/$defs/Message"
},
"artifacts": {
"type": "array",
"items": {
"$ref": "#/$defs/Artifact"
}
}
},
"additionalProperties": false
},
"AgentFlowStreamChunk": {
"type": "object",
"properties": {
"modelChunk": {
"$ref": "#/$defs/ModelResponseChunk"
},
"status": {},
"artifact": {
"$ref": "#/$defs/Artifact"
},
"snapshotId": {
"type": "string"
},
"endTurn": {
"type": "boolean"
}
},
"additionalProperties": false
},
"Artifact": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"parts": {
"type": "array",
"items": {
"$ref": "#/$defs/Part"
}
},
"metadata": {
"type": "object",
"additionalProperties": {}
}
},
"required": [
"parts"
],
"additionalProperties": false
},
"SessionState": {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"$ref": "#/$defs/Message"
}
},
"custom": {},
"artifacts": {
"type": "array",
"items": {
"$ref": "#/$defs/Artifact"
}
},
"inputVariables": {}
},
"additionalProperties": false
},
"SnapshotEvent": {
"type": "string",
"enum": [
"turnEnd",
"invocationEnd"
]
},
"DocumentData": {
"type": "object",
"properties": {
Expand Down
1 change: 1 addition & 0 deletions genkit-tools/scripts/schema-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { zodToJsonSchema } from 'zod-to-json-schema';

/** List of files that contain types to be exported. */
const EXPORTED_TYPE_MODULES = [
'../common/src/types/agent.ts',
'../common/src/types/document.ts',
'../common/src/types/embedder.ts',
'../common/src/types/evaluator.ts',
Expand Down
Loading
Loading