LangGraph Agent
--agent (CLI) and POST /agent + approve/reject (API) run a LangGraph StateGraph with three tools, behind a mandatory human-in-the-loop gate: no tool ever executes without explicit approval, in either mode.
The three tools
eval or exec.docs/ — path-confined, can't escape the corpus directory.Graph & approval gate
agent/graph.py's AgentGraph compiles the graph with a MemorySaver checkpointer and interrupt_before=["tools"]: execution pauses right before a tool call would run. session_id doubles as the LangGraph thread_id — the same validated field used elsewhere, no new ID scheme.
CLI flow
Synchronous — when the graph pauses, it prints every proposed tool call (there can be more than one in a single turn, via parallel tool calling) and prompts once with [y/N]. Approval or rejection applies to the whole batch.
API flow
Two-step, by explicit design choice — an auto-approve-via-header alternative was considered and rejected as weakening the safety gate.
POST /agentruns until it finishes or pauses. A pause returns{"status": "pending_approval", "pending_id": <session_id>, "pending_tool_calls": [{"tool": str, "args": dict}, ...]}— every pending call, not just one, so an approver can't unknowingly approve a call they never saw.POST /agent/{pending_id}/approveexecutes the batch and continues. Executed calls are logged tologs/agent.jsonlwith a real result.POST /agent/{pending_id}/rejectdeclines the whole batch instead — the agent must acknowledge it can't complete that step (enforced viaAGENT_SYSTEM_PROMPT_SUFFIX), not silently retry.
Neither approval route has a per-route rate-limit decorator, for the same ASGI-middleware reason as /chat//chat/rag — see REST API Reference.
Calculator cost bound
calculator's AST evaluator bounds ast.Pow's cost before computing, not just the grammar it accepts: Python ints are arbitrary-precision, so an innocuous-looking 9**9**9 would otherwise pin a CPU core computing a ~369-million-digit number. _check_pow_cost estimates the result's bit-length via log2 and rejects anything over _MAX_POW_RESULT_BITS before evaluating.
Audit log
Every tool-call attempt — approved-and-executed, or rejected — is logged as one JSON line to logs/agent.jsonl (gitignored, like sessions//chroma_db/): {"timestamp", "session_id", "tool", "args", "result", "declined", "approved_by"}. Tool results are truncated to 500 characters in the log only — the LLM/caller still receives the full result.
MemorySaver is in-memory, so a pending approval is lost if the API process restarts before /approve//reject is called. verify_token authenticates one shared service secret, not a per-user identity, so any valid token holder can approve or reject any session's pending call — identical to the pre-existing /chat session_id trust model, not new to this feature.Next steps
- Run agent mode from the CLI — see CLI Reference.
- Understand the calculator and path-containment hardening in more depth — see Security.