Skip to content
Kaiov0.8.0

An agent that runs Kaio

The Hermes Agent example runs an agent as a stack. This one turns it around: the agent connects to Kaio’s MCP server and looks after the host it runs on, answering “what is broken” from a chat and, once it has earned it, applying the updates itself.

It needs Kaio behind a proxy that names its callers, so the agent has a credential and a level of its own instead of sharing yours.

Start from SSO for people, a credential for machines: a second name served by the proxy, where each machine logs in with Basic auth and gets a group named after it. The agent line of that basic_auth block is this agent’s:

Terminal window
openssl rand -hex 32 > agent.password
caddy hash-password --plaintext "$(cat agent.password)"

On Kaio, map the agent’s group to read and set the MCP ceiling:

/etc/kaio/kaio.env
KAIO_GROUPS_READ=kaio-viewers,machine-agent
KAIO_MCP=write
KAIO_MCP_ALLOWED_HOSTS=kaio-api.example.net

KAIO_MCP=write is the most any caller can reach through /mcp, and the agent’s group keeps it at read for now. Nobody reaches the destructive tools this way.

Check the credential before handing it over:

Terminal window
KAIO_ADDR="https://agent:$(cat agent.password)@kaio-api.example.net" kaio-cli whoami

Hermes reads its MCP servers from config.yaml in its data volume. Build the header, then open a shell in the Hermes container:

Terminal window
printf 'agent:%s' "$(cat agent.password)" | base64 -w0
kaio-cli container shell <hermes-container>
Terminal window
cat >> /opt/data/config.yaml <<'EOF'
mcp_servers:
kaio:
url: "https://kaio-api.example.net/mcp"
headers:
Authorization: "Basic YWdlbnQ6..."
tools:
include:
- kaio_overview
- kaio_stack
- kaio_stack_compose
- kaio_stack_versions
- kaio_stack_plan
- kaio_logs
- kaio_images
- kaio_image_vulnerabilities
EOF

If config.yaml already has an mcp_servers: key, add kaio under it rather than appending a second one. The gateway watches the file and connects new servers by itself, within about a minute; the tools appear to the agent as mcp_kaio_kaio_overview and so on.

tools.include is the agent’s side of the ladder: Kaio decides what the credential may call, and the list decides what Hermes even offers the model.

From Telegram, Discord or whatever the gateway answers on:

  • Which stacks are not fully up, and why? kaio_overview, then kaio_logs on the stack it names.
  • Which images have critical CVEs, and which stacks use them? kaio_images, then kaio_image_vulnerabilities.
  • What changed in the blog stack since last week? kaio_stack_versions and kaio_stack_compose on two versions.

None of these can change anything: at read, no tool in the agent’s list writes, and Kaio would refuse one that did.

When the answers have been right for long enough, move the agent’s group up a rung and widen its list to the tools you want it to use:

/etc/kaio/kaio.env
KAIO_GROUPS_WRITE=kaio-devs,machine-ci,machine-agent
tools:
include:
- kaio_overview
- kaio_stack
- kaio_stack_versions
- kaio_stack_plan
- kaio_logs
- kaio_stack_check_updates
- kaio_stack_update
- kaio_stack_rollback
- kaio_scan

Leaving kaio_stack_deploy out is deliberate. It refuses a file asking for the socket or privileged: true until the agent repeats the call with accept_risks, but an agent can repeat a call, so it is still the one write tool to grant last. An update pulls the images a stack already names, and a rollback goes back to a version a person deployed.

Now check the stacks for updates, show me what each would change, and apply the ones that are only a patch release is a task the agent can carry out: kaio_stack_plan lays out each update before it runs, and kaio_stack_update with wait: true answers only once the stack is up again, putting back the images it ran before when it does not get there.

The agent is not alone on the host: you deploy, and so does CI. Two changes to one stack never run at once, the second is refused with code busy and the agent tries again later. And a rollback given the expected_version the agent read is refused with version_moved when someone deployed in between, so it reads the stack again instead of undoing a deploy it never saw.

Every write call lands in the audit log under the agent’s name, refused ones included:

Terminal window
kaio-cli audit --limit 50

To take it back: drop machine-agent from KAIO_GROUPS_WRITE, or delete its line in the proxy to cut it off entirely. Nothing on the agent’s side has to change for either to hold.

Kaio, built by Régis Gaidot