Agent frameworks describe a workflow as a graph: nodes do work and return partial state updates, a reducer merges each update into shared state, and edges (fixed or chosen by a router function) decide which node runs next. Loops are allowed, so an agent can call a tool and come back. Build the execution engine.
Implement run_graph(nodes, edges, entry, state, reducers=None, max_steps=25) returning (final_state, trace, status).
nodes: dict mapping a node name to a callable fn(state) -> dict | None. The callable receives its own deep copy of the current state and returns a partial update (or None for no update).edges: dict mapping a node name to either a node name (string) or a router callable router(state) -> str that sees a deep copy of the state after that node's update was merged. The special target "END" stops the run. A node with no entry in edges also ends the run after it executes.reducers: dict mapping a state key to "replace" (default for unlisted keys), "append" (the update is a list; the new value is the old list, or [] if absent, followed by the update's items) or "add" (the new value is the old value, or 0 if absent, plus the update).trace is the list of node names in the order they executed.status is "done" when the run reaches "END" (or a node without an edge) and "max_steps" when max_steps nodes have executed and the next target is still a node. Stop immediately in that case.ValueError if entry, or any target an edge produces, is neither "END" nor a key of nodes.state dict or the lists inside it. final_state is a new dict.