Skip to Content
AgentShield
Architecture

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
}
  • Validate returns an InvalidError for calls the adapter will not run. Its message is safe to return to the agent as 400 validation_failed, and it does not count toward the circuit.
  • Run receives 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.

gateway-tools.json
{
  "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

Operationssample.echo
ArgumentsIgnored
Side effectNone
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.

FieldContract
operationhttp.get, http.head, http.post, http.put, http.patch, http.delete
resourceCanonical URL scheme://host[:port]/path. No userinfo, query, fragment, or dot segments. Lowercase host. Exactly one spelling is accepted
arguments.queryObject of string or string-list values
arguments.headersOnly Accept, Accept-Language, If-Match, If-None-Match
arguments.bodyJSON, 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

OptionDefaultLimits
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
timeout5sUp to 30s
max_response_bytes262144 (256 KiB)Up to 4 MiB
allow_insecure_httpfalseRefused in production
allow_private_networksfalseRefused 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:

  1. Implement the interface in runtime/gateway/internal/adapter.
  2. Make Validate reject everything outside a narrow, canonical form, so policy resource rules can compare exactly.
  3. Keep secrets in the gateway: inject credentials from configuration, never from arguments.
  4. Bound time, response size, and recursion.
  5. Register it in Build behind a tools-file section with unknown fields rejected.
  6. 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.

Was this page helpful?

On this page