To build a workflow, create agents and compose them into steps. Steps can be nested freely.
pipeline.py
import asynciofrom definable.agent import Agentfrom definable.agent.workflow import Workflow, Step, Parallelresearcher = Agent(model="gpt-4o", instructions="You are a research specialist.")analyst = Agent(model="gpt-4o", instructions="You are a business analyst.")writer = Agent(model="gpt-4o", instructions="You are a technical writer.")workflow = Workflow( name="research-pipeline", steps=[ Parallel(name="research", steps=[ Step(name="web-research", agent=researcher), Step(name="analysis", agent=analyst), ]), Step(name="writer", agent=writer), ],)async def main(): result = await workflow.arun("Write about the state of AI agents in 2026.") print(result.content)asyncio.run(main())
Run Your Workflow
1
Set up your environment
python3 -m venv .venvsource .venv/bin/activate
python -m venv .venv.venv\Scripts\activate
uv venv --python 3.12source .venv/bin/activate
2
Install Definable
pip install definable
uv pip install definable
poetry add definable
3
Export your API key
export OPENAI_API_KEY=sk-***
setx OPENAI_API_KEY sk-***
4
Run
python pipeline.py
Step Executors
Each Step wraps exactly one executor. Set agent=, team=, or executor=.
# Agent stepStep(name="researcher", agent=my_agent)# Team stepStep(name="analysis-team", team=my_team)# Callable step (sync or async)async def process(step_input): data = step_input.get_last_step_content() return f"Processed: {data}"Step(name="processor", executor=process)
Step Parameters
str
required
Step name. Used to access results via result.get_step_output(name).
Agent
Agent to execute. Mutually exclusive with team and executor.
Team
Team to execute. Mutually exclusive with agent and executor.
Callable
Custom function (StepInput) -> str | RunOutput. Mutually exclusive with agent and team.
float
Maximum execution time in seconds.
int
default:"0"
Number of retry attempts on failure.
Callable[[StepInput], str]
Custom function to build the prompt from step context.
Composing Steps
All step types are composable. Nest them freely:
from definable.agent.workflow import Workflow, Step, Parallel, Condition, Loopworkflow = Workflow( name="full-pipeline", steps=[ Parallel(name="research", steps=[ Step(name="web", agent=web_researcher), Step(name="papers", agent=paper_reader), ]), Step(name="writer", agent=writer), Condition( name="quality-check", condition=lambda ctx: "APPROVED" in (ctx.get_last_step_content() or ""), true_steps=Step(name="publish", agent=publisher), false_steps=Loop( name="revise", steps=[ Step(name="rewrite", agent=writer), Step(name="review", agent=reviewer), ], end_condition=lambda outputs: any("APPROVED" in (o.content or "") for o in outputs), max_iterations=3, ), ), ],)