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.

Read the quickstart
pip install loomflow

Latest release: v0.20.0. See what changed

classifyrouteagent.runas_tool
Workflow steps are the warp threads running down. The agent is the weft, passing across them one step at a time.

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.

support.py
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 happens during a run

Agents and workflows go through the same four stages, so tracing and audit look the same whichever you use.

  1. Start

    Loads the instructions, the user's partition and what is remembered about them.

  2. Decide

    The workflow graph or the agent loop picks the next step.

  3. Act

    Calls tools: your @tool functions, MCP servers, files and shell, or vector search.

  4. 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.

pip install loomflow
Read the quickstartView on GitHub