Pipecat Flows
Technical reference for Pipecat’s conversation flow system
New to building conversational flows? Check out our Pipecat Flows guide first.
Installation
Core Types
FlowArgs
Type alias for function handler arguments.
FlowResult
Base type for function handler results. Additional fields can be included as needed.
FlowConfig
Configuration for the entire conversation flow.
NodeConfig
Configuration for a single node in the flow.
ContextStrategy
Strategy for managing conversation context during node transitions.
ContextStrategyConfig
Configuration for context management strategy.
FlowManager
Main class for managing conversation flows, supporting both static (configuration-driven) and dynamic (runtime-determined) flows.
Methods
Initialize the flow with starting messages.
Set up a new conversation node.
- For dynamic flows, the application must advance the conversation using
set_node
to set up the next node. - For static flows,
set_node
is triggered by a function call that contains atransition_to
field.
Register a handler for a custom action type.
Get the current conversation context.
Returns a list of messages in the current context, including system messages, user messages, and assistant responses.
Example usage:
State Management
The FlowManager provides a state dictionary for storing conversation data:
Usage Examples
Functions that execute operations within a state.
Functions that create transitions between nodes. Use transition_to
(static flow) or transition_callback
(dynamic flow) to specify the target node.
Function Properties
Async function that processes data within a node. Can be specified as:
- Direct function reference
- Either a Callable function or a string with
__function__:
prefix (e.g.,"__function__:process_data"
) to reference a function in the main script
Handler for dynamic flow transitions. Must be an async function with one of these signatures:
The callback receives:
args
: Arguments from the function callresult
: Typed result from the function handler (new style only)flow_manager
: Reference to the FlowManager instance
Example usage:
Note: A function cannot have both transition_to
and transition_callback
.
Handler Signatures
Return Types
Provider-Specific Formats
You don’t need to handle these format differences manually - use the standard format and the FlowManager will adapt it for your chosen provider.
Actions
pre_actions
and post_actions
are used to manage conversation flow. They are included in the NodeConfig
and executed before and after the LLM function call, respectively.
Two categories of actions are available:
- Built-in actions: These actions ship with Flows by default.
- Custom actions: These are developer defined actions.
Built-in Actions
Common actions shipped with Flows for managing conversation flow. To use them, just add them to your NodeConfig
.
Speaks text immediately using the TTS service.
Ends the conversation and closes the connection.
Custom Actions
You can define custom pre_actions
and post_actions
. They are registered automatically when included in the NodeConfig
.
Custom actions are composed of:
String identifier for the action
Async or sync function that handles the action
Example:
Exceptions
Base exception for all flow-related errors.
Raised when flow initialization fails.
Raised when a state transition fails.
Raised when an invalid or unavailable function is called.