Architecture Comparison

Proxy vs Agent Framework Hooks: Where to Put Tool-Call Controls

For a single agent framework with disciplined code paths, framework hooks can provide adequate tool-call control. For multi-framework environments, MCP-based deployments, or compliance programs requiring one audit trail, proxy or gateway enforcement provides the consistent, bypass-resistant control point that framework hooks cannot guarantee alone. Most mature architectures use both: hooks for context-aware checks, a proxy for final mediation.

Two Different Control Points, One Governance Problem

Enterprise teams deploying AI agents face a basic architectural choice: where should tool-call controls live? Agent frameworks like LangChain and Microsoft AutoGen expose in-process hooks. LangChain's callback handler interface (on_tool_start, on_tool_end) lets developers intercept, log, or block tool calls within the framework's own execution loop. AutoGen provides similar human-in-the-loop confirmation and function-call interception mechanisms. These hooks execute inside the same application process as the agent, giving them access to in-process reasoning and state context that an external layer cannot see.

An alternative is to enforce controls through a proxy or gateway that intercepts tool calls at runtime, outside the agent's code. This mirrors the policy enforcement point (PEP) pattern described in NIST SP 800-207's Zero Trust Architecture, where a centralized component mediates every access request between a subject and a resource, regardless of which application generated it.

Neither OWASP's LLM Top 10 nor NIST's AI Risk Management Framework prescribes which placement to use. Both call for monitoring and least-privilege enforcement, and OWASP's "Excessive Agency" category describes exactly this risk, without specifying where in the stack that enforcement should sit. That decision is an architecture choice enterprises have to make deliberately rather than inherit by default.

Framework Hooks vs Proxy Enforcement

Bypass Risk and Blind Spots

Framework-hook enforcement depends on every code path in the agent invoking the callback system. LangChain's documented callback architecture runs within the same process as the agent, so hook coverage is only as strong as the consistency of the code that calls it. A custom tool-calling path, a forked chain, or a direct API call that bypasses the standard execution loop can skip the hook entirely, and most frameworks provide no built-in way to detect that this happened.

Proxy-based enforcement removes this dependency on application code by mediating calls externally, but it introduces a different bypass vector. If an agent retains direct network egress to a tool endpoint, it can call that endpoint directly and skip the proxy altogether. Proxy enforcement is only as strong as the network controls that force all tool traffic through the gateway.

In practice, framework hooks are vulnerable to code-path gaps, and proxies are vulnerable to network-path gaps. Evaluating either approach requires identifying which gap is more likely in a given deployment and whether it can realistically be closed.

Where MCP Fits Into the Decision

The Model Context Protocol (MCP), released by Anthropic in November 2024, adds a third layer to this picture. MCP defines a host-client-server architecture in which MCP servers expose tools, resources, and prompts that a host application invokes through a client. This separation creates a protocol-level interception point distinct from both framework callbacks and application-level proxies.

MCP's own security guidance instructs hosts to obtain explicit user consent before invoking a tool and not to fully trust server-supplied tool descriptions. This guidance describes a trust boundary, not an enforcement mechanism, and it does not mandate where that enforcement is implemented. In practice, the host/client layer MCP describes can coincide with a gateway component, which is one reason enterprises adopting MCP are revisiting where their tool-call controls sit rather than assuming existing framework hooks will automatically cover MCP-mediated calls.

Layering Controls for Defense in Depth

Framework hooks and proxy enforcement are not mutually exclusive. Hooks can perform context-aware checks that depend on an agent's reasoning or state at that execution point, while a proxy can perform a final, framework-independent check immediately before a tool call reaches its destination. This layered pattern resembles the defense-in-depth principle behind zero trust's PEP model, although no current guidance documents this exact combination as a named pattern specifically for AI agents.

For teams running a single framework with disciplined code paths, hooks alone may provide adequate coverage with lower operational overhead. For teams running multiple frameworks, using MCP across heterogeneous agent stacks, or needing a centralized audit trail for compliance review, a proxy or gateway layer provides the single enforcement point and consolidated logging that framework-specific hooks cannot produce on their own.

Trussed AI's runtime governance platform enforces tool-call policy at the proxy layer, applying agent identity, least-privilege permissions, and tool approval workflows independently of the underlying agent framework, with audit logging consolidated across frameworks and MCP servers.

Three Possible Enforcement Points

Each layer sees a different slice of agent activity, which is why most architectures end up combining more than one.

Framework Hooks

In-process callbacks (LangChain, AutoGen) that intercept tool calls within the agent's own execution loop.

Proxy / Gateway Layer

An external component that mediates tool calls at runtime, independent of which framework generated them.

MCP Host-Client Boundary

The protocol-level separation where MCP hosts invoke server-exposed tools through a client.

Questions to Evaluate Before Choosing a Control Point

Use this checklist to pressure-test whether your current enforcement layer actually covers your architecture.

  • Does our agent architecture span multiple frameworks, and can framework-specific hooks provide consistent policy enforcement across all of them?
  • Can developers bypass framework-level hooks via custom tool-calling code paths, and what detection controls exist for that?
  • Does a proxy or gateway layer have visibility into MCP server interactions, or only direct API-based tool calls?
  • What audit log format and retention does each enforcement layer produce, and does it meet our compliance requirements?
  • If adopting MCP, does the host application enforce the protocol's recommended consent and trust-boundary checks, or is this left entirely to the agent framework?
  • If we rely on a proxy, have we closed off direct network egress from agents to tool endpoints?

Decide Where Your Tool-Call Controls Actually Enforce

Map your agent architecture against framework-hook coverage and proxy enforcement before assuming either one is sufficient on its own.

Request a Demo