Most agent frameworks start with a program.
You draw a StateGraph: nodes are functions, edges are transitions, a router
decides which node runs next. Each node receives a mutable state dict, does
something, and returns a command that says where to go.
That model is honest when the path is known. extract → validate → answer is a
graph. Draw it and move on.
But an agent answering an open-ended question rarely knows the path in advance.
One question needs a CSV and a policy document. The next needs a web page and a
verification step. A follow-up needs a different subset of the same
capabilities. The graph becomes a map of every path you imagined, and every new
capability means editing the map.
reactifact starts somewhere else: the state is the program.
An artifact is not a dict entry. It is a pydantic model plus identity, version,
content hash and provenance edges, stored in a Context. An Agent groups steps
and owns their wake contract; a Step is one transformation.
You define typed artifacts and the steps that react to them. You do not call a
step. You create an artifact; the step that consumes it wakes. It produces
another artifact; the next step wakes. The path is derived from state, not
declared as edges.
TL;DR — reactifact 0.33 is a Python runtime where typed artifacts are the
state and steps react to them. You declare what exists and what wakes what,
not a central graph or a sequence of commands.
To be precise: there is still a graph. It is derived at runtime from the types
and wake contracts; you do not maintain it as a separate object. The rest of
this post is about making that model pleasant to write.
What a StateGraph asks you to know
A graph-first framework usually asks for four things before a run:
- a state schema (
dict[str, Any]or a typed state object); - a transition function that knows which node follows which;
- commands or edges that encode those transitions;
- an entry point that invokes the graph.
This is a useful contract. It is also a prediction about the future. The moment
a request needs a branch nobody drew, the graph is no longer a description of
the work. It is a constraint on it.
The same failure shows up in the code. A node often starts with a guard:
def route(state): if not isinstance(state.get("question"), Question): return {"next": "wait"} The type is in the state, but the runtime cannot use it. So the developer checks
it again in the body, then edits the graph to route around the case.
The contract lives in three places — the state, the edge and the guard — and
nothing forces them to agree.
The alternative: an artifact in, an artifact out
reactifact treats the state as a typed, versioned ledger. A Question is an
artifact. So is an Answer. An Agent groups steps and owns their wake
contract; a Step is one transformation. The group's wake contract appears only
on the agent; Step.on only narrows it. The runtime decides when the group is
ready:
from pydantic import BaseModel from reactifact import Application, Pipeline, step class Question(BaseModel): text: str class Answer(BaseModel): text: str @step def answer(question: Question) -> Answer: return Answer(text=question.text.upper()) pipeline = Pipeline(seed_type=Question, answer_type=Answer) pipeline.agent(answer, consumes=[Question], name="answer") app = Application(pipeline) result = app.run(Question(text="why did cloud spend jump in Q2?")) There is no add_edge. No next_node. No state["answer"] = ....
At runtime, there is one imperative act: writing an artifact.
app.run(Question(...)) seeds the context; after that, the runtime matches
events to reactions until nothing new can run.
This is not "no structure". The structure is the set of types and contracts:
what exists, what wakes an agent, what a step reads, what it produces. The
runtime materializes only the path this run needs.
| Graph-first | Artifact-first |
|---|---|
| a mutable state dict | typed, versioned artifacts |
| nodes and edges | steps and artifact types |
commands / next | Consume and Step.on |
| a router chooses the node | the runtime matches events to reactions |
| the graph is the source of truth | the context is the source of truth |
| a trace is a log of calls | provenance is a graph you can query |
A step is a sentence about the domain
The nicest part of this model is how the code reads.
A step has no if isinstance(trigger, ...) guard. It has a signature. A step
that computes spend consumes a Table, reads the question and produces a
Spend:
from reactifact import Artifact, Condition, Ensure, Select, step @step( produces=Spend, on=Select[Table].where(Condition.equals("locator", "transactions.csv")), ) def compute_spend( table: Artifact[Table], question: Artifact[Question], ) -> Ensure[Spend]: ... The agent's consumes says when the group wakes. Step.on narrows the step to
one kind of event. The typed parameters are ordinary reads. Select chooses
which artifact of a type a parameter receives.
They are deliberately separate:
| Layer | Answers |
|---|---|
Agent.consumes | when does the group wake? |
Step.on | which events does this step handle? |
| typed parameters | what does the step read once it runs? |
Select | which artifact of that type does the parameter receive? |
The types are the nouns. The steps are the verbs. The runtime handles the
grammar.
The runtime is the injector
A step never reaches into a global context or a request object to find its
inputs. The runtime reads the signature and resolves every parameter before
calling the step.
If you have used FastAPI, the feeling is familiar: annotations are the contract,
and the framework supplies the values. The difference is that the "request" is
not an HTTP body. It is the current artifact event plus the context.
| Annotation | What the runtime injects |
|---|---|
Question, list[Doc], `Question \ | None` |
Artifact[Question] | the artifact handle, not just its data |
Annotated[Doc, Select.by_status("ready")] | the artifact selected by that condition |
Context / CurrentRequest | the artifact graph / the current request mapping |
Effects, Progress, Event | built-in step collaborators |
LLMProvider, Catalog, a client | a resource registered on RuntimeResources |
Annotated[T, FromKey(KEY)] | a keyed resource, for duplicate types or scalars |
The rule is type-driven:
from reactifact import Artifact, LLMProvider, RuntimeResources, step class Catalog: def price(self, sku: str) -> float: ... resources = RuntimeResources() resources.register(Catalog, Catalog()) @step def answer( question: Artifact[Question], # artifact from the Context catalog: Catalog, # resource from RuntimeResources llm: LLMProvider, # resource, injected by type ) -> Answer: ... A plain pydantic model is treated as an artifact. A plain class is treated as a
resource. An explicit registration wins over artifact resolution, which is why a
pydantic Settings object can be a resource while Question stays data.
Inject() (or the FastAPI-style Depends()) is only needed when the intent is
ambiguous. FromKey(KEY) is for the cases a type cannot express: two instances
of the same class, a list, a callable or a scalar. A required resource that is
missing raises MissingResourceError before the step runs; T | None means an
honest optional dependency.
No request.state, no service locator in the body, no constructor wiring per
step. The signature is the wiring.
Waking up is a decision about state
A reaction is not only "this type exists". The state carries the details that
decide whether a step should run:
- which event happened: created, updated, deleted or stale;
- what the artifact contains: a field or status condition;
- which set of artifacts must be present together;
- which phase the workflow is in, when order matters more than pure reactivity.
A lifecycle is part of the contract:
pipeline.agent( index, consumes=[Consume.on_create(Doc)], name="index", ) Only a new Doc wakes the indexer. An update to the same id does not.
Content is part of the contract too. A document with status="ready" and a
document with status="draft" are the same Python type, but they are different
work:
@step( produces=Index, on=Select[Doc].by_status("ready"), ) def index(doc: Artifact[Doc]) -> Ensure[Index]: ... The same idea works on the agent side:
pipeline.agent( index, consumes=[Consume.by_field(Doc, "status", "ready")], name="index", ) For a compound condition, use Select.where(...) on a step, or
Consume.where(...)/Consume(..., condition=...) on an agent. For a set that
must arrive together, use Join(...): it waits until every part exists for the
same correlation key.
And when the workflow genuinely has phases — collect everything, settle, then
answer — you can group agents into stages:
with pipeline.stage("collect"): pipeline.agent(collect, consumes=[Question], name="collect") with pipeline.stage("answer"): pipeline.agent(answer, consumes=[Evidence], name="answer") A stage is a quiescence barrier, not an edge. Agents inside the stage stay
reactive; the next stage starts only when the current one settles. Stages are
optional: reach for them when the order is deliberate, not to re-create a graph
you were trying to avoid.
Event, content, correlation, phase. Those are the four knobs. None of them is a
command that tells another step to run.
Writing state without a command object
In a graph framework, the unit of change is usually a command: update_state,
return {"key": value}, goto("next").
In reactifact, the unit of change is an instruction over an artifact. For the
common case, a step just returns it:
from typing import Annotated from reactifact import Artifact, Condition, Ensure, Select, step @step(produces=Variance, on=Spend) def compute_variance( spend: Artifact[Spend], question: Artifact[Question], budget_table: Annotated[ Artifact[Table], Select.where(Condition.equals("locator", "budget.csv")) ], ) -> Ensure[Variance]: return Ensure( Variance(...), source=question, links=( ("calculated_from", spend), ("calculated_from", budget_table), ), ) Ensure is an idempotent create whose id is derived from question. Emit is
the upsert form. Edit, Drop and Relate cover updates, deletes and
provenance edges. The runtime compiles them into one atomic patch.
No effects: Effects in the signature. No manual f"variance:{question.id}".
No separate link call.
Effects is still there when you need a handle before commit, or a batch of
conditional writes. It is an escape hatch, not the default authoring style.
The graph is a consequence
The demo in the repo is deliberately small: three steps, a transactions CSV, a
budget CSV and a policy document. No API key, no model call. Run
reactifact demo (the install line is under Try it) and you should
see:
answer Q2 cloud spend was $45,000 against a $40,000 budget (+12.5%) — exceeds the 10% policy threshold. CFO approval is required before the quarter is closed. computed cloud spend $45,000 (2026-04 $12,000, 2026-05 $15,000, 2026-06 $18,000) policy threshold 10% → approval required citations budget.csv, transactions.csv, policy.md provenance (context.related(answer.id, "supported_by")) Answer → supported_by → Variance, policy.md Variance → calculated_from → Spend, budget.csv Spend → calculated_from → transactions.csv context sha256 ffeca1bb18cbc34749d3b5bdb40d85677b1ac33d47fb1160f6c89053694b2783 re-run identical ✓ The numbers are computed in plain Python. The model never produces the figure.
The answer links to the rows and the policy that justify it. A second run
reaches the same context_hash.
The execution order was never written down. The wake contracts were; the path
fell out of the artifacts:
Table ──consumes──▶ compute_spend ──produces──▶ Spend Spend ──consumes──▶ compute_variance ──produces──▶ Variance Variance ──consumes──▶ answer ──produces──▶ Answer That is the graph. It exists at runtime, for this run, because those artifacts
exist. It is not a separate object you maintain.
demo --web serves the same run with the provenance graph, the generated
contracts page and a real trace dashboard.
The trace is not a transcript of prose. It shows which agent woke, which
artifacts it read, what it wrote, and why a step was skipped. "Why did it say
that?" becomes a query over the context.
The loop is built in
A run is not finished when the answer appears. The same runtime also leaves a
receipt and a way to regression-test it.
Traces are typed records, not log lines. Turn them on with RunConfig:
from reactifact import Application, RunConfig app = Application(pipeline, config=RunConfig(traces=True)) A finished trace holds the agent spans, the artifacts each span read and wrote,
the relations it created, the LLM calls, and the decisions that explain skipped
work. reactifact trace renders the same data locally; demo --web serves the
dashboard.
Scenarios seed artifacts and assert on the graph a run produced, not on a
returned value:
from reactifact.testing import ScenarioLab lab = ScenarioLab(app) result = lab.run_sync(Question(text="why did cloud spend jump in Q2?")) assert result.artifacts(Answer).exists() assert result.path.contains("answer") assert result.errors.count() == 0 ScenarioLab also injects tool/resource faults and records or replays LLM calls,
so an LLM-in-the-loop test is deterministic without monkeypatching.
Evals score the same runs over a dataset with deterministic metrics,
Answer/evidence/claim checks and optional LLM judges. evaluate(...) returns
a report; report.assert_passed(0.8) is the same gate in code. The CLI combines
the whole loop:
reactifact check app.pipeline:pipeline \ --scenarios app.scenarios \ --evals evals/qa.json \ --overall 0.8 Contracts, scenarios and dataset evals run in one gate. This is the part I care
about most: traces, tests and evals are not a second stack bolted onto the agent
framework. They read the same artifacts and the same run.
What changed in 0.33
If you tried an older reactifact, the current surface is much smaller:
-
Agentis the only group. It owns steps,consumesand policy.Bindingis gone. - Inputs are typed parameters.
@step(reads=...)andStep.needsare compatibility aliases, not the canonical form. -
SelectreplacesRead/ReadSpec.Select[T]names a filter;Step.onnames the step's reaction. -
Step[T]andLatest[T]are gone. Useclass X(Step)withproduces=(Foo,)orrun() -> Foo; ambient reads useAnnotated[T, Latest()]. - Return-style instructions are first-class.
Ensure,Emit,Edit,DropandRelatecover the common writes without an injectedEffects. -
pipeline.bindis gone. UsePipeline.agent(...)orPipeline.mount(...). -
ScenarioLabtakes anApplication. Resources, budget and concurrency live inRunConfig, not in the test harness.
The migration guide has the full checklist:
migrating to 0.33.
When a StateGraph is still the right tool
I would not use reactifact for a fixed A → B → C flow. If you know the path,
a function or a graph is shorter and easier to explain.
reactifact earns its keep when:
- the path depends on which artifacts exist;
- capabilities are added over time and should not require rewiring;
- the answer needs provenance and a reproducible state hash;
- a human approval or an outbound action has to pause and resume the same run.
It is not a distributed task queue. It is not a managed platform. It is
a Python library with three core dependencies (pydantic, httpx,
python-dotenv), and the demo runs offline.
It is still pre-1.0. But the authoring model is finally the one I wanted: one
Agent, typed inputs, explicit reactions, and a run you can inspect.
Try it
pip install "reactifact[web]==0.33.1" reactifact demo reactifact demo --web - Repo: github.com/bzdvdn/reactifact
- Docs: bzdvdn.github.io/reactifact
- 0.33 migration: docs/en/migration-0.33.md
- PyPI: pypi.org/project/reactifact
If you try it and something breaks, open an issue. That is still the most useful
feedback.



