Model-Backed Coordinator Rebuild
This document defines the replacement target for the current coordinator conversation path.
The current coordinator is model-assisted, but it is still mostly a code-routed intent switch. It asks a model to classify a turn, then TypeScript routes the result through fixed branches such as chat, status, steer, or queue run. That is not the intended product.
The intended coordinator is an AI agent with durable context, known tools, known skills, bounded delegation authority, and policy-enforced side effects. The model should decide which coordinator tools to call, inspect relevant state, delegate specialist work when needed, and answer the user from observed facts. Code should validate and execute actions, enforce policy, record audit trails, and prevent unsafe or inconsistent mutations.
Target Behavior
The coordinator should be able to handle requests like:
- “Implement the proposed patch.”
- “What is going on with the last agent?”
- “Stop that run and ask a smaller coding agent to fix it.”
- “Use the plan from above but make the UI less disruptive.”
- “Find the patch proposal, check whether it was applied, and tell me what changed.”
- “Start a research agent, then have a reviewer check the sources.”
For each turn, the coordinator should:
- Read the current conversation and relevant memory.
- Inspect active and recent runs when the message refers to prior work.
- Call tools to retrieve run state, task sessions, artifacts, approvals, and traces as needed.
- Decide whether to answer, ask a question, stop/pause/resume work, attach guidance, delegate work, request approval, or create a new run.
- Produce a structured action plan.
- Let the orchestrator validate and execute only allowed actions.
- Tell the user what happened and why, using facts from tool results.
Architectural Principle
Model reasoning owns interpretation. Deterministic code owns authority.
The coordinator model should handle:
- conversational meaning
- follow-up references
- choosing which state to inspect
- deciding when specialist agents are needed
- decomposing work into delegated tasks
- summarizing progress and blockers
- explaining decisions to the user
The runtime should handle:
- schema validation
- tool permission checks
- policy enforcement
- approval checkpoints
- exact patch-bundle verification
- idempotency and duplicate-action prevention
- run/task/session persistence
- traces, artifacts, and audit exports
Hardcoded text matching is acceptable only as a fallback for offline tests, defensive safety gates, or compatibility shims. It should not be the primary coordinator intelligence path.
Validation and persistence must not recreate the old failure mode. The coordinator should not be boxed into a tiny set of hardcoded intent branches. The model must retain meaningful authority to inspect, reason, delegate, stop, guide, ask, answer, and queue work through known tools. Runtime checks should answer “is this action allowed and well formed?” rather than “did this message match a TypeScript phrase list?”
Coordinator Loop
The new coordinator loop should replace the current fixed intent path:
user message
-> build coordinator context packet
-> model chooses tool calls or final action plan
-> execute read-only coordinator tools
-> repeat until enough context is gathered
-> model emits structured action plan
-> orchestrator validates action plan
-> execute approved actions
-> append coordinator response
The loop is bounded by max tool calls, max model turns, timeout, and token budget. If the model cannot produce a valid action plan, the coordinator should ask for clarification or report the failure with the inspected state.
Coordinator Tools
Coordinator tools are not raw shell access. They are typed Aegis operations with scoped permissions and audit records.
Required read tools:
conversation.get: read current conversation, recent events, attachments, active run, and linked memory.conversation.search: find earlier events and run links in the current conversation.runs.list: list active and recent runs with status, goal, workflow, and timestamps.runs.getWorkspace: read run status, progress, task sessions, approvals, artifact index, and coordinator reports.runs.readArtifact: read a named artifact from a run.taskSessions.get: read task session details, event stream, model calls, tool uses, guidance, artifacts, and file changes.approvals.list: list pending and recent approvals.memory.search: retrieve relevant active memory and memory candidates.profiles.list: inspect available coordinator and specialist profiles.capabilities.list: inspect known tools, skills, workflow templates, and policy classes.workspace.gitStatus: inspect the requested repo or active run repo branch, HEAD, and dirty worktree state.workspace.gitDiff: read a bounded staged/unstaged diff summary for commit preparation.
Required action tools:
runs.queue: create a run or single-agent task from a structured request.taskSessions.delegate: create delegated specialist work with role, objective, inputs, expected artifacts, and permissions.taskSessions.guidance: attach guidance to active or follow-up task sessions.taskSessions.stop: stop active specialist work.runs.pause: pause a run.runs.resume: resume a paused run.runs.cancel: cancel a run.git.commit: stage and commit the requested file set when the operator explicitly asked for a commit.git.push: push the requested branch/remote when the operator explicitly asked for a push or gave conversational approval to push.conversation.answer: append a coordinator answer without queueing work.conversation.requestClarification: ask the user for missing information.approval.present: surface a pending approval with evidence and required review.
High-risk action tools remain policy-gated. The coordinator can request or present approval checkpoints, but cannot silently bypass policy.
Delegation Authority
The coordinator should have explicit authority to delegate safe bounded work without a code path selecting a workflow from text matching.
Delegation should be model-planned and runtime-validated:
- The model proposes specialist roles, objectives, dependencies, expected artifacts, and needed capabilities.
- The runtime checks whether the coordinator profile may delegate those roles.
- Each specialist profile bounds tools, skills, model routing, and policy classes.
- Work that mutates the repo must still produce a verified patch bundle before application.
- External side effects remain blocked or approval-gated by policy.
The coordinator should be able to choose between:
- answering directly
- using one specialist
- using multiple specialists
- asking a reviewer/verifier agent to inspect results
- continuing an existing run
- canceling redundant work
- starting a new run only when needed
Structured Action Plan
The model should emit a validated action plan instead of only an intent label.
Minimum shape:
{
"summary": "Short description of what the coordinator decided.",
"rationale": "Why this action follows from the conversation and inspected state.",
"actions": [
{
"type": "answer",
"content": "User-facing response grounded in inspected state."
}
],
"references": {
"conversationEventIds": [],
"runIds": [],
"taskSessionIds": [],
"artifactPaths": []
},
"risk": {
"requiresApproval": false,
"policyClasses": []
}
}
Action types should include:
answerask-clarificationqueue-rundelegate-taskattach-guidancestop-task-sessionpause-runresume-runcancel-runpresent-approvalcreate-memory-candidate
The executor should reject invalid references, missing evidence, unsupported action types, disallowed profiles, and policy violations.
Context Packet
Every coordinator turn should receive a compact but useful packet:
- latest user message
- full conversation event history, plus a recent-events subset for compact scans
- active run summary
- recent linked runs
- pending approvals
- task-session rollups
- relevant memory records
- available coordinator tools
- available specialist profiles
- relevant capabilities and workflow templates
- policy summary
The model can call tools to expand run, artifact, approval, and task-session details. Conversation context should not be reduced to a narrow recent window in the live coordinator path; otherwise pasted examples and follow-up corrections can be misread as the current task.
Testing Strategy
Tests should validate behavior rather than phrase matching.
Required scenario tests:
- A user says “implement the proposed patch” after a patch was already applied; coordinator inspects run artifacts and answers that it is done.
- A user says “apply it” after a patch bundle exists but approval is pending; coordinator surfaces the approval evidence.
- A user says “what happened?” after a failed model call; coordinator reads the task session events and explains the failure.
- A user says “stop that agent”; coordinator identifies the active task session and stops it.
- A user says “use the smaller workflow”; coordinator attaches guidance or starts a single specialist depending on run state.
- A user asks for a UI fix; coordinator delegates one coding specialist with proper repo-write bundle behavior.
- A user asks for parallel research and coding; coordinator delegates multiple bounded agents with dependencies.
- A user asks for a high-risk external side effect; coordinator refuses or presents an approval checkpoint depending on implemented policy.
Unit tests should cover schema validation, tool permission checks, policy enforcement, and duplicate-action prevention. Integration tests should run the coordinator loop with a fake model gateway that selects tools based on inspected state.
Implementation Task List
Phase 1: Define Contracts
- Add
CoordinatorToolCall,CoordinatorToolResult,CoordinatorActionPlan, andCoordinatorActionschemas. - Add action plan validation to shared contracts.
- Add typed references for conversation events, runs, task sessions, approvals, artifacts, profiles, tools, skills, and memory records.
- Add a coordinator turn transcript record that captures model tool calls, tool results, final action plan, validation result, and executed actions.
Phase 2: Build Coordinator Tool Runtime
- Implement read-only tools: conversation, runs, task sessions, artifacts, approvals, memory, profiles, and capabilities.
- Implement action tools: answer, clarify, queue, delegate, guidance, stop, pause, resume, cancel, and present approval.
- Add per-tool permission metadata and policy class metadata.
- Record every coordinator tool call in trace/audit state.
- Keep raw filesystem, shell, network, and repo mutation unavailable to the coordinator except through approved specialist work.
Phase 3: Replace Intent Routing
- Replace
classifyCoordinatorIntentas the primary path with a bounded model-tool loop. - Keep deterministic fallback only for offline tests and explicit no-model mode.
- Remove one-off conversational text matchers from the primary live-model path.
- Make “status”, “follow-up”, “apply prior patch”, “steer active work”, and “queue work” emerge from model tool use and action planning.
Phase 4: Delegation Planner
- Let the coordinator model propose specialist tasks directly.
- Validate proposed roles against coordinator profile authority.
- Validate specialist tool/skill/profile permissions.
- Support one-agent and multi-agent task graphs without requiring separate text-routed workflow templates.
- Preserve workflow templates as reusable scaffolds, not the only way to delegate work.
Phase 5: Policy And Approval Integration
- Keep repo writes bound to exact verified patch bundles.
- Keep high-risk external actions blocked or approval-gated.
- Add duplicate-action checks for applying already-applied patches, restarting redundant runs, and repeated approvals.
- Ensure the coordinator can present approval evidence but cannot forge approval review.
- Make policy reasons visible in coordinator responses.
Phase 6: Dashboard Integration
- Show coordinator tool calls and inspected state in the agent chat overlay.
- Show when the coordinator is thinking, inspecting, delegating, waiting on tools, or executing an action plan.
- Render action plans, delegated tasks, approvals, and final answers as conversation-native events.
- Preserve user selection and scroll behavior while live updates arrive.
Phase 7: Evaluation
- Add scenario tests for conversational follow-ups.
- Add fake-model integration tests for tool-use loops.
- Add replay packets for coordinator turn failures.
- Add dashboard smoke tests for live coordinator progress and action-plan rendering.
- Add a “why did the coordinator do that?” explanation view based on coordinator turn transcripts.
First Refactor Slice
The first coding slice should be small enough to land safely but should follow the final architecture:
- Add the action-plan and tool-call schemas.
- Add a coordinator tool registry with read-only tools for conversation, runs, task sessions, artifacts, and approvals.
- Implement a model-tool loop behind a feature flag or runtime mode.
- Route coordinator live-model turns through the tool loop.
- Keep the existing intent path only as deterministic fallback.
- Add tests proving “implement the proposed patch” is solved by inspecting artifacts, not by text matching.
Once that slice works, remove the tactical patch-followup matcher from the live path.
Next Action Plan
Treat this section as the active task list for the next implementation pass. The goal is to harden the model-backed coordinator path without reducing it back to a brittle router.
Current Progress
- Completed: model-backed coordinator tool-call and action-plan contracts.
- Completed: primary live coordinator path now asks the model for tool calls/action plans before falling back to deterministic intent routing.
- Completed: read tools for conversation, runs, task sessions, artifacts, approvals, memory, profiles, and capabilities.
- Completed: action execution for answer, clarify, queue, delegate, guidance, stop, pause, resume, cancel, present approval, and memory-candidate responses.
- Completed in this slice: durable coordinator turn transcripts are persisted for model-backed turns, linked from coordinator response events, exposed through
GET /coordinator/conversations/:id/turns, and covered by migration/API/service tests. - Started in this slice: action-plan validation now checks references and rejects stale/redundant approval, run, and task-session actions before execution, recording blocked transcripts instead of falling through to deterministic fallback.
- Started in this slice: duplicate queue prevention blocks model plans that reference an active equivalent run while trying to start the same work again.
- Started in this slice: active-run follow-ups stay with the model-backed coordinator by default. The coordinator is prompted to inspect and answer through tools while a run is active; runtime validation blocks implicit queue/delegate actions unless the user explicitly asks for a new, separate, parallel, or additional workstream.
- Started in this slice: delegated specialist roles are validated against active agent profiles, and delegated runs prefer the selected profile’s workflow/model hints.
- Started in this slice: compatible multi-
delegate-taskaction plans now create one coordinated run with custom delegated tasks and planned session dependencies. - Started in this slice:
delegate-task.dependencyActionIdslets the model declare dependencies between new delegated actions; validation rejects unknown, duplicate, self-referential, and cyclic dependency graphs. - Started in this slice: the shell dashboard fetches conversation-scoped coordinator turn transcripts and renders compact expandable turn details under coordinator responses.
- Started in this slice: live coordinator turns now include full conversation events in the model context packet, attempt model-based schema repair for invalid action plans, and surface coordinator planning failures instead of silently falling back to deterministic routing.
- Started in this slice: coordinator read tools now honor model-provided scope and filters, so
approvals.listscoped to a conversation does not leak unrelated old approvals andruns.list status=activedoes not return completed runs. - Started in this slice: repairable runtime validation failures, such as pasted sample artifact paths being mistaken for current run artifacts, are fed back to the coordinator model for one corrected action plan before blocking.
- Started in this slice: action plans that require approval without a real approval checkpoint or work action are treated as repairable consistency failures, so the model can queue work instead of asking the user to approve a nonexistent patch bundle.
- Remaining: deeper claim/evidence validation, broader duplicate-action coverage, richer transcript panel links, replay/audit integration, and cleanup of tactical fallback matchers.
Guardrails
- Keep the live coordinator path model-first: model chooses tools, model emits action plan, runtime validates and executes.
- Do not add new conversational phrase matchers to decide behavior in the live model path.
- Deterministic matching is allowed only for no-model fallback, safety checks, schema validation, and tests.
- Validation must check references, permissions, policy, and duplicate actions; it must not decide user intent.
- Tools must honor the model’s explicit scope and filters. If the model asks for conversation-scoped approvals or active runs, the runtime should return those facts accurately instead of widening the query behind the model’s back.
- Repairable validation errors should be returned to the model for a corrected action plan once. Non-repairable policy, permission, duplicate-work, stale-approval, and invalid-dependency failures should still block.
- The coordinator should never ask the user to approve a repo patch that does not exist. It should present an existing approval checkpoint, queue/delegate work that can produce a patch bundle, or ask a clarification.
- Active-run follow-ups are coordinator conversation by default. The model can inspect, answer, guide, stop, pause, resume, approve/reject allowed checkpoints, or ask a clarification. Starting another workstream requires an explicit user request for separate work.
- The coordinator should be able to delegate bounded work without a hardcoded workflow tree choosing everything for it.
- High-risk effects remain policy-gated, but safe read/inspect/answer/guide/stop/delegate operations should be easy for the coordinator to perform.
- Approval decisions are structured coordinator actions. The coordinator may approve only executor-marked bounded start/internal checkpoints after tool inspection; repo-write patch bundles and external side effects must be presented to the human.
Task List
- Persist coordinator turn transcripts. Status: completed for model-backed turns; follow-up links to context packets/trace events remain.
- Add a durable
coordinator_turnsor equivalent table. - Store source conversation event ID, status, model prompt kind, tool calls, tool results, action plan, validation errors, executed actions, timestamps, and linked run/session/artifact/approval references.
- Record failed model-tool turns instead of silently falling back with no explanation.
- Add schema migration coverage.
- Add contract/schema tests.
- Add a durable
- Add coordinator transcript read APIs. Status: conversation-scoped list endpoint added; single-turn and compact summary APIs remain.
- Add service methods to list turns for a conversation and retrieve one turn.
- Add API endpoints for conversation-scoped coordinator turn history.
- Include compact transcript summaries in conversation details or run workspace where useful.
- Keep raw large tool-result content expandable rather than always embedded in main conversation payloads.
- Expose “why did the coordinator do that?” data.
- Link coordinator response events to transcript IDs.
- Link transcripts to context packets and trace events.
- Add a derived explanation object with inspected tools, evidence, selected actions, validation checks, and execution result.
- Surface pending approvals in the new dashboard. Status: inline conversation approval controls added to the chat shell.
- Load
GET /approvals/queueinto the new dashboard shell. - Render pending approvals in the conversation flow rather than a separate dashboard panel.
- Keep human decisions to simple Approve/Reject controls under the relevant artifact links.
- Show whether a checkpoint is coordinator-approvable, human-owned, or unknown.
- Load
- Add structured coordinator approval decisions. Status: bounded
decide-approvalaction added.- Add a typed action-plan action for approval decisions.
- Remove the live coordinator approval text-matching shortcut so the model-backed path can inspect state and decide.
- Validate approval/run references and pending status before execution.
- Allow coordinator approval only for executor-marked bounded start/internal checkpoints.
- Include enough information to debug wrong coordinator behavior without reading raw logs.
- Strengthen action-plan validation. Status: started; reference checks and stale state checks are in place.
- Validate referenced run IDs, task session IDs, approval IDs, artifact paths, memory IDs, profile IDs, and capability IDs before executing actions.
- Reject
present-approvalunless the approval exists and is pending. - Reject
stop-task-session,pause-run,resume-run, andcancel-runwhen the referenced state makes the action invalid or redundant. - Reject
answerclaims about applied patches or approvals unless tool results or references support the claim. - Return validation failures as coordinator-visible responses instead of silently routing through fallback.
- Add duplicate-action prevention. Status: started for stale approval presentation, redundant terminal run/task actions, duplicate active-run queueing, and implicit new workstreams during active-run follow-ups.
- Prevent applying or presenting an already-decided approval as if it were pending.
- Prevent queueing a new run when a model action plan references an already-running equivalent task and only needs guidance/status.
- Prevent queueing or delegating new work from an active-run follow-up unless the user explicitly requests a separate workstream.
- Prevent duplicate stop/cancel/resume actions from creating misleading conversation events.
- Add tests for repeated “apply it”, “stop that”, and “run it again” follow-ups.
- Improve delegation semantics. Status: started; delegated roles must resolve to active specialist profiles, profile workflow/model hints are used when queueing delegated work, compatible multi-delegate plans are grouped into one coordinated run, and explicit delegate dependencies are supported.
- Replace the temporary
delegate-task -> inferred single-agent workflowmapping with a validated delegation planner. - Validate the requested specialist role against coordinator profile authority.
- Validate specialist profile tool allowlist, skill IDs, policy classes, and model routing.
- Support multiple delegated tasks with dependencies from one action plan.
- Preserve workflow templates as reusable scaffolds, not the only delegation mechanism.
- Replace the temporary
- Implement multi-agent task graph execution. Status: started for compatible profile-backed delegated tasks in one workflow-backed run with model-declared action dependencies.
- Let an action plan create several specialist task sessions or a run-level delegation plan directly.
- Support dependencies between researcher, coder, reviewer, verifier, and summarizer roles.
- Ensure task sessions remain inspectable and steerable.
- Keep repo writes on verified patch-bundle rails.
- Remove tactical live-path matchers.
- Ensure model-backed planning errors never silently fall through to
classifyCoordinatorIntentorhandlePatchProposalFollowup. - Remove the live-path dependency on
handlePatchProposalFollowup. - Keep only no-model fallback behavior for offline/local deterministic operation.
- Add tests proving patch follow-ups, status follow-ups, steering, and approval presentation go through tool calls/action plans.
- Ensure model-backed planning errors never silently fall through to
- Improve coordinator prompts. Status: started for active-run conversational behavior.
- Add the persisted transcript schema and action validation rules to the coordinator prompt.
- Include available tools and specialist profiles in a compact form.
- Include full conversation event history so the model can distinguish the current request from quoted samples, old approval text, and follow-up corrections.
- Add a schema-repair turn when the model returns malformed action-plan JSON.
- Teach the model to inspect before acting on ambiguous references.
- Teach the model to prefer inspecting, answering, continuing, stopping, or guiding existing active work over starting redundant runs.
- Add scenario coverage.
- “What happened?” after a failed/stuck model call.
- “Stop that one, use a smaller agent.”
- “Apply it” with pending approval.
- “Apply it” after already applied.
- “Research this and have a reviewer check it.”
- “Do not start work yet, just explain the plan.”
- “Use the previous plan but change the UI behavior.”
- “Continue the last run with this added constraint.”
- Dashboard transcript UI. Status: started; coordinator response messages now include compact expandable turn details for transcript status, tools, action plans, validation errors, and delegated tasks.
- Show coordinator states: thinking, inspecting, reading artifacts, presenting approval, delegating, stopping, validating, executing.
- Render tool calls and results as compact expandable rows.
- Show action-plan summary and executed actions.
- Link tool results to run/session/artifact/approval panels.
- Preserve append-only updates so selection and scroll are not disrupted.
- Audit and replay integration.
- Include coordinator transcripts in audit export.
- Include coordinator turn failures in replay packets.
- Add trace events for tool-call started/completed/failed, action-plan validated/rejected, and action executed.
- Make transcript hashes available for integrity checks.
- Cleanup and simplification.
- Delete obsolete intent-router branches once the tool loop covers the scenarios.
- Move fallback logic into a clearly named no-model path.
- Remove redundant text-matching helpers from live execution.
- Update docs to mark completed slices and remaining gaps.