Tool Execution Architecture
The adapter registry, the adapter interface, the built-in sample.echo and http.request adapters, and the tools configuration file.
Tools run only inside the gateway, through adapters. An adapter is Go code registered under a tool name. The agent never receives a function to call; it receives a result.
The adapter interface
type Adapter interface {
Name() string // tool name, e.g. "http.request"
Supports(operation string) bool // which operations it implements
UsesArguments() bool // whether execute must present bound arguments
Timeout() time.Duration // 0 means the gateway default (2 s)
Validate(call Call) error // no side effects; runs before the claim
Run(ctx context.Context, call Call) (map[string]any, error) // at most once per execution
}Validatereturns anInvalidErrorfor calls the adapter will not run. Its message is safe to return to the agent as400 validation_failed, and it does not count toward the circuit.Runreceives a context with the deadline. It must respect cancellation.- The returned map is the result. The gateway stores a redacted copy and returns the live copy on the first call.
The registry
The registry maps tool names to adapters. A duplicate name is a startup error. sample.echo is always registered. Other adapters are enabled by the JSON file named in GATEWAY_TOOLS_CONFIG; unknown fields in that file are rejected.
{
"http": {
"timeout": "5s",
"max_response_bytes": 262144,
"hosts": [
{
"host": "api.github.com",
"headers": {
"Authorization": { "env": "AGENTSHIELD_GITHUB_AUTHORIZATION" }
}
},
{ "host": "httpbin.org" }
]
}
}At startup the gateway logs the registered adapter names. A request for a tool or operation with no adapter returns 501 not_implemented. It never runs a placeholder.
sample.echo
| Operations | sample.echo |
| Arguments | Ignored |
| Side effect | None |
| Result | { adapter, label, operation, resource } |
Use it to verify identity, policy, approvals, and auditing end to end without touching another system.
http.request
The first adapter with a real side effect. It turns an authorized decision into one HTTPS request.
| Field | Contract |
|---|---|
operation | http.get, http.head, http.post, http.put, http.patch, http.delete |
resource | Canonical URL scheme://host[:port]/path. No userinfo, query, fragment, or dot segments. Lowercase host. Exactly one spelling is accepted |
arguments.query | Object of string or string-list values |
arguments.headers | Only Accept, Accept-Language, If-Match, If-None-Match |
arguments.body | JSON, at most 256 KiB, only for post, put, and patch |
Any other argument key is refused.
Result
{
"status": 200,
"headers": { "Content-Type": "application/json; charset=utf-8", "Etag": "\"abc\"" },
"truncated": false,
"json": { "id": 1296269, "full_name": "octo/hello" }
}JSON bodies are returned parsed under json, other UTF-8 under text, and binary under body_base64. Only Content-Type, Content-Length, Etag, Last-Modified, Location, and Retry-After response headers are returned. Set-Cookie and everything else are dropped. A 3xx response is returned as-is; redirects are not followed.
Tools file options
| Option | Default | Limits |
|---|---|---|
hosts[].host | — | Lowercase hostname, optional port. IP addresses are refused |
hosts[].headers | — | Header name → { "env": "VAR" }. Host, Content-Length, Transfer-Encoding, Connection cannot be injected |
timeout | 5s | Up to 30s |
max_response_bytes | 262144 (256 KiB) | Up to 4 MiB |
allow_insecure_http | false | Refused in production |
allow_private_networks | false | Refused in production |
Injected header values come from the gateway's environment. The tools file contains only variable names, so it can be committed. An empty or missing variable stops the gateway at startup.
Network controls
The dialer checks the resolved IP address immediately before connecting, so DNS rebinding between lookups cannot reach an internal address. Proxy environment variables are ignored. See SSRF protection for the blocked ranges.
Writing an adapter
New adapters follow the same shape. Each must be designed for the scope it is limited to:
- Implement the interface in
runtime/gateway/internal/adapter. - Make
Validatereject everything outside a narrow, canonical form, so policy resource rules can compare exactly. - Keep secrets in the gateway: inject credentials from configuration, never from arguments.
- Bound time, response size, and recursion.
- Register it in
Buildbehind a tools-file section with unknown fields rejected. - Add tests that fail if the adapter runs twice, follows a redirect, or reaches a refused address.
See Custom tool integration for how agents call adapters, and Writing integrations for contribution guidelines.
Implementation references
Was this page helpful?