Runtime Flow

The runtime is the execution engine inside the local Aegis workspace. It keeps agent work bounded by workflow stages, task contracts, tool allowlists, verifiers, and approval checkpoints.

Run State Machine

intake -> plan -> prepare -> execute -> verify -> repair -> review -> finalize

Rules:

Verifier Repair Loops

Verifier failures are treated as feedback, not just terminal errors, when the workflow owns a bounded repair path.

Agent Profiles

Workflow templates can declare agentProfiles for task roles. These profiles describe the effective execution identity for each role:

When a profile omits provider or model, the task defaults to the run-level provider/model. This keeps current behavior stable while making the future multi-agent model explicit. Task records persist the effective profile in inputs.agentProfile, and model calls honor provider/model overrides from that profile.

Aegis also maintains a durable read-only agent profile registry. It is seeded from built-in coordinator defaults and workflow-template specialist roles. Registry entries include stable IDs, status, version, source, role, provider/model hints, prompt profile, tool allowlists, skill IDs, approval policy class, allowed policy classes, and metadata. Task-session details link back to the matching registry entry so the operator can inspect both the effective runtime profile and its durable source.

Profile changes use a review/activation path:

Future model routing should make agent profiles smarter without hiding decisions:

Current routing foundation:

Provider/model routing behavior is documented through the API reference, operator contracts, and model provider setup guide.

Secrets And Credentials

Provider API keys, Aegis API tokens, CLI credentials, and webhook secrets are represented as SecretRecord metadata plus local file-backed material.

Current foundation:

This prepares provider execution, LAN/mobile auth, webhook automations, and future connector credentials without mixing raw credentials into run artifacts.

Model-provider CLI subprocesses do not inherit the full operator environment. The runtime builds a bounded child environment from a documented allowlist, then layers only the provider credential variables resolved from the secret registry. The inherited allowlist is limited to process/runtime basics (PATH, HOME, user/shell names, temp directory variables, locale/color/CI flags, and Windows command-resolution variables) plus provider CLI config homes (CODEX_HOME, OPENCODE_HOME, XDG_CONFIG_HOME, XDG_CACHE_HOME, XDG_DATA_HOME, and XDG_STATE_HOME). Other AGENT_HARNESS_*, cloud, connector, or local shell variables are absent unless the selected provider credential explicitly maps a secret to that environment variable.

Coordinator And Task Sessions

Coordinator-led runs add a planning layer over the existing workflow runtime:

Coordinator chat currently has an intent layer before execution. A coordinator turn is classified as chat, clarify, plan, execute-small, execute-workflow, status, or steer. When live models are enabled, the coordinator profile’s provider/model can classify and answer; deterministic fallback keeps tests and offline local operation usable. Planning turns persist a pending plan and do not queue work until the user confirms. Small coding or analysis requests can route to single-agent workflows instead of always expanding to the full specialist workflow.

This intent layer is transitional. The target runtime is a model-backed coordinator loop with typed tools and structured action plans. The coordinator model should inspect conversation/run state, retrieve artifacts and approvals, delegate specialist work, and decide whether to answer, ask, steer, stop, resume, or queue work. The orchestrator should validate and execute those actions while preserving policy boundaries. See docs/architecture/model-backed-coordinator.md.

This keeps existing coding, research, provider-smoke, verifier repair, patch-bundle, and audit behavior intact while adding the backend primitives the dashboard needs.

Automation Lifecycle

Saved automations turn repeatable requests into durable definitions without hiding runtime policy checks.

Current foundation:

Memory And Context Lifecycle

Coordinator conversations, audio transcripts, task-session guidance, coordinator reports, verifier findings, and run summaries are durable source material for long-lived context.

Current foundation:

Planned lifecycle:

Memory and context behavior is documented through the API reference, settings walkthrough, and operator contracts.

Workspace Model

Each run receives an isolated workspace:

/run/{run_id}/
  goal.md
  workflow.json
  coordinator/
  plan.md
  tasks/
  work/
  reviews/
  final/
  evals/
  logs/
  manifest.json

Policy Model

The policy engine classifies each action with an action type, policy class, domain, risk level, approval requirement, implementation flag, and audit requirement.

Implemented classes:

Implemented high-risk classes:

Prepared but blocked high-risk action types/classes:

Approvals are surfaced as checkpoints rather than implicit side effects. Checkpoints persist the action type, policy class, risk level, policy decision, evidence, reviewer decision, and timestamps. Policy decisions are also emitted to the trace log so a run has an audit trail for allowed, blocked, and approval-gated actions.

Coordinator/operator approval has three practical forms:

Future connectors for purchases, trades, tax workflows, network administration, device control, and broader self-extension already have explicit action types and policy classes, but they are marked unimplemented and blocked. Adding a live connector must first change that policy deliberately, add verifier coverage, and preserve approval checkpoints and audit traces.

Repo Write Bundles

Coding workflows do not approve a loose intent to mutate the repository. Small coordinator-managed coding requests use one patch-author agent to produce concrete edits, then verify and apply the exact bundle if checks pass. Larger coding and self-development workflows may still use planner, patch-author, verifier, and reviewer stages, but the implementation handoff is always a patch bundle rather than a plan-as-output. For git repositories, single-agent coding runs first create an isolated worktree and branch named for the run. The runtime snapshots the operator’s current tracked working-tree changes into that branch as a baseline, lets the worker edit the isolated checkout, then converts the branch diff back into an approval-gated patch bundle. For non-git repositories or fallback paths, patch authors may provide complete post-change file contents, or exact oldText/newText replacements for large files; the runtime expands replacements into full-file contents before hashing, validation, approval, and application. Before a repo-write approval is recorded or requested, the verifier stage writes:

The verifier stage refuses to create a repo-write approval checkpoint when disposable-copy validation fails. The approval checkpoint records the bundle hash, file before-hashes, and validation artifact. Start/internal checkpoints may be coordinator-approved only when the model-backed coordinator has inspected the approval and the executor marks that specific checkpoint as bounded. Repo-write patch bundles, external side effects, and unsupported high-risk actions are human-owned. Finalize recomputes the bundle from current workspace/repo state and refuses to apply if the proposed edits or repo file hashes changed after approval was recorded.

Repo-write tool calls are approval-contextual: an approved repo-write checkpoint only authorizes repo.write-text for files listed in that checkpoint evidence, with matching proposed content hash and current before-hash. A generic approved repo-write action does not unlock arbitrary repository mutation.

Self-development bundles include scope metadata: workflow mode, base git commit when available, allowed and blocked path rules, required commands, rollback notes, aggregate risk labels, and per-file risk labels. The scope report mirrors this metadata so approval review can distinguish documentation/test-only changes from policy, runtime, schema, dependency, workflow, or self-extension-surface changes.

Audit Export

Aegis can export a run audit package through GET /runs/:id/audit or export-audit <run-id> [output-json-path]. The package includes run metadata, summary, jobs, tasks, coordinator delegation plan, task sessions, steering events, coordinator conversation events linked to the run, coordinator reports, approvals, evaluations, trace events, and an artifact manifest with size and SHA-256 hashes. It intentionally exports artifact metadata rather than copying every artifact body into one large object.

For debugging and reproduction, GET /runs/:id/replay-packet and replay-packet <run-id> [output-json-path] return a smaller run replay packet: run state, summary, captured run input, workflow snapshot, task inputs, model trace summaries with prompt/response hashes, task sessions, approvals, evaluations, trace tail, artifact hashes, artifact manifest, verifier command, repo/workspace paths, and a dry-run replay plan. replay-from-packet <packet.json> --dry-run validates the packet and prints the required inputs and replay steps without mutating the repo or Aegis state. Replay packets are intended for operator troubleshooting; full audit exports remain the archival record.