AI SRE Agent Architecture
How to assemble an SRE agent from Autohand Code CLI parts: sub-agents, piped data and MCP servers, structured diagnosis, patches, permission rules, hooks and traces.
Overview
Autohand Code CLI has no separate SRE agent, orchestrator service or sre command. An “SRE agent” is a normal Autohand run that you start from a script, a CI job or a terminal, with the right context, tools and limits. This guide shows how the pieces fit together.
The architecture has five parts:
- Orchestration: the main agent delegates focused work to sub-agents you define with
--agents - Signal input: alert payloads and logs piped in, or read through MCP servers
- Diagnosis: a read-only run whose answer must match a JSON Schema
- Action: fixes produced as patches, under permission rules and hooks
- Audit and review: event streams, hooks and agent traces, plus runbooks your team updates after each incident
Orchestration with sub-agents
Define specialist sub-agents for one run with --agents. Each entry needs a description and a prompt, and can limit its tools and set a model. The main agent hands work to them with its delegate_task and delegate_parallel tools.
cat alert.json recent-errors.log \
| autohand --ephemeral --restricted -p "Diagnose this incident. Ask log-analyst and change-reviewer in parallel, then combine their findings." \
--agents '{
"log-analyst": {
"description": "Finds the first error and the failing component in log excerpts",
"prompt": "You read logs. Report the earliest error, the component that raised it, and the timestamps. Do not change files.",
"tools": ["read_file", "find_grep"]
},
"change-reviewer": {
"description": "Checks recent commits for changes that match the failure",
"prompt": "You review git history. List commits from the last 24 hours that touch the failing component and explain why each could matter.",
"tools": ["read_file", "find_grep", "run_command"]
}
}'
To reuse the same sub-agents across runs, keep them as files in an agents directory and pass the directory path instead: --agents ./sre-agents. See Sub-agents.
Signal input
Autohand does not collect metrics, logs or traces itself. Give it the signals in one of two ways:
- Pipe them in: fetch the alert, metrics and log excerpts with your own tools and pipe them to
autohand -p. Piped input is added to the prompt as context. - Add an MCP server: register your monitoring vendor’s MCP server so the agent can query it during the run.
# Pipe a log excerpt and a metrics export into a run
kubectl logs deploy/payment-service --since=30m > recent-errors.log
cat alert.json recent-errors.log metrics.csv \
| autohand --restricted -p "Summarise what these signals show."
# Or register an MCP server for your monitoring stack
autohand mcp add monitoring -- npx -y <your-monitoring-mcp-package>
autohand mcp add --transport http monitoring https://mcp.example.com/mcp
Keep log excerpts short and relevant. Filter by time window and service before piping, so the context holds the evidence rather than noise.
Diagnosis
Run the diagnosis with --restricted so nothing dangerous can run, and with --output-schema so the answer is a JSON document your automation can route on. If the answer does not match the schema, the command exits with status 1.
{
"type": "object",
"required": ["suspect_component", "causal_chain", "confidence", "runbook"],
"properties": {
"suspect_component": { "type": "string" },
"causal_chain": { "type": "array", "items": { "type": "string" } },
"confidence": { "type": "string", "enum": ["low", "medium", "high"] },
"runbook": { "type": "string" }
}
}
cat alert.json recent-errors.log \
| autohand --ephemeral --restricted \
-p "Diagnose this incident using the code in this repository and the runbooks in runbooks/." \
--output-schema diagnosis.schema.json --json local \
| jq -r .content > diagnosis.json
The causal chain is the model’s reading of the evidence you gave it. Treat confidence as a hint for routing, not a measured probability, and have a person check the chain before acting on it.
Context and memory
There is no incident database or vector store built in. The agent knows what is in the repository and what you pass to the run: runbooks, past postmortems, AGENTS.md (which autohand init creates), and any file you add with --append-system-prompt-file. Keeping postmortems in the repository is the simplest way to let later runs find similar incidents. See Memory.
Action and guardrails
Write remediation steps as Markdown runbooks in the repository, not as an action-chain config. Then ask Autohand to prepare the fix as a patch, so nothing changes until a person applies it:
autohand -p "Apply the fix in diagnosis.json, following runbooks/$(jq -r .runbook diagnosis.json)." \
--patch --output incident-fix.patch --max-duration 600
# After review
git apply incident-fix.patch
Patch mode captures file edits instead of writing them, but it approves tool calls automatically. Add --disallowed-tools run_command,shell when the run should not execute shell commands.
Policy enforcement
Autohand does not use an external policy engine. These controls decide what a run may do:
permissions.denyListin the config blocks commands for every run, for example"run_command:kubectl delete:*"--allowed-toolsand--disallowed-toolslimit the tools for one run--restricteddenies all dangerous operations;--planstarts in read-only plan mode- A
pre-toolhook that exits with code 2 blocks the tool call, so you can add your own checks, such as change windows
{
"permissions": {
"denyList": ["run_command:kubectl delete:*", "shell:kubectl delete:*", "run_command:terraform destroy:*", "shell:terraform destroy:*"]
},
"hooks": {
"enabled": true,
"hooks": [
{
"event": "pre-tool",
"matcher": "run_command",
"command": "./scripts/check-change-window.sh"
}
]
}
}
The hook receives HOOK_TOOL and HOOK_ARGS (JSON) in its environment. Hooks do not run with --bare, so do not rely on them for runs that use it.
Audit and review
Record what each run did:
--output-format stream-jsonwrites every tool event as JSON lines you can store with the incident- A
post-toolorfile-modifiedhook sends each action to your own log autohand traces onturns on local agent trace monitoring with metadata sync to Autohand Console;autohand traces statusshows the current state. See Agent traces.
cat alert.json \
| autohand --restricted -p "Diagnose this incident." --output-format stream-json \
> incidents/INC-1234/run.jsonl
autohand traces status
Autohand does not learn from incident outcomes or tune alert thresholds on its own. Improvement comes from your team: after each incident, have Autohand draft the postmortem and the runbook change as a patch, review it, and merge it. The next run reads the updated runbook.
cat diagnosis.json incident-timeline.md \
| autohand -p "Write a postmortem in postmortems/ and update the matching runbook with what we learned." \
--patch --output postmortem.patch
Integration points
Autohand reaches the rest of your stack through general interfaces, not built-in connectors:
| Category | How Autohand connects |
|---|---|
| Telemetry | Piped exports, or an MCP server for your monitoring tool |
| Incident tools | Your alerting system calls a script or CI job that runs autohand -p; an MCP server can read or update tickets |
| Knowledge | Runbooks, postmortems and AGENTS.md in the repository |
| People | Post the diagnosis and patch to your chat or ticket from the calling script |
| Infrastructure | Shell commands through run_command, limited by permissions.denyList and hooks |
Deployment considerations
Context size
- Filter logs and metrics before piping them in
- Use sub-agents for large searches so the main run keeps a short context
- Set
--max-duration,--max-requestsand--max-tokenson unattended runs
Security and guardrails
- Use
--restrictedfor diagnosis and--patchfor fixes, so a person approves every change - In CI and containers,
--barereads credentials fromAUTOHAND_PROVIDER,AUTOHAND_API_KEYandAUTOHAND_AI_API_KEY; keep those in your secret store - Store
stream-jsonoutput with the incident record as the audit trail
See Incident Response for the full flow and Headless mode for running Autohand from scripts.