Skip to content

Agent and automation architecture

This page is the architecture analysis for the agents/automation module. It complements the implementation pages by focusing on how custom agents, subagents, tasks, slash commands, auto-mode, and hosted review compose without owning a different runtime rather than re-listing each constant.

Scope: custom agents from --agents, background agents (claude agents), task tools (TaskCreate/TaskGet/TaskList/TaskUpdate), task scheduling/completion, subagent lifecycle hooks, slash-command automation, auto-mode, ultrareview hosted review, and cron/timed tasks. Implementation specifics live in Agents, tasks, and subagents, Agent runtime, scheduling, and completion, and Slash commands and automation.

Module purpose

This module owns delegation and scheduled automation around the main session. It does not own model turns or tool execution; it composes them by:

  1. Letting users define agents (inline JSON or claude agents).
  2. Letting the model delegate work via task tools.
  3. Letting plugins/keybindings/skills trigger slash-command automation.
  4. Letting auto-mode classify and consent to common actions.
  5. Letting hosted ultrareview invoke multi-agent code review.

Architecture thesis

Agents and automation are orchestration over the existing runtime, not parallel runtimes. The same composition root, context loop, tool/permission boundary, and session envelope are reused; this module adds (a) a task store as shared state, (b) lifecycle hooks distinct from tool hooks, (c) a slash-command/keybinding/skill triggering surface, and (d) optional hosted backends.

Source anchors

Semantic aliasSourceApproximate locationString or symbolArchitectural meaning
AgentsCommandFamilycli.jsline ~19550, byte 0xdcc1acH.command("agents")Background agents command family registered on the root.
InlineAgentsFlagcli.jsline ~19525, byte 0xdc1fcb--agents <json>Inline custom-agent injection at session start.
TaskCreateToolcli.jsline ~1091, byte 0x4804f6var LX="TaskCreate"Task-tool constants used by orchestration.
TaskGetToolcli.jsline ~1091, byte 0x48050avar DQ="TaskGet"Task status/result retrieval constant.
TaskListToolcli.jsline ~1091, byte 0x48051bvar UZ="TaskList"Task listing constant.
TaskUpdateToolcli.jsline ~1091, byte 0x48052dvar J0="TaskUpdate"Task update constant.
SubagentContextClassifiercli.jsline ~253, byte 0x2104ceagentType==="subagent"Runtime classifier distinguishing subagent context.
SubagentLifecycleHookscli.jsline ~185, byte 0x10b75dSubagentStart, SubagentStopSubagent lifecycle hook events.
TaskLifecycleHookscli.jsline ~185, byte 0x10b7d5TaskCreated, TaskCompletedTask lifecycle hook events.
TaskNotificationFramecli.jsline ~930, byte 0x4674dctask_notificationOutbound frame carrying long-running task progress.
LongRunningMonitorContractcli.jsline ~185, byte 0x112031Each stdout line is delivered to the model as a <task_notification> event; the process runs for the session lifetime.Long-running monitor process specification.
UltraReviewCommandcli.jsline ~19550, byte 0xdcc963H.command("ultrareview [target]")Hosted multi-agent review command.
AutoModeCommandcli.jsline ~19550, byte 0xdccb56H.command("auto-mode")Auto-mode inspection/critique command.
AutoModePolicyConsentcli.jsline ~188, byte 0x127123[auto-mode] hasAutoModeOptIn=true policy defaultMode=auto implies consentAuto-mode consent precedence: policy implies opt-in.
AutoModeConsentSourcescli.jsline ~188, byte 0x127250[auto-mode] hasAutoModeOptIn=...skipAutoPermissionPrompt: user=... local=... flag=... policy=...Auto-mode multi-source consent computation.
SlashCommandKeybindingscli.jsline ~605, byte 0x39074fcommand:help, command:compactKeybinding actions that execute slash commands.
PluginSlashCommandSchemacli.jsline ~185, byte 0x1104d7slash command namePlugin schema turning command files into slash commands.
SkillSlashDispatchcli.jsline ~185, byte 0x11234evia Skill tool or slash commandSkill dispatch can be triggered by slash commands.
SkillShellExecutionPolicycli.jsline ~185, byte 0x11a8f2disableSkillShellExecutionPolicy boundary for slash-command/skill shell execution.
PromptSuggestionFramecli.jsline ~2004, byte 0x519dafprompt_suggestionPredicted-next-prompt frame; relevant to automation/auto-mode UX.

Internal decomposition

flowchart TD
Root[Root composition] --> AgentsCmd[claude agents]
Root --> AgentsFlag[--agents JSON]
Root --> Ultra[ultrareview]
Root --> AutoCmd[auto-mode command]
Root --> Slash[Slash command registry]
Session[Active session] --> Tasks[Task store]
Session --> Hooks[Subagent + task hooks]
Session --> Slash
Session --> AutoConsent[Auto-mode consent classifier]
Tasks --> TaskTools[TaskCreate / TaskGet / TaskList / TaskUpdate]
TaskTools --> Subagent[Subagent runtime context]
Subagent --> SubLoop[Context/model loop with agentType=subagent]
Hooks --> SubStart[SubagentStart / SubagentStop]
Hooks --> TaskLife[TaskCreated / TaskCompleted]
Slash --> Plugin[Plugin slash commands]
Slash --> Skill[Skill dispatch]
Slash --> Keybind[Keybinding command:*]
Slash --> Policy[disableSkillShellExecution]
Ultra --> Preflight[/v1/ultrareview/preflight]
Ultra --> Hosted[Hosted multi-agent run]
AutoCmd --> Inspect[defaults/config inspection]
AutoCmd --> Critique[AI critique of custom rules]
AutoConsent --> Permission[Permission boundary]
Sub-componentResponsibility
Custom agent injectionParses --agents JSON and merges with plugin/marketplace agents.
Background agents commandManages long-running agent jobs; reuses session/MCP/plugin/permission defaults.
Task storeShared state holding task records; addressed by TaskCreate/TaskGet/TaskList/TaskUpdate.
Subagent runtime contextA session-loop projection where agentType==="subagent" changes prompt boundaries and hook routing.
Lifecycle hooksSubagentStart/SubagentStop for subagents, TaskCreated/TaskCompleted for task records.
Slash command dispatcherResolves plugin command files, skill metadata, keybindings into commands.
auto-mode classifierComputes consent (user/local/flag/policy) and dispatches to the permission boundary.
Hosted review (ultrareview)Sends preflight, then invokes a hosted multi-agent run; mirrors results locally.
Task notification monitorOptional long-running process that emits <task_notification> frames per stdout line for the model.

Public interface

Inputs

SurfaceEffect
--agents <json>Inline custom agent definitions for the current session.
claude agents ... (with --setting-sources, --add-dir, --plugin-dir, --settings, --mcp-config, --strict-mcp-config, --permission-mode, --dangerously-skip-permissions, --model)Background-agent dispatch with session defaults.
ultrareview [target]Hosted multi-agent code-review entry.
auto-mode subcommandsInspect classifier defaults and critique custom rules.
Plugin slash commands (/plugin:about, …)Plugin-defined commands surfaced through the dispatcher.
Skill metadata / Skill toolSkill-based dispatch path.
Keybinding actions (command:help, command:compact)UI-driven slash command invocation.
Managed setting disableSkillShellExecutionTrust gate for inline shell in skills/custom slash commands.
Managed setting disableAgentViewHides the agent UI surface.

Outputs

OutputConsumer
task_notification framesHeadless multiplexer / SDK / TUI.
prompt_suggestion framesUX; relevant to auto-mode discoverability.
Subagent and task hook callsHook scripts/commands, telemetry.
Hosted review resultsLocal renderer / preflight metadata.
Auto-mode telemetry (tengu_auto_mode_decision, tengu_auto_mode_denial_limit_exceeded, tengu_auto_mode_fallback_to_ask, tengu_auto_mode_opt_in)Telemetry sink.

Internal collaborators

CollaboratorContract
Runtime lifecycleRegisters agents, ultrareview, auto-mode, and slash-command surfaces on the root command.
Context/model loopRuns subagent and task contexts as projections; emits prompt_suggestion after each turn.
Tool/permission runtimeReceives auto-mode consent decisions; runs task tools through the same boundary as built-ins.
Sessions moduleStores agent/task state; resume re-applies custom agents and any task records.
MCP/plugins/hooksPlugins contribute agents, skills, slash commands, and hooks; hosted review may coordinate with MCP.
Ops moduleReceives auto-mode/task/subagent telemetry; surfaces hosted-review failures via doctor.
Remote bridgeLong-running tasks and hosted review interoperate with remote variants via the same envelope.

Design decisions

  1. Tasks are constants, not classes. Task identity is conveyed through string constants (TaskCreate/TaskGet/TaskList/TaskUpdate), so the same task store works for any orchestrator producing those constants.
  2. Subagent is a context flag, not a separate loop. agentType==="subagent" changes prompt boundaries and hook routing within the existing context/model loop; this avoids forking the runtime.
  3. Lifecycle hooks are split. SubagentStart/Stop describe runtime context; TaskCreated/Completed describe persistent records. Splitting them lets hook scripts react to either dimension without conflation.
  4. Slash commands are a dispatcher, not a parser. Slash inputs flow from multiple sources (plugin files, skill metadata, keybindings) into one dispatcher, which routes through the existing runtime; this keeps the model’s view stable regardless of trigger.
  5. auto-mode is multi-source consent. Opt-in is computed from policy → user → local → flag, with the policy defaultMode=auto implying opt-in. This lets ops set default behavior without per-user changes.
  6. Hosted review is opt-in and explicit. ultrareview exists as its own command; it does not silently activate during normal turns.
  7. Notification monitor is well-scoped. The long-running process documented at byte 0x112031 runs for the session lifetime and emits one <task_notification> per stdout line — a narrow, predictable contract.
  8. Background agents reuse session flags. claude agents accepts the same --setting-sources, --add-dir, --plugin-dir, --settings, --mcp-config, --permission-mode, --model so deploys do not invent a parallel configuration surface.
  9. Auto-mode telemetry classifies decisions. tengu_auto_mode_decision, _denial_limit_exceeded, _fallback_to_ask, _malformed_tool_input, _opt_in cover the visible state machine so operators can audit behavior.

Orchestration patterns

PatternWhen used
Inline custom agent (--agents)Lightweight, session-only agent set; common in scripted runs.
Background agentsLong-running or repeated work that should outlive a single session command.
Subagent via Task toolsModel-driven delegation inside a turn; subagent runs in the same process.
Slash command + skillHuman-/keybinding-/plugin-triggered automation that is not model-initiated.
Auto-modeReduce per-action approval prompts when consent is established; explicit opt-in path.
ultrareviewHosted multi-agent code review with preflight checks; opt-in and explicit.

Failure modes

FailureBehavior
--agents payload invalidStartup error before mode dispatch.
Task tool input malformedBoundary rejection with structured error; auto-mode logs tengu_auto_mode_malformed_tool_input if applicable.
Subagent runs over a turn/budget capResult frame uses the same error subtypes as the main loop.
Subagent hook denyThe deny path propagates with the standard PermissionDenied semantics.
Auto-mode hits denial limittengu_auto_mode_denial_limit_exceeded is emitted; behavior falls back to ask.
Hosted review preflight rejectionUX surfaces the reason; no hosted run begins.
Slash command resolves to nothingDispatcher reports the unknown command without invoking model.
Managed policy disables skills’ shell executionInline shell in skills/custom slash commands becomes a placeholder; no covert escalation.

Extension points

ExtensionHow it plugs in
New agent kindProvide through --agents JSON, plugin schema, or claude agents registration; do not invent a parallel session loop.
New task fieldExtend task store metadata; orchestrators interact through the same TaskCreate/TaskUpdate constants.
New slash command sourceContribute via plugin schema or keybinding action; dispatcher handles routing.
Custom auto-mode ruleUse auto-mode config plus AI critique path; do not bypass the permission boundary.
Custom hosted review backendCompose at preflight; reuse the local rendering path.

Caveats

  • The exact task-store data shape is implementation-defined; this page documents responsibilities and interaction surfaces, not record layouts.
  • task_notification is a system-frame subtype; consumers should treat unknown task-notification fields as forward-compatible.
  • ultrareview references both local UX (/ultrareview, /review) and a hosted preflight route; behavior here is bounded by hosted availability and policy.

Created and maintained by Yingting Huang.