Skip to main content
Custom functions provide maximum flexibility by allowing you to define specific logic for step execution. Use them to preprocess inputs, orchestrate agents and teams, and postprocess outputs with complete programmatic control. Key Capabilities
  • Custom Logic: Implement complex business rules and data transformations
  • Agent Integration: Call agents and teams within your custom processing logic
  • Data Flow Control: Transform outputs between steps for optimal data handling
Implementation Pattern Define a Step with a custom function as the executor. The function must accept a StepInput object and return a StepOutput object, ensuring seamless integration with the workflow system. Custom function step workflow diagram

Example

Standard Pattern All custom functions follow this consistent structure:

Class-based executor

You can also use a class-based executor by defining a class that implements the __call__ method.
When is this useful?:
  • Configuration at initialization: Pass in settings, API keys, or behavior flags when creating the executor
  • Stateful execution: Maintain counters, caches, or track information across multiple workflow runs
  • Reusable components: Create configured executor instances that can be shared across multiple workflows
Also supports async execution by defining the __call__ method to be an async function.
For a detailed example see Class-based Executor.

Streaming execution with custom function step on AgentOS:

If you are running an agent or team within the custom function step, you can enable streaming on the AgentOS chat page by setting stream=True and stream_events=True when calling run() or arun() and yielding the events.
Using the AgentOS, runs will be asynchronous and responses will be streamed. This means you must keep the custom function step asynchronous, by using .arun() instead of .run() to run your Agents or Teams.
custom_function_step_async_stream.py
Streaming in case of a class-based executor also works the same way by defining the __call__ method to yield the events.

Developer Resources