All projects
Personal project · 2024

Magpie: A graph-based framework for agentic workflows

A graph-based framework for quickly building agentic workflows and automation pipelines.

PythonAIWorkflow Automation
Source on GitHubLast updated June 2026

What it does

LLM workflows are rarely a straight line. One step fans out to several, another waits for two results, a check sends weak output back for another try, and you want to watch every result as it happens.

Magpie (package llmagpie) lets you write those workflows as an explicit graph in Python. You write small typed nodes, wire one node's named output to another's input, and run the whole graph as a pipeline that streams every result. The core depends only on networkx and pydantic; the LLM client is your choice.

See it run

Here the graph from the repo's multi_input_with_loop.py drafts a support reply. A1 reads the question while A2 finds a help article; B waits for both, then drafts. C reviews: its notes go back into B, and once the draft passes it goes on to D. Every result streams out the moment it's ready. The text is illustrative; the wiring is the example's.

0 / 8
loopA1questionA2retrieveBdraftCreviewDsend

B waits for both inputs

Streamed results

  1. Press Run or Step.

The building blocks

Nodes

A class or function with typed inputs and named outputs. Sync, async or a generator.

@MakeNode.from_class(outputs={"outputs": str})

Wires

Connect one node’s output to another’s input. Types are checked when you wire, and again on compile.

(a >> "out") >> ("in" >> b)

Merges

A node with several inputs waits until each has arrived, then runs with the latest of each.

Branches and loops

A node picks which output to send, which picks the path. A wire back makes a loop, capped per run.

return {"final_outputs": …}

Streaming

Every output is yielded the moment it’s ready; generator nodes stream chunk by chunk.

for state in pipe.invoke(inputs)

Nesting

A compiled pipeline is itself a node, so pipelines compose. Keys are namespaced per level.

"inner.B1.inputs"

Beyond the core

Optional pieces for LLM work. The first three are in llmagpie.experimental; tracing is in llmagpie.observability.

Multi-agent supervisor

A supervisor hands tasks to worker agents through tool calls, in parallel, with limits on how deep and how often it delegates.

LLM nodes

Chat nodes for OpenAI, Anthropic and Ollama with token streaming, and an agent with memory, tools and token budgets.

Record and replay

Record real LLM calls once, then replay them so tests give the same result every time.

Tracing

OpenTelemetry spans for nodes, pipelines and agent steps, plus a CLI to read recorded runs.

🎵 My AI-generated music [AI in 2026] is playing. Toggle it on/off in the header.