AI Agent Deployment: Hallucination Evaluation and Sandbox Permissions

    Deploying AI agents requires more than strong benchmark scores. This article explains how to evaluate end-to-end task completion, define and detect hallucinations, assess token-based costs, and enforce sandbox permissions. It also covers tool governance and a modular cloud architecture for building agents without tying the system to a single model service.

    Recent industry developments have arrived in rapid succession: new models becoming production-ready, vendors reporting their lowest internal hallucination rates, tiered pricing per million tokens, and agent-based personal assistants expanding into additional regions. Other developments highlight operational risks and opportunities: internal discussions at a social platform reportedly exposed agents accessing private messages and account information beyond their authorization; a coding tool published a detailed sandbox permissions design; and a music-generation service opened its tool integration protocol to all users.

    Taken together, these developments point to four engineering priorities—not simply which vendor has released another model: task completion evaluation, hallucination measurement and mitigation, cost structure, and the boundaries of agent permissions and privacy.

    1. From Benchmark Scores to End-to-End Task Completion

    Traditional evaluations often rely on multiple-choice benchmarks that measure accuracy in a single question-and-answer exchange. Real business workflows demand something different: given an ambiguous goal, an agent must break it down, call tools, execute steps, verify results, and deliver a usable artifact.

    Evaluating this end-to-end capability requires a different approach:

    • Verifiable deliverables: Does the code pass its tests? Can the report be checked? Can the data results be reproduced?
    • Observable execution: Intermediate steps, tool-call sequences, and retry counts must be recorded.
    • Attributable costs: Measure total token consumption and elapsed time for the entire task, rather than a single response.

    To assess production suitability, build a small evaluation set of 30–100 real business tasks. Track four metrics: first-pass success rate, human rework rate, average token consumption, and end-to-end latency.

    The following illustrates a basic evaluation framework:

    1. def evaluate(model, tasks):
    2. rows = []
    3. for t in tasks:
    4. r = model.run(t.prompt, tools=t.tools, budget=t.budget)
    5. rows.append({
    6. "task_id": t.id,
    7. "passed": t.verifier(r.output), # Executable validation, not subjective scoring
    8. "tokens": r.usage.total_tokens,
    9. "latency_ms": r.latency_ms,
    10. "retries": r.retries,
    11. })
    12. return summarize(rows) # Pass rate / P50-P95 latency / Cost per task

    The essential requirement is an executable verifier. Without automated validation, evaluation results risk becoming subjective impressions rather than reliable engineering evidence.

    2. Hallucination Rates Need Clear Definitions

    When a vendor claims the lowest hallucination rate in internal testing, ask three questions: What task distribution was used? How was a hallucination identified? Were refusals distinguished from fabricated answers?

    A useful engineering classification separates hallucinations into three categories:

    1. Factual hallucinations: Statements that conflict with verifiable facts.
    2. Citation hallucinations: References to nonexistent sources, interfaces, or fields.
    3. Process hallucinations: Claims that a step was completed when it was not actually executed.

    Mitigation should be layered. Retrieval-augmented generation anchors answers to citable source passages. Structured outputs constrain fields and enumerated values. Feeding tool results back into the model grounds its responses in actual return values. A final validation layer can use rules, a model, or both.

    The following is an illustrative constraint configuration, not a provider-specific API contract:

    1. {
    2. "response_format": "json_schema",
    3. "schema": {"required": ["answer", "citations", "tool_calls"]},
    4. "citations_min": 1,
    5. "allow_free_text": false
    6. }

    The engineering objective is not to promise “zero hallucinations.” It is to make hallucinations detectable before they cause downstream damage. Outputs that cannot be validated should not enter production workflows directly.

    3. How Tiered Token Pricing Shapes Architecture

    Common pricing structures charge separately for input and output tokens, typically per million tokens. They may also include long-context tiers and asynchronous batch options. Batch processing is often substantially cheaper, with more relaxed latency expectations.

    These pricing structures influence architecture choices:

    • Route frequent, short requests to smaller models or lightweight tiers, and long-document analysis to long-context tiers.
    • Use asynchronous batch processing for delay-tolerant offline work, such as log classification and bulk summarization.
    • Reduce input tokens through prompt compression, retrieval-passage trimming, and conversation-history summarization.
    • Use prefix caching and semantic caching to reduce repeated charges.

    A practical estimate is:

    Average cost per task ≈ (total input tokens × input price per token + total output tokens × output price per token) / number of tasks

    When prices are quoted per million tokens, convert them to per-token rates before applying the formula.

    Evaluate cost alongside first-pass success rate. A cheaper model that needs multiple retries may not produce a cheaper completed task.

    4. Sandboxes and Permissions Are a Deployment Prerequisite

    A coding tool’s published sandbox design and reported agent failures at a social platform illustrate two sides of the same issue. The latter reportedly included unauthorized access to encrypted private messages, confusion between user conversations, and unintended subscriptions to expensive paid services.

    The lesson is straightforward: as agent capabilities grow, permission design becomes a foundational requirement.

    Apply least privilege across the following areas:

    • Filesystem: Mount files read-only by default and restrict writes to allowlisted working directories.
    • Network: Deny outbound access by default, explicitly allowing only approved domains and ports.
    • Credentials: Inject short-lived tokens and keep them out of prompts and logs.
    • Actions with side effects: Require explicit confirmation or approval workflows for payments, deletion, and external communications.
    • End-to-end auditing: Make tool-call inputs, outputs, and decision rationale traceable.

    An illustrative sandbox policy:

    1. sandbox:
    2. fs: {read: ["/data"], write: ["/work"]}
    3. net: {default: deny, allow: ["api.internal:443"]}
    4. secrets: {mode: short_lived_token, log: false}
    5. approvals: [payment, delete, external_send]

    5. Tool Integration and Ecosystem Governance

    Opening tool integration protocols to all users allows agents to invoke external capabilities across host applications. For enterprise deployments, three controls are essential:

    • A tool inventory with an assigned owner for each tool.
    • Schema validation for tool inputs and outputs.
    • Quotas and circuit breakers.

    Without these controls, an expanding tool ecosystem can become an expanding attack surface rather than simply a broader set of capabilities.

    6. Practical Deployment Guidance

    To build similar capabilities in your own environment, start with a modular combination of standard cloud services:

    • A container platform to host sandbox runtimes.
    • Object storage to retain deliverables.
    • Message queues to decouple asynchronous tasks.
    • Logging, monitoring, and alerting services for auditing and cost visibility.

    Baidu AI Cloud has corresponding product categories for these general infrastructure needs. The architectural principle is to assemble these layers independently rather than bind the entire system to a single model service.

    Model releases will continue to accelerate, but engineering reliability comes from executable evaluations, detectable hallucinations, attributable costs, and enforceable permissions. With these four foundations in place, changing models can become a configuration change rather than an architectural rewrite.