Build AI agents and workflows in Python.
Loomflow gives you two building blocks. A Workflow is a set of steps you lay out. An Agent is a loop where the model picks the next step. Use either one, or put one inside the other. Memory, budgets and the audit log stay separate for every user automatically.
pip install loomflowLatest release: v0.20.0. See what changed
Two building blocks that fit together
Most real apps need both: some steps should always run the same way, others are best left to the model. Loomflow lets you mix them freely.
Workflow: you decide the steps
A graph of plain functions, agents or other workflows. You choose how the steps connect and where to branch. Loops are allowed, with a visit limit so a retry loop can't run forever.
Agent: the model decides the steps
A loop where the model reasons, calls tools, checks memory and decides when it is done. Switch between twelve loop styles, from ReAct to Tree of Thoughts, with one argument.
A support router in about twenty lines
A small model sorts each ticket, then the matching specialist agent answers it. The workflow records which steps ran.
from loomflow import Agent, Workflow
# Two specialists. Each one is an agent loop.
billing = Agent("Handle billing.", model="gpt-4.1-mini")
tech = Agent("Handle tech.", model="gpt-4.1-mini")
async def classify(text: str) -> str:
reply = (await Agent(
"Reply 'billing' or 'tech'.", model="claude-haiku-4-5",
).run(text)).output
return "billing" if "billing" in reply.lower() else "tech"
# The workflow: classify first, then route.
support = Workflow.route(classify, {
"billing": billing, "tech": tech,
})
r = await support.run(
"My card was charged twice.", user_id="alice",
)
print(r.visited) # ['classify', 'route_billing']Use them in either direction
Pass an Agent as a workflow step, or call wf.as_tool() to hand a whole workflow to an agent as a tool.
Branches and loops
add_router branches on whatever the last step returned. Loops are allowed and capped by max_visits_per_node.
Pick up after a crash
Run under SqliteRuntime or PostgresRuntime and finished steps are saved. A resumed run skips them.
What's included
Workflows
chain, route and parallel cover the common shapes, or build the graph by hand.
Twelve agent loops
ReAct, Plan-and-Execute, ReWOO, Reflexion, Supervisor, Debate, Swarm and more.
Studio
Record every run to a local file, then browse traces, versions, architecture and evals with loom studio.
Separate data per user
Pass user_id and memory, budgets, permissions and audit records stay partitioned.
Typed outputs
Give output_schema= a Pydantic model and get a validated object back. Misses are retried.
Streaming
agent.stream() and wf.stream() yield events you can send over SSE or WebSockets.
Any model
OpenAI, Anthropic, DeepSeek and about 100 more through LiteLLM. Images work on vision models.
Resume after a crash
Each step is journaled, so a resumed run skips the work that already finished.
Tools and MCP
Turn any function into a tool with @tool, or connect an MCP server.
Guardrails and approvals
Screen for prompt injection and PII, and ask a person before a risky tool call runs.
What happens during a run
Agents and workflows go through the same four stages, so tracing and audit look the same whichever you use.
Start
Loads the instructions, the user's partition and what is remembered about them.
Decide
The workflow graph or the agent loop picks the next step.
Act
Calls tools: your
@toolfunctions, MCP servers, files and shell, or vector search.Finish
Saves the result to memory, writes a signed audit record and emits OpenTelemetry spans.
Get started
Install the package, then follow the quickstart. Its first example runs without an API key.