Flows API
Flows are the primary mechanism for orchestrating multi-step AI tasks in Genkit. Each flow run is automatically traced for observability.defineFlow()
Defines and registers a flow function. Signature:Parameters
FlowConfig | string
required
Flow configuration or simple name string
FlowFn<I, O, S>
required
The flow implementation function
Returns
Action<I, O, S>
A registered flow action that can be invoked
Example
Streaming Flows
Flows can support streaming by providing astreamSchema and using the streaming callback.
Example
run()
Executes a function within a flow context, creating a distinct trace span. Used to add observability to sub-operations. Signature:Parameters
string
required
Label for the trace span
any
Optional input to pass to the function
Function
required
Function to execute within the traced span
Returns
T
The result of the function execution
Example
Flow Types
FlowFn
The function signature for flow implementations.StreamingCallback
Callback for streaming chunks.FlowConfig
Configuration for defining a flow.Usage with Genkit Instance
When using theGenkit class, flows are defined through the instance:
Production Deployment
Flows can be deployed as HTTP endpoints:POST /menuSuggestionFlowPOST /complexFlow