- 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
Defining a Function
The preferred way to define a function is with a direct function: a single async function that is both the handler (the code that runs) and the schema (what is advertised to the LLM). Flows auto-derives the function’s metadata — name, description, parameter properties (with their descriptions), and which parameters are required — from the function’s signature and docstring. The first parameter is alwaysflow_manager (a FlowManager); the function’s own parameters follow. Document each parameter in a Google-style docstring.
The direct-function schema generator doesn’t yet map
Literal types to a
JSON-schema enum. Express enum-like constraints in the docstring prose
instead (e.g. ‘Must be one of “red”, “green”, or “blue”’). If you need a
strict enum in the schema, use the
FlowsFunctionSchema
pattern.Return Values
A function can return any JSON-serializable value (string, dict, list, etc.) that gets passed to the LLM. To also specify the next node, return a tuple:- Result: Data provided to the LLM for context in subsequent completions, or
None. Any JSON-serializable value is accepted. - Next Node: The
NodeConfigfor Flows to transition to next, orNone.
None for the next node. One that only changes conversational state, without doing other work, can return None for the result.
Per-Function Call Options
By default, a function is not cancelled when the user interrupts, and it uses the LLM service’s global timeout. To override either, decorate the function with@flows_tool_options:
Advanced: Defining a Function with FlowsFunctionSchema
Direct functions cover most cases. Reach for FlowsFunctionSchema when you need explicit control over the schema — for example a strict enum constraint or a numeric minimum/maximum — that a direct function can’t yet express.
A FlowsFunctionSchema spells out the function’s name, description, and parameters by hand, and takes the handler that runs when the LLM calls the function:
handler is required. It receives the LLM-supplied arguments and returns the same result and next-node values as a direct function. To override its call options, decorate it with @flows_tool_options, the same decorator direct functions use.