/engineering:ai-agent-runtime-architecturefrom engineering
Designs multi-tenant agent runtimes: state machines, durable resumability, retries, idempotency, step caps, cancellation, and workflow boundaries.
Ships in engineering. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
| Artefact | Required? | Purpose |
|---|---|---|
| Task state model, tools, durability, timeout, retry, cancellation, tenant, memory, and budget boundaries | yes | Define safe runtime transitions |
Skill-specific outputs:
agent_tasks and agent_steps table schemas.Read/search are required. Runtime implementation, queue changes, migrations, replay, and cancellation tests require explicit authority and isolated fixtures.
Fallback without a runnable environment: produce the state machine and unverified test plan; do not claim runtime enforcement.
| Workload | Runtime choice | Failure avoided |
|---|---|---|
| Short, deterministic, read-only request | Bounded synchronous flow | Unnecessary orchestration |
| Long, retryable, or externally waiting | Durable state machine | Lost or duplicated work |
| Irreversible or costly step | Approval and checkpoint | Unbounded blast radius |
agent.task.started, agent.step.completed, agent.task.paused, agent.task.killed, agent.task.completed) for observability and back-office.ai-agents-tools.ai-agent-multi-agent-coordination.ai-agent-async-and-long-running-tasks builds on this skill.ai-on-saas-architecture.ai-on-saas-architecture) — gateway, audit log, prompt registry.saas-entitlements-and-plan-gating).distributed-systems-patterns, reliability-engineering).ai-agent-eval, ai-agent-safety-and-red-team).SKILL.md.ai-agent-cost-and-step-budgets for full enforcement).task_id, tenant_id, feature, model_pin, prompt_version, tool_set_version, step_budget, wallclock_budget, cost_budget, created_at, state.agent_steps with step_index, state_before, action, observation, tokens, usd_cost, latency_ms before the next step runs.agent.task.budget_exceeded, and surfaces in the agent inbox.ai-agent-safety-and-red-team, saas-admin-backoffice-tooling).max_execution_time > 30s. Always queued.while (not_done) { call_llm(); execute_tool(); } inside a Flask/Express request handler. First failure leaves orphan side-effects.send_email sends twice.maxSteps not enforced or set to 100). One bad prompt drains USD-thousands.feature or prompt_version recorded on the task row. Replay impossible.| Category | Artifact | Format | Example |
|---|---|---|---|
| Correctness | Agent runtime service spec | Markdown + diagram | docs/ai/agent-runtime.md |
| Correctness | State-machine transition test suite | CI report | tests/ai/agent_state_machine_test.py |
| Release evidence | Resumability drill report | Markdown | docs/runbooks/agent-resumability-drill.md |
| Operability | Task lifecycle event taxonomy | YAML | ops/events/agent-task-events.yaml |
references/agent-loop-state-machine.md — formal state machine, transitions, idempotency contract.references/agent-vs-workflow-vs-cron-decision.md — decision matrix with worked examples.references/agentic-ai-operating-model-source-synthesis.md - autonomy ladder, production spine, tool contracts, memory/RAG discipline, multi-agent roles, deployment stages, and human-agent operating model distilled from supplied agentic AI source material.ai-agents-tools, ai-agent-tool-catalogue-and-action-gating, ai-agent-cost-and-step-budgets, ai-agent-observability-and-replay, ai-agent-async-and-long-running-tasks, ai-on-saas-architecture, distributed-systems-patterns, reliability-engineering.Most "we need an agent" requests are workflows in disguise. An agent is only the right tool when:
If steps are fixed, prefer a workflow — same LLM calls, deterministic order, vastly cheaper to test, debug, and operate. See references/agent-vs-workflow-vs-cron-decision.md.
QUEUED -> PLANNING -> ACTING -> OBSERVING -> COMPLETED
| |
| +-> PLANNING (continue or revise)
+-> AWAITING_APPROVAL -> ACTING or terminal rejection
Any active state may transition to FAILED, BUDGET_EXCEEDED, KILLED, or ABANDONED.
Terminal states: COMPLETED, FAILED, BUDGET_EXCEEDED, KILLED, ABANDONED.
All state transitions write to agent_steps before the next state is entered. A worker crash between two steps re-enters the loop in the last persisted state. See references/agent-loop-state-machine.md.
| Wallclock cap | Resumability requirement | Substrate |
|---|---|---|
| < 30s | Best-effort | Inline in HTTP request (only for read-only agents) |
| < 5 min | At-least-once | Queue worker (BullMQ, Celery, RQ, Sidekiq) |
| < 1 hour | Exactly-once | Durable workflow engine (Temporal, Inngest, Restate) |
| Hours / days | Exactly-once + resume on deploy | Durable workflow engine, mandatory |
For anything writing to customer state, never run inline in the HTTP handler. The customer's request times out and the agent keeps spending.
Before entering PLANNING and ACTING, the loop checks four budgets:
| Budget | Check point | Action on exceed |
|---|---|---|
step_budget (max iterations) | Before each PLANNING | Transition to BUDGET_EXCEEDED, emit event, summarise progress |
wallclock_budget_seconds | Before each state transition | Same |
cost_budget_usd | After each LLM call | Same |
tool_cost_budget_usd | Before each ACTING | Same |
Budgets come from ai-agent-cost-and-step-budgets. The runtime is the enforcement point.
Every side-effecting tool call carries an idempotency key derived from (task_id, step_index, tool_name, arg_hash). If a worker crashes after the side-effect but before persistence, the next worker's tool call short-circuits to the recorded result.
def execute_tool_with_idempotency(task_id, step_idx, tool_name, args):
idem_key = sha256(f"{task_id}:{step_idx}:{tool_name}:{stable_json(args)}")
cached = idempotency_store.get(idem_key)
if cached:
return cached # tool already ran; replay the recorded observation
result = tools[tool_name].run(args, idempotency_key=idem_key)
idempotency_store.put(idem_key, result, ttl_days=30)
return result
Tools that cannot accept an idempotency key (legacy APIs) must be wrapped in an outbox pattern with a deduplication table. See distributed-systems-patterns.
| Event | When | Used by |
|---|---|---|
agent.task.created | Enqueue | Audit log, observability |
agent.task.started | Worker claims | Observability, agent inbox UI |
agent.step.completed | After OBSERVING | Trace, replay |
agent.task.awaiting_approval | HITL transition | Approval UI, mobile push |
agent.task.approved / agent.task.rejected | HITL outcome | Audit, resume |
agent.task.budget_exceeded | Budget hit | Cost ops, support |
agent.task.killed | Manual kill | Back-office, audit |
agent.task.completed | Success | Customer notification, eval |
agent.task.failed | Unrecoverable error | Support, eval |
random.uuid().Every state-machine transition emits a compliance event onto the hash-chained action audit log (ai-agent-audit-log-integrity). The runtime is the canonical source of compliance evidence for ai-agent-soc2-controls CC7.2 (monitoring), PI1.1 (processing integrity), and ai-agent-iso27001-controls A.8.15 (logging, ISO/IEC 27001:2022).
Minimum event taxonomy emitted by the loop:
| Transition | event_class | Required fields |
|---|---|---|
| Task accepted | task_accepted | task_id, tenant_id, agent_id, intent_summary, policy_version |
| Plan committed | plan_committed | task_id, plan_hash, step_count |
| Tool call started | tool_call_started | task_id, step_index, tool_name, tool_version, reversibility, data_class |
| Tool call ended | tool_call_ended | task_id, step_index, outcome, idempotency_key, latency_ms |
| Approval required | approval_required | task_id, step_index, tool_name, approver_role |
| Approval received | approval_received | task_id, step_index, approval_id, approver_id |
| Kill-switch flipped | kill_switch_flipped | scope, actor, reason, drill_run_id (nullable) |
| Budget breached | budget_breached | task_id, budget_kind, threshold, observed |
| Memory write | memory_write | task_id, tier, retention_class, subject_id (hashed) |
| Erasure step | erasure_step | request_id, step, status |
| Task closed | task_closed | task_id, terminal_state, verdict_ref |
Every event carries policy_version so historical authority checks resolve correctly (see ai-agent-compliance-controls/references/ai-agent-approval-audit-completeness). Emissions are synchronous on the critical path for irreversible-action transitions and kill_switch_flipped; everything else may be batched with at-most-1s drain.
Cross-links: ai-agent-audit-log-integrity, ai-agent-soc2-controls, ai-agent-evidence-automation, ai-agent-compliance-controls/references/ai-agent-approval-audit-completeness.
references/routing.md to map retired AI child skill slugs to their reference modules.../../sdlc-meta/references/book-driven-system-decision-and-agent-orchestration.md for autonomy, side-effect, escalation, rollback, and currentness controls.references/agent-loop-state-machine.md (opens in a new tab)references/agent-vs-workflow-vs-cron-decision.md (opens in a new tab)references/agentic-ai-operating-model-source-synthesis.md (opens in a new tab)references/ai-agent-async-and-long-running-tasks/entrypoint.md (opens in a new tab)references/ai-agent-async-and-long-running-tasks/references/durable-state-patterns.md (opens in a new tab)references/ai-agent-memory/entrypoint.md (opens in a new tab)references/ai-agent-memory/references/forget-on-erase-cascade.md (opens in a new tab)references/ai-agent-memory/references/memory-tiers.md (opens in a new tab)references/routing.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub peterbamuhigire/chwezi-dev-engine --plugin engineering169 skills in this plugin
/accounting-engineUse when designing or implementing double-entry accounting policy and an embedded ledger engine for invoices, payments, stock, balanced postings, mapped accounts, idempotency, reversals, period locks, audit trails, and financial statements./accounting-finance-controllerUse when coordinating accounting and finance implementation reviews, doctrine routing, control evidence, remediation priorities, and release decisions across a software system./advanced-testing-strategyUse when designing or reviewing test strategy for production systems, APIs, mobile apps, SaaS platforms, ERP workflows, and AI-enabled systems. Covers unit, integration, contract, end-to-end, regression, release-gate, and risk-based testing decisions./ai-agent-commercial-operationsUse when pricing, billing, refunding, recognizing revenue, or packaging commercial terms for agentic AI services, or when defining agent SLAs, customer commitments, SLA dashboards, breach credits, and service evidence./ai-agent-compliance-controlsUse when mapping AI agent operations to SOC 2, ISO 27001, HIPAA, audit logs, control testing, attestations, and compliance evidence, including drill-cadence evidence, approval-completeness (PI1.1) gap checks, and signed agent-memory erasure proofs./ai-agent-governance-and-limitsUse when defining agent budgets, step limits, reversibility, blast-radius controls, kill switches, and governance policy for agentic AI systems.Other plugins' skills for the same job