Skip to content
FunCoding

agent-in-the-loop

Agent in the Loop: the pseudo-model loop/mcp makes every model call of a chat run a step that an external MCP client (Claude Code, Codex) answers over the inbound MCP server. A loop model must answer only inside its own run scope, never wait outside one, never be retried, and never let the outside brain approve its own dangerous actions. Trigger: editing agentic/agent_in_the_loop/; adding a model call site or a retry loop in the agent; adding a path that builds an LLM from a model id; editing webapp/src/lib/mcp/loop*.ts, webapp/src/lib/agentInTheLoop.ts, or the LOOP_STATUS handling in the chat drawer.

Star
3,553
License
MIT
Last commit
Nov 30, 2026

skills/agent-in-the-loop/SKILL.md

View on GitHub

When to Use

  • Changing the step broker, the adapter, the prompt document or the /loop/* routes.
  • Adding a model call to the agent, or a loop that retries model calls.
  • Adding any endpoint, job or feature that builds a chat model from a model id.
  • Changing the loop MCP tools, their scope, the driver-token rule, or the drawer's loop status.

Critical Rules

  • A loop model answers ONLY inside a live run scope of its session that uses the loop. Its identity comes from get_broker().scope_for_session(current_log_session_id), never from current_user_id, current_project_id or current_session_id: initialize_node calls the guardrail and the classifier before any node sets those (model.py, agent_context.py).
  • A new path that builds an LLM from a model id refuses loop/ with refuse_loop_model() / LoopModelNotSupportedHere (code loop_model_not_supported_here): no chat run, no driver, a wait that never ends (llm_builder.py, the api.py builders). Feature pickers filter it with excludeLoop, saves refuse it.
  • Loop errors are never retried. They carry no_retry = True and their messages contain no transient phrase (timeout, connection, a bare 5xx); is_transient_llm_error checks the marker first. A new loop that retries on ANY exception must break on getattr(e, "no_retry", False) (errors.py, phase.py is the example).
  • A limit that can end a run is told to both sides. An interactive driver makes no call while its person talks to it, so the driver reads runEndsIfSilentSeconds on every step and the pack tells it never to end its turn while a run is live; the drawer gets noDriverEndsInSeconds and shows the clock time the run ends. A new timer or cap that ends a run goes into both, or a driver that read only deadlineInSeconds believes it has longer. Keep LOOP_STEP_DEADLINE_S above LOOP_NO_DRIVER_GRACE_S: the deadline counts from the step's opening, so a lower one ends a pause first.
  • A run that ends for want of an answer keeps what it found. The report node's fallback is built from state alone (last Fireteam wave, session findings, how to resume), since after a lost driver every later step, the report included, fails at once (generate_response_node.py).
  • A new model call site gets an llm_purpose(...) label, or its step reaches the driver as other with a text answer format (purpose.py).
  • A loop run follows the project's REQUIRE_TOOL_CONFIRMATION, and an unattended run shows it. The gates read the setting as in a provider run; _stream_graph passes it to run_scope(tool_confirmation=...), the drawer's loop_status carries it as toolConfirmation, and false puts a red risk icon next to the Agent in the Loop chip (loopStatus.ts). It stays out of the driver's view and the step (a step change bumps contractVersion).
  • Only a person answers approvals, questions and dangerous-tool confirmations, and only one who may take that decision. No MCP tool may answer them (loopTools.ts). Before anything runs or is saved the socket checks the answer twice: _refused_without against the ticket's cap, then _refused_now, which asks the webapp again and refuses when it cannot be reached; an admitted answer is saved with decision_actor() (sub, act under act-as), as _record_decision does (websocket_api.py). A new kind of answer takes all three.
  • A loop step belongs to the person, never the tenant. Run scopes and steps are keyed by the session's person (get_identifiers; the token's user on the MCP side); the project's owner is only the graph tenant (get_tenant_id). A driver reaches a shared project only at agent:loop's level through mcpProjectAccess (loopProjects in loopTools.ts).
  • A driver token holds no write or exec scope besides agent:loop. Compute it from MCP_SCOPE_COPY with loopTokenProblem, never a hand list; the loop tools refuse wider tokens (loopScopes.ts).
  • A person picks the brain. MCP writes, presets, imports and user defaults never set a loop model (loopModelRefusal, the preset checks, rememberedDefaults).
  • Any change to the step shape bumps contractVersion (agent CONTRACT_VERSION, the skill pack's LOOP_CONTRACT_VERSION), so a client's out-of-date skill says so.
  • A new loop tool joins LOOP_TOOL_NAMES (withdrawn while the switch is off), every MCP test that stubs MCP_KALI_EXEC_ENABLED also stubs AGENT_IN_THE_LOOP_ENABLED, then npm run docs:mcp (the mcp-server-tools skill).
  • loop_status and the step views carry no prompt or answer text; the WebSocket frame is sent, never persisted.

Where things live

ConcernFile
Switch, tunables, is_loop_model, is_loop_llmagentic/agent_in_the_loop/__init__.py
Steps, leases, deadlines, no-driver rule, dedup, pruningagentic/agent_in_the_loop/broker.py
Run scope around every streaming graph loopAgentOrchestrator._stream_graph in agentic/orchestrator.py
MCP tools, client, driver-token rulewebapp/src/lib/mcp/loopTools.ts, loopClient.ts, loopScopes.ts
Skill pack per clientwebapp/src/lib/mcp/loopSkill.ts
Drawer status stringswebapp/src/app/graph/components/AIAssistantDrawer/hooks/loopStatus.ts
Fallback report when a loop step failsagentic/orchestrator_helpers/nodes/generate_response_node.py

Resources

  • docs/readmes/README.MCP.SERVER.md - the inbound MCP server and its security model
  • The wiki page Agent-in-the-Loop - setup for Claude Code and Codex, how it works, limits
  • Related skills: llm-provider-integration, mcp-server-tools, rbac-authz, redamon-testing

Similar Skills

wayfinder

MAmattpocock/skills336k4,217 new stars in the last 7 days

grill-with-docs

MAmattpocock/skills336k4,217 new stars in the last 7 days

to-tickets

MAmattpocock/skills336k4,217 new stars in the last 7 days

to-spec

MAmattpocock/skills336k4,217 new stars in the last 7 days

loop-me

MAmattpocock/skills336k4,217 new stars in the last 7 days

implement-spec

MAmattpocock/skills336k4,217 new stars in the last 7 days