As autonomous agents move from experimental sandboxes to production-grade infrastructure, the tension between flexibility and control becomes the primary architectural bottleneck. Developers often find themselves hard-coding guardrails directly into the agent’s core execution flow, resulting in brittle systems where policy updates require full-cycle deployments. To address this, we have open-sourced our governance layer, which utilizes a hexagonal architecture to strictly separate business logic from policy enforcement.
The core premise of this design is that an agent should remain agnostic of its own constraints. By treating governance as an externalized concern that wraps the agent’s core, we can iterate on safety policies, audit logging, and resource limits without modifying the underlying model integration or task-specific code.
The Hexagonal Pattern in Agent Systems
In a traditional monolithic agent, the orchestration logic, state management, and safety checks are often tightly coupled. This leads to ‘governance leakage,’ where security logic permeates every function. By applying the Ports and Adapters (hexagonal) pattern, we define a strict interface for execution.
The ‘Inside’ contains the pure agent logic—the intent formulation and tool selection. The ‘Outside’ consists of adapters for LLM providers, database state, and the governance layer itself. The governance layer acts as a middleware that intercepts all inputs and outputs (I/O) to the agent, ensuring that every action is validated against a set of dynamic policies.
Governed Execution Flow
Governed execution requires a predictable interceptor pattern. We model the execution lifecycle as a series of gates: Pre-execution policy checking, execution monitoring, and post-execution audit logging. By using this structure, we ensure that no agent action can bypass the governance layer.
interface AgentGovernor {
validateRequest(context: AgentContext): Promise<ValidationResult>;
validateToolCall(tool: ToolCall): Promise<ValidationResult>;
logAction(action: ExecutedAction): void;
}
class GovernedAgent {
constructor(private core: AgentCore, private governor: AgentGovernor) {}
async execute(input: string) {
const validation = await this.governor.validateRequest({ input });
if (!validation.allowed) throw new Error('Policy violation');
return this.core.process(input);
}
}
Policy Enforcement as Middleware
The governance layer is implemented as a set of composable policy engines. Because the architecture is hexagonal, we can swap out the policy engine implementation (e.g., from a static regex-based check to a semantic-based classification model) without changing the agent’s core code. This modularity is essential for scaling across different compliance environments.
Trade-offs and Limitations
While this approach provides robust control, it introduces latency. Every gate incurs a performance tax. In high-frequency agent environments, the overhead of serializing context for governance checks can be significant. We mitigate this by using asynchronous validation where possible, though this introduces a potential race condition that must be handled by the state management layer.
- Increased latency due to middleware interception
- Complexity in maintaining consistent state across distributed governance nodes
- Overhead of defining and maintaining strict interfaces for all tool calls
Practical Implementation Lessons
During the development of this layer, we learned that governance is most effective when it is declarative. Instead of hard-coding rules in TypeScript or Python, we moved towards a schema-based definition where policies are defined in YAML or JSON and injected at runtime. This allows security teams to manage policies independently of the engineering team.
Governance should not be a bottleneck for development; it should be an infrastructure concern that provides guardrails without impeding the agent’s capability.
Conclusion
By open-sourcing our governance layer, we hope to move the industry toward a standardized way of handling agent safety. Hexagonal architecture provides the necessary decoupling to treat governance as a first-class citizen in agent development. As we continue to refine the platform, our focus will shift toward formal verification of these policy engines to provide mathematical guarantees of agent behavior.