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:
| Pattern | Example | Builds on |
|---|---|---|
| A tool class per gateway tool | LangChain GatewayTool, CrewAI GatewayCrewTool | agentshield_sdk.tools.ToolSpec and invoke |
| A node or server that forwards named calls | LangGraph GatewayToolNode, GatewayMCPServer | Client.call_tool |
Requirements
- No local callable. The constructor accepts a client and specs or names. Reject
func,coroutine, handlers, and unknown fields withTypeError. Use the framework's strict model configuration (extra="forbid") where available. - Only the SDK executes. Call
invoke,call_tool,authorize, orexecute. Never call a function after an allow. - 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.
- Fixed resources stay fixed. If a spec fixes the resource, refuse a model-supplied resource that differs.
- Pass analysis through. Include
analysisandwarningwith allowed results. - Bind arguments. When executing yourself, pass the exact authorized arguments.
- 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_approvalnever call execute; - a fixed resource cannot be changed;
- results include
analysisandwarningwhen 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_toolthat 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.
- Implement
adapter.Adapterinruntime/gateway/internal/adapter. - Accept only a narrow, canonical resource form so exact policy rules cannot be bypassed by alternate spellings.
- Validate everything in
Validate, which must have no side effects. ReturnInvalidErrorwith a message safe for agents. - Keep credentials in gateway configuration; never accept them from arguments.
- Bound time, size, and recursion; respect the context deadline.
- Add a section to the tools file that rejects unknown fields, and refuse unsafe development options in production.
- 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?