- Process data by interfacing with external systems and APIs to read or write information
- Progress the conversation by transitioning between nodes in your flow
How Functions Work
When designing your nodes, clearly define the task in thetask_messages and reference the available functions. The LLM will use these functions to complete the task and signal when it’s ready to move forward.
For example, if your node’s job is to collect a user’s favorite color:
- The LLM asks the question
- The user provides their answer
- The LLM calls the function with the answer
- The function processes the data and determines the next node
Function Definition
Flows provides a universalFlowsFunctionSchema that works across all LLM providers:
Function Handlers
Each function has a correspondinghandler where you implement your application logic and specify the next node:
Handler Return Values
Function handlers return a tuple containing:- Result: Data provided to the LLM for context in subsequent completions, or
None. This can be any serializable value — a string, dict, etc. - Next Node: The
NodeConfigfor Flows to transition to next, orNone
None for the next node. Other handlers may only want to transition conversational state without doing other work, in which case you can return None for the result.
Direct Functions
For more concise code, you can optionally use Direct Functions where the function definition and handler are combined in a single function. The function signature and docstring are automatically used to generate the function schema:FlowsFunctionSchema definitions while maintaining the same functionality.
To control interruption behavior, use the @flows_direct_function decorator: