Engineering · AI Agent Architecture
Tool Sandboxes, Schema Validation, and Safe Failures
Structured outputs, pre-call validation, sandbox limits, and semantic errors that reduce misuse and privilege bugs.
1. Schemas and constrained decoding
Describe tools with JSON Schema; validate or constrain-decode model output. Document enums, ranges, and mutually exclusive fields with counter-examples so calls look right and are legal.
2. Sandbox and egress
Run code, shell, and SQL tools inside cgroups/containers with CPU, memory, and wall-clock caps. Default-deny egress; allowlist by tool. Mount only ephemeral filesystems destroyed after the job.
3. Error wrapping and degradation
Normalize RETRYABLE, AUTH, VALIDATION, and FATAL. The agent retries, switches tools, or asks the user. Never leak internal paths into user-visible copy.
4. Engineering checklist
- Bind high-risk tools to one-time confirmation tokens
- Log tool_name, latency, and bytes for cost and abuse review
- Rotate credentials; never hard-code secrets in prompts
5. Sample configuration
tool_gateway:
schema_validation: strict
sandbox: { cpu: 1, memory_mb: 512, timeout_s: 30 }
egress: deny_all6. FAQ
- What if the model invents a tool name?
- Gateway-reject unknown names, return the allow-list, and reinforce it in the system prompt.