Context
I built this engine at Computech so that a new business process would not need a new agent. It runs internal approval workflows and a second product. The example packs in the repository model a leave request signed by employee, manager and director, an expense claim, and a policy attestation.
The problem
Each new agent usually arrives with its own graph, prompt handling, approval logic and error shapes. After a few of them you maintain several engines that do the same jobs in slightly different ways. I wanted a new process to mean a new directory under domains/, with no change to the engine.
Design
There is exactly one StateGraph in the codebase. It has six nodes: guard, intake, route, agent, step and finalize. Domain behaviour lives under domains/<id>/ as data: a domain.yaml naming the enabled tools and the default workflow, a system prompt, skills, tool specs, workflows and eval seeds.
The graph runs in two modes, and route picks one per run and never changes it:
- Dynamic. The model decides the order of work. This goes through
create_deep_agent, and there is exactly one call site for it. - Workflow. A declarative
steps.yamldecides the order. Step types aretool,transform,validate,agent,interruptandbranch. A branch can only jump forward, so a workflow cannot loop. Anagentstep runs one bounded deep agent, and its output is recorded as data: it can never change which step runs next.
Decisions and the alternatives I turned down:
- One graph for every domain. A second demo pack exists only to prove the engine is domain-agnostic, and a test asserts the graph compiles to the same node set under different configurations.
- Framework mechanisms only. Checkpointing, memory, skills, summarisation, interrupts and auth all use the LangChain, LangGraph and Deep Agents primitives. I did not write my own versions.
- The model sees a projection of state. The system prompt is constant per domain and never trimmed, which keeps provider prompt caching effective. Skills load in three levels: name and description always, the body when the agent reads it, resources only when the body says so.
- Provider is an environment decision.
init_chat_modelresolves the model fromHARNESS_MODEL, with retries, fallbacks and a rate limiter set the same way. Importing the package never imports a provider.
Guardrails
- Sensitive tools need approval. Tools with a
write,destructiveorsendeffect default toapproval: always, and a synchronous tool with one of those effects is rejected when the domain loads. These tools are never retried. - Approvals are bound to a person. An approval step can name a role. A resume from anyone else re-asks the step, and a stale token re-asks without advancing. Every decision lands in the result with the approver and the time.
- The server owns document access. Who can reach a document thread is a code map on the server. Client-supplied
accessandownermetadata are always overwritten, and the subject must equal the authenticated identity before any step runs. - Budgets are task-wide.
max_model_callsandmax_tool_callsare shared by the main agent and its subagent. A cost cap is opt-in, and with it set, a model with no price fails the run closed. - PII is masked in code. Email addresses are redacted and card numbers masked to the last four digits on user input, model output and tool results.
- Auth fails closed. With no JWKS endpoint configured and the static-token switch unset, every request gets a 401.
- Failures are typed. Every run that finishes or pauses returns an
ExecutionResultwith one of six statuses and an error from a closed set of categories. Partial work is never reported as success, and a result that fails validation is replaced by afailedresult.
Evals and results
- Unit tests run offline. They need no network, no API key and no server. Fake chat models stand in for providers.
- Architecture rules are tests. The suite asserts one
StateGraph(insrc/, onecreate_deep_agent(insrc/, and that domain packs reach the engine only through the tool spec module. - The document access layer is tested against the example packs. That covers role gating, identity mismatch, overwritten client metadata, subject immutability and wrong-signer re-asks.
- Integration tests start
langgraph dev. They cover the auth handlers, approval access and a set of security vectors. - Eval seeds live in the domain pack. One YAML file per case pairs a task with reference outputs, and a pytest module per domain runs each case through
runtime.run. With a LangSmith key set, each run is recorded as an experiment against a dataset.
What is not measured: the seeds check run status and step statuses, not the quality of a model’s answer, and there are only three of them. I have no task-success rate or answer-quality score to report yet.
A failure I handled
The first version of the call budget did not hold across a task. LangChain’s run_limit middleware resets for every invocation and for every subagent, so a run that used a subagent, or several agent steps in one workflow, got a fresh allowance each time. In practice the configured cap limited each call, and the task as a whole had no limit.
The fix keeps the count in graph state. Each agent invocation is handed only what remains for the task, max(0, cap - used), and the main agent and the subagent draw on the same count. The remaining budget can reach zero instead of being floored at one. Regression tests pin all three behaviours, and a looping fake model now ends with limit_reached and a typed limit_exceeded error.
Stack
Python, LangGraph, LangChain, Deep Agents, LangSmith (tracing and eval experiments), Pydantic v2, PostgreSQL checkpointer and store, PyJWT. Model providers through init_chat_model: OpenAI and Azure, Anthropic, Google, DeepSeek and Ollama.
Links
Private repository, code on request. I am happy to walk through the architecture on a call.