Blog

The model decides. The call layer executes.

Why always-on agents like OpenClaw and Hermes need a strict layer between the model's decisions and your APIs.

Chilarai Mushahary

Co-founder, CTO

AI AgentOct 8, 2026

Why I'm writing this

I build a lot of agent demos, and I run Hermes on my own machine every day. Agents like Hermes and OpenClaw aren't chat windows you open and close. They run all day, take messages from Telegram, Slack or Discord, run jobs on a schedule, and call real APIs while I'm doing something else.

Once an agent runs like that, the model matters less than you'd expect. What matters is everything that happens after the model has decided what to do: where the key lives, how the request is built, what happens when it fails, and whether anyone can check it later. This post is about that part, and why I think it belongs in its own layer.

How these agents make a call today

From what I've seen, an always-on agent reaches an API in one of three ways.

1. A shell tool. The agent writes curl or a short script and runs it:

curl -s https://api.stripe.com/v1/refunds \
  -u "$STRIPE_SECRET_KEY:" \
  -d charge=ch_123 -d amount=5000

The model builds every part of this from memory: the URL, the auth scheme, the body format, and what to do if it fails. The key has to be in the shell's environment, so the agent can read it, and so can anything that talks the agent into running env.

2. A skill or plugin per service. Someone writes a wrapper for one API. Every service needs its own, and each one handles auth, errors and retries its own way, if at all.

3. An MCP server per service. This is the right shape, but most of these servers turn every endpoint into its own tool and pass the call straight through. Whatever the server doesn't do, nobody does.

In all three, the boundary between the model's decision and the real API is usually very thin. Nothing consistently checks the call against your rules, adds the credential at the last moment, retries safely, or writes down what happened. That's the gap I want to talk about.

Hooking it up

For Hermes, Swytchcode is one entry in ~/.hermes/config.yaml:

mcp_servers:
  swytchcode:
    command: swytchcode
    args:
      - mcp
      - serve

Any agent that supports MCP servers can connect the same way. Agents built around skills, like OpenClaw, can also run the CLI from a skill. Either way, the agent works in three steps: find a capability, read its schema, run it.

swytchcode discover "refund a stripe charge" --json
swytchcode info refunds.refund.create --json
swytchcode exec refunds.refund.create --json --body '{"charge":"ch_123","amount":5000}'

Here's what I think that layer gets right for agents, and where its limits are.

1. The tool list doesn't grow with your APIs

If every endpoint is an MCP tool, every tool's name, description and schema goes into the context on every turn. The Stripe spec in one of my demo projects has 587 methods. That project has about 1,900 methods across all its providers.

The agent profile exposes 7 tools, however many providers are installed:

["swytchcode_add", "swytchcode_discover", "swytchcode_exec", "swytchcode_info",
 "swytchcode_list", "swytchcode_policy", "swytchcode_search"]

discover returns the top 5 matches by default, and info loads one schema when the agent needs it. The agent pays in tokens for the method it's about to use, not for the whole catalogue. For an agent that runs for hours, that difference adds up on every turn.

2. The agent fills in a schema, it doesn't build a request

The model never writes HTTP. It fills in a schema, and the same code builds every request.

Stripe is a good example. It wants form-encoded bodies with nested keys like metadata[source]=agent. Models often send JSON, or get the nesting wrong. With Swytchcode, the agent passes JSON and the request goes out in the format the spec says:

{"body":"email=a%40acme.com&metadata%5Bsource%5D=agent","headers":{"Authorization":"[REDACTED]","Content-Type":"application/x-www-form-urlencoded"},"method":"POST","url":"https://api.stripe.com/v1/customers"}

The schema is cleaned for the agent too. Credential parameters like api_key and access_token are removed, so the agent doesn't ask for a token or make one up. Google's extra query parameters are dropped. http_method and endpoint are included, so two similar methods are easy to tell apart.

3. Keep credentials out of the agent's context

The credential is added when the call is sent, from the connected account. It's never in the prompt, the schema or the output, and dry runs show it as [REDACTED]. Response policies can also redact secrets that come back from an API, like Stripe keys, GitHub tokens or private keys, before the agent sees them.

One honest caveat: if the agent also has an unrestricted shell as the same user, it can read any file that user can. What Swytchcode does is keep credentials out of the model's context and its tools. I give agents the MCP tools for API work and keep secrets out of the shell's environment.

4. The agent can only reach the hosts you allow

Prompt injection on an always-on agent usually ends with "send this data to some URL". If tooling.json limits which hosts the agent can reach, calls to anything else are refused. Redirects are checked against the same list, so a 3xx can't send a call somewhere it isn't allowed to go.

5. Responses are sized for a context window

A long-running agent can't afford a 5 MB JSON response landing in its context. By default, max_response_bytes cuts a response at 100 KB and marks it "truncated": true. The cut-off body comes back as a string, so it never breaks JSON parsing. A 10 MB hard limit applies everywhere. Binary files need --output <file>, so raw bytes never end up in the context at all.

6. Errors are a contract, not prose

Every error has the same fields: category, retryable, suggested_action. Exit codes are fixed: 6 for a policy block, 7 for waiting on approval, 4 for failing after retries. My agents check the category, not the message text.

retryable is the field I care about most. It's only true when sending the call again is safe. A POST that got a 503 comes back with "retryable": false, because the provider may have already acted on it. An agent that trusts the field won't send the same email twice.

7. Rules live outside the prompt

A prompt tells the model what it should do. A policy decides what the system will let it do.

"Never refund more than $500" in a system prompt is a suggestion the model can forget or be talked out of. In policies.json, it's checked by code before every call:

{
  "id": "large-refunds",
  "target": ["refunds.refund.create"],
  "when": { "field": "amount", "operator": ">", "value": 50000 },
  "action": { "type": "REQUIRES_APPROVAL", "message": "Refunds over $500 need approval" }
}

For an always-on agent, the approval goes to Slack or Telegram, the same place I already talk to it. The agent sees exit code 7, knows the call is waiting, and gets on with other work.

The agent profile can read policies but can't add or remove them, so the agent can't loosen its own rules. Policies can also match on $caller (CLI or MCP) and $mcp_client, so I can be stricter with the agent than with myself.

8. Identity comes from the caller, not the model

A bot in a team chat serves more than one person. If you build a product on top of an agent, you have the same problem many times over: whose Gmail should this call read?

The answer should never come from the model. With the SDK, I set the end user once per request, from my app's own verified user id:

const client = new Swytchcode(provider, { tenantId: req.user.id });

Every call then runs with that person's connected account, or it doesn't run. It never falls back to mine. The tenant id isn't a tool argument, so the model can't see it or change it. For a chat platform, take it from the platform's verified sender id, never from text the user typed.

The MCP server, on the other hand, runs as one account: mine. That's fine for a personal agent like my Hermes setup. For anything with more than one user, I use the SDK.

9. Retries behave the same at 3am

Scheduled jobs hit every flaky moment an API has. Retries are settings per provider, not something the model works out each time:

  • 429, 503 and 504 are retried with backoff and some randomness.
  • Retry-After is honoured. If it's longer than the call's time limit, the call fails straight away with the real reason, instead of waiting and timing out.
  • A POST is only retried when idempotency is on. Then every retry carries the same Idempotency-Key, so the provider can drop the repeat.
  • max_concurrent limits parallel calls to one provider, so a burst of scheduled jobs doesn't hit the provider's rate limit.

10. It's built to stay running

mcp serve is a long-lived process. Agents make lots of small calls, and a provider spec can be large: the Stripe bundle in my demo project is 2 MB on disk. The parsed spec stays in memory and is only parsed again when the file's size or modified time changes. Usage events go to a local SQLite queue and are sent in the background, so a call never waits on reporting, and a dropped connection doesn't lose events.

11. There's a record

Every exec writes an entry to a local audit log. Each entry has the tool, the outcome and how long it took, and every HTTP attempt with its host, status and duration, so retries show up as separate attempts. When a call fails, the entry has the error category. When a policy is involved, it has the policy id, the decision (blocked, approved, denied or monitored) and the field and value that matched, with the arguments redacted. For an end user's call, it has their tenant id.

In the morning, I can see what the agent did overnight:

swytchcode audit network          # outbound calls
swytchcode audit stats            # history and success rate
swytchcode audit policy blocked   # what a policy stopped
swytchcode audit policy hitl      # what's still waiting for a person

Where the limits are

None of this makes an agent safe on its own, and I'd rather be clear about that:

  • It isn't a sandbox. It controls the calls that go through it, not the machine the agent runs on. See the shell caveat above.
  • $mcp_client is self-reported. The client names itself when it connects. I use it to make rules stricter, never to make them looser.
  • Policies only cover calls that go through Swytchcode. If the agent can still curl the API directly, a rule in policies.json won't stop it.

Summary

When I started building with always-on agents, I spent most of my time on prompts. Now I spend it on the layer underneath.

Models will keep getting better at deciding. The execution layer doesn't need to get smarter. It needs to get more predictable.

Credentials should be added outside the model. Policies should be enforced outside the prompt. Identity should come from the caller. Retries should follow settings, not guesses. And every action should leave a record.

Let the model decide. Let the call layer enforce. That's the layer we're building at Swytchcode.

Use any AI coding agent

Give this prompt to your agent and get started.

More from the blog