Protocol Design for Direct Agent-to-Automation Runtime Connections

    This article explains when agents can connect directly to browser, desktop, and task runtimes, why agent traffic needs a dedicated protocol, and how identity, schemas, capabilities, streaming, errors, and idempotency should be specified before choosing in-process, sidecar, or gateway deployment.

    1. Direct connection is possible—but it is not “just a wire”

    Connecting a general-purpose agent to browser automation, desktop automation, a task executor, or internal toolchains often looks simple: the agent emits actions, the runtime executes them, and results return to the model. That works for prototypes and can be wired up in a day. Once you have multiple users, long workflows, sensitive data, retries, and audit, the question is no longer “can we call it,” but “who does this call represent, under what permission, is the response shape stable, and can we retry safely.”

    Direct connection therefore does not mean skipping the middle layer. It means moving that layer’s responsibilities into the protocol. A clean split is:

    1. Agent orchestration
    2. ↓ task intent, context, output constraints
    3. Protocol adaptation
    4. ↓ identity, capabilities, schema, stream frames, error semantics
    5. Execution runtime
    6. ↓ browser / desktop / commands / internal APIs
    7. External systems and data sources

    In a controlled single-machine setup, the adapter can be an in-process library. In multi-tenant or high-privilege environments, a sidecar or unified gateway is a better fit. Whether direct connection is appropriate depends on the risk boundary, not on whether you saved a layer of code.

    2. Why agent traffic deserves its own protocol

    Typical resource-oriented HTTP APIs assume a stable program calling another program, with field meaning, auth, and errors left to each team. Agent calls add extra variables: the caller may be model-driven, the action space can change, outputs enter the context window, long tasks need streaming, and actions can have real side effects. Reusing APIs designed for humans often hits four problems.

    2.1 Repeating schemas on every response inflates context cost

    When a model hits a typical paginated API, each row and page repeats field names:

    1. {
    2. "items": [
    3. {"id": "p-1", "name": "示例商品", "price": 10, "category": "demo"},
    4. {"id": "p-2", "name": "示例商品二", "price": 12, "category": "demo"}
    5. ]
    6. }

    After the first response, the model already knows id, name, price, and category, yet later rows still carry the same names. On metadata-heavy, deeply nested, or heavily paginated APIs, that repetition costs a non-trivial share of context; the exact ratio depends on payload shape and should not be reduced to one number. Repeated names also dilute attention on the values that matter.

    The fix is not merely compressing JSON. The protocol should treat schema as known:

    • First interaction returns the full schema plus a stable schema id or digest.
    • Later responses return the schema id and values ordered by field number.
    • The caller declares cached schemas so the runtime can omit the schema.
    • Schema changes must version explicitly so the model does not parse new data with old semantics.
    • Pagination should use continuation cursors and stable sort to cut duplicate work and transfer.

    A request might look like:

    1. {
    2. "protocol": "agent-runtime/1",
    3. "session": {
    4. "id": "s-01",
    5. "subject": "user-42",
    6. "scopes": ["task:read", "task:write"],
    7. "delegation": "signed-chain-ref"
    8. },
    9. "request": {
    10. "id": "r-1001",
    11. "capability": "page.navigate",
    12. "input": {"url_ref": "artifact-7"},
    13. "output_schema_ref": "schema:page.v3",
    14. "known_schemas": ["schema:page.v3"]
    15. },
    16. "options": {
    17. "stream": true,
    18. "idempotency_key": "k-9f2c"
    19. }
    20. }

    If the runtime confirms the caller already has the schema, it can return only the schema reference and row data. Omitting field names is a tactic, not a substitute for debuggability. Production systems still need a schema registry, version history, and sampled replay; otherwise a field-order or type change costs more to debug than the tokens saved.

    2.2 Agent identity has no natural home

    Classic auth answers “which user” or “which service.” Agent calls also need: who issued this agent, which user or system it represents, which scopes it holds, whether the delegation chain is complete, whether credentials were revoked, and whether the runtime may return results to that agent.

    Putting long-lived secrets in the model context so the model attaches them to requests is the most dangerous pattern. Use short-lived, verifiable, revocable credentials and enforce checks at the runtime:

    • Credentials should include issuer, subject, actor, audience, scopes, expiry, and a delegation-chain reference.
    • Authorize at action granularity, not merely “logged in.”
    • High-side-effect actions need step-up confirmation or human-approval tokens.
    • Downstream access should use controlled token exchange for temporary rights; do not expose long-lived keys to the model.
    • Log every action with session, subject, actor, capability name, and outcome for audit and accountability.

    A signed token in a header is not enough. The protocol must define where tokens live, how the delegation chain is passed, how revocation takes effect, and how errors are expressed—or every team will reinvent incompatible conventions.

    2.3 Capability discovery and version negotiation are missing

    To act, the agent must know what the runtime can do. If the capability list lives only in the prompt, the model will call missing actions or old parameters on a new version. The runtime should expose a machine-readable catalog: capability name, input/output schemas, idempotency, side effects, suggested timeouts, and required permissions.

    Version negotiation belongs in the protocol:

    • Catalogs use semantic versions; breaking changes bump the major version.
    • Callers declare supported protocol and schema versions.
    • Unsupported versions get explicit errors, not silent downgrades.
    • Compatibility tests cover old callers so a runtime upgrade does not break agents in bulk.

    2.4 Streaming, error semantics, and idempotency are incomplete for long tasks

    Agent work is often a long flow: open a page, wait, extract, submit, poll. A protocol with only success and failure cannot tell the caller whether to retry, wait, cancel, or ask a human.

    Put stream frames and error classes in the protocol:

    1. {"type":"task.started","task_id":"t-1","seq":1}
    2. {"type":"task.progress","task_id":"t-1","seq":2,"phase":"loading","percent":40}
    3. {"type":"task.partial","task_id":"t-1","seq":3,"delta_ref":"d-7"}
    4. {"type":"task.completed","task_id":"t-1","seq":4,"result_ref":"r-9"}

    Errors should at least distinguish invalid input, permission denied, resource conflict, temporary unavailability, runtime internal error, and user confirmation required. Side-effecting actions need idempotency keys, a dedupe window, and replay protection. Long tasks need cancel, timeout, resume, and backpressure. Otherwise a network blip becomes a duplicate order, submit, or notification.

    Prototypes can use in-process direct load of the runtime library: single user, low privilege, easy rollback. In production, introduce at least a thin protocol adapter:

    1. Agent orchestration
    2. ↓
    3. Protocol adapter (identity, schema, capabilities, stream frames)
    4. ↓
    5. Policy checks (permissions, approval, sandbox, quotas)
    6. ↓
    7. Execution runtime (browser / desktop / commands / internal APIs)
    8. ↓
    9. Audit logs, schema registry, monitoring and alerts

    If you deploy on Baidu AI Cloud, you can combine object storage, message queues, logging, and monitoring for artifact archival, async work, audit records, and metrics. The protocol itself should not bind to a specific cloud API, or you lose portability across environments.

    4. Engineering notes for rollout

    First, define the contract before the transport. Identity fields, capability catalogs, schema refs, error classes, and idempotency matter more than the encoding.

    Second, treat the schema registry as infrastructure. Identifiers should be stable and traceable; changes need compatibility checks. Cache hot schemas, but handle invalidation and version mismatch.

    Third, enforce permissions in the runtime, not the prompt. Models can be steered; policy cannot rely on the model “behaving.” High-side-effect actions need sandboxing, quotas, approval, and audit.

    Fourth, observability should include agent semantics: session id, subject, actor, capability name, schema-cache hits, context token use, retries, and human interventions—not only latency and error rate.

    Fifth, do not over-compress to save tokens. Field numbers and schema refs reduce cost, but readability, debugging, and backward compatibility still matter. Keep full schemas on debug traffic and enable compact encoding on stable production traffic.

    5. Conclusion

    Direct agent-to-automation runtime integration is viable in controlled environments and can remove unnecessary middle layers. Direct does not mean protocol-free. Multi-user systems, high-privilege actions, long flows, and real side effects require explicit design of identity, schemas, capabilities, streaming, errors, and idempotency. Establish a small but complete protocol contract first, then choose in-process, sidecar, or gateway based on risk. That usually lasts longer than stuffing everything into prompts and ad-hoc glue.