Claude Agents Integration
Claude Agents SDK wrapper and agent loop governance.
Overview
ClaudeAgentGuard wraps an Anthropic client so every messages.create() response is validated before it reaches your code or triggers a tool call.
Tier: Team+
Why It Matters
Claude Agents run autonomous tool-use loops. Governance must intercept loop outputs without breaking the agent's tool execution flow.
Prerequisites
pip install agentrust-py
# Team+ API key
# Claude Agents SDK installed in your environmentStep-by-Step Guide
wrap_client() returns a proxy — it is not a context manager. Use the returned
object in place of the original client.
from anthropic import Anthropic
from agentrust_sdk import ClaudeAgentGuard
guard = ClaudeAgentGuard(
agent_id="claude-agent",
base_url="http://127.0.0.1:8765", # adapter default is :8000
)
client = Anthropic()
governed = guard.wrap_client(client) # use `governed` from here on
response = governed.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Analyze this document"}],
)To govern a whole agent loop instead of individual calls, wrap the loop function:
@guard.wrap_loop
def run_agent(query: str) -> str:
...Each governed call sends the response text and any tool calls to the gateway; with the
default block_on_block=True a block decision raises BlockedError.
Examples
See agentrust_sdk/agentrust_sdk/adapters/claude_agents.py in the repository for implementation details.
Best Practices
- Wrap at the client level for consistent coverage
- Use
block_on_block=Truefor sensitive document processing - Combine with PII policy pack for customer data
Common Mistakes
- Catching
TierGateError— the guard raises plainRuntimeErrorat construction - Calling
guard.wrap(...)— the methods arewrap_client()andwrap_loop() - Continuing to use the original client instead of the returned proxy
Troubleshooting
| Issue | Fix |
|---|---|
RuntimeError: [AgentTrust] Claude Agents adapter requires Team tier… | Upgrade to Team (this is not a TierGateError) |
| Loop interrupted | Check if block outcome is expected; review policy |