Skip to Content
AgentShield
Contributing

Writing Integrations

Rules and patterns for adding a framework integration, a language client, or a gateway adapter to AgentShield without creating a bypass.

Every integration in AgentShield follows one rule: there must be no path that runs a tool without a gateway decision. This page explains how the existing integrations meet that rule and how to build new ones.

Framework integrations

A framework integration adapts the framework's tool interface to the SDK. Use the existing ones as templates:

PatternExampleBuilds on
A tool class per gateway toolLangChain GatewayTool, CrewAI GatewayCrewToolagentshield_sdk.tools.ToolSpec and invoke
A node or server that forwards named callsLangGraph GatewayToolNode, GatewayMCPServerClient.call_tool

Requirements

  1. No local callable. The constructor accepts a client and specs or names. Reject func, coroutine, handlers, and unknown fields with TypeError. Use the framework's strict model configuration (extra="forbid") where available.
  2. Only the SDK executes. Call invoke, call_tool, authorize, or execute. Never call a function after an allow.
  3. Outcomes are results. Return deny, approval, and errors as content the model can read, or as the framework's tool-error type. Never fall back to running something locally.
  4. Fixed resources stay fixed. If a spec fixes the resource, refuse a model-supplied resource that differs.
  5. Pass analysis through. Include analysis and warning with allowed results.
  6. Bind arguments. When executing yourself, pass the exact authorized arguments.
  7. Name collisions fail. Building several tools with the same name raises.

Tests

Add tests under tests/ that use a fake client and assert:

  • passing a function or extra field raises TypeError;
  • deny and require_approval never call execute;
  • a fixed resource cannot be changed;
  • results include analysis and warning when present;
  • the framework's async path (if any) does not block the event loop.

CI must install the framework and fail if the tests skip.

Language clients

A client in a new language must reproduce the signing input exactly and pass the shared vector in runtime/identity/identity_test.go. It must:

  • serialize once and sign the bytes it sends;
  • generate a fresh nonce per request;
  • refuse redirects;
  • accept a decision only with status 200 or 403;
  • expose authorize, execute, and a call_tool that executes only on allow;
  • never accept a local tool function.

The TypeScript SDK in sdk/typescript is a compact reference: about 300 lines with no runtime dependencies.

Gateway adapters

Adapters are the only code that performs side effects. Adding one is a security-sensitive change that needs an ADR.

  1. Implement adapter.Adapter in runtime/gateway/internal/adapter.
  2. Accept only a narrow, canonical resource form so exact policy rules cannot be bypassed by alternate spellings.
  3. Validate everything in Validate, which must have no side effects. Return InvalidError with a message safe for agents.
  4. Keep credentials in gateway configuration; never accept them from arguments.
  5. Bound time, size, and recursion; respect the context deadline.
  6. Add a section to the tools file that rejects unknown fields, and refuse unsafe development options in production.
  7. Write tests that fail if the adapter runs twice, reaches a refused destination, or leaks a credential.

See Tool execution architecture.

Documentation

Add a page under apps/docs/content/docs/integrations/ with verified examples, and link it from the integration overview.

Was this page helpful?

On this page