Bidirectional Agent Collaboration: Protocol Adaptation and Registration/Discovery in Practice

    This article explains how to build bidirectional interoperability between AI agents, covering outbound invocation and inbound service exposure. It breaks down the core problems of communication compatibility, capability description, and dynamic discovery, then proposes a four-layer architecture with a registry, outbound and inbound adapters, and an orchestration layer. It also details capability description design, two-phase dynamic routing, task lifecycle and reliability, security governance, observability, and a phased rollout plan. Readers will learn how to design stable, governable contracts between internal capabilities and external agent services without letting the system degrade into hard-to-maintain point-to-point integrations.

    1. From Monolithic Applications to Multi-Agent Collaboration

    A single agent works well for tasks with clear boundaries and a limited set of tools. When a business involves information retrieval, data analysis, rule evaluation, and result generation at the same time, concentrating all of these capabilities in one agent tends to cause context bloat, excessive permissions, and maintenance difficulty.

    The core value of multi-agent collaboration is decomposing a complex task into execution units with clear responsibilities. For example, a retrieval agent finds information, an analysis agent performs structured computation, a business agent validates rules, and an orchestration layer coordinates execution and consolidates results.

    But “splitting into multiple agents” does not mean the system naturally gains collaboration ability. Different agents may use different communication methods, identity mechanisms, and task models. If every new agent requires separately written invocation code, agreed return formats, and custom routing rules, then the more agents you add, the higher the integration cost becomes.

    So what really needs to be built is not a collection of interfaces, but a collaboration infrastructure that covers discovery, invocation, execution, and governance.

    2. What Bidirectional Interoperability Must Solve

    Bidirectional interoperability contains two independent directions:

    • Outbound invocation: the application platform can discover and call external agents.
    • Inbound service: agents built within the platform can expose services externally under an agreed protocol.

    The two can share capability descriptions and security conventions, but they should not be conflated. Being able to call external agents does not mean the application can already be discovered and called by external systems.

    2.1 Communication Compatibility Is Not Task-Semantics Compatibility

    Even if both sides support network requests, they may understand “task” differently. One side treats a request as a question that returns immediately; the other treats it as an asynchronous job that runs continuously.

    Protocol adaptation typically needs to handle:

    • how inputs and outputs are expressed;
    • parsing of capability descriptions;
    • task identifiers and status correlation;
    • execution progress and result retrieval;
    • timeout, cancellation, and error feedback;
    • propagation of identity information and invocation context.

    If an adapter only converts fields but ignores the task lifecycle, problems easily arise: the caller times out while the server keeps running, or duplicate requests trigger duplicate operations.

    2.2 A Service Address Is Not Complete Capability Information

    An accessible address only tells you “where to call,” not “what task it is suited for.”

    Effective agent discovery also requires understanding the capability scope, input requirements, output form, protocol compatibility, and access conditions. Capability descriptions should be as structured as possible, rather than relying on a paragraph of natural-language introduction.

    2.3 Dynamic Discovery Is Not Arbitrary Invocation

    The presence of an agent in the registry does not mean the current user is authorized to use it, nor that it is suitable for the current task.

    Discovery results must still be filtered by permissions, health status, protocol version, and business constraints. The goal of dynamic selection is to reduce hardcoding, not to abandon deterministic control boundaries.

    A general implementation can be divided into four layers:

    1. Business applications and task orchestration layer
    2. │
    3. ├─ Outbound invocation adapter ── External agent services
    4. │
    5. └─ Inbound service adapter ── Internal application execution entry
    6. │
    7. Agent registration and discovery service
    8. │
    9. Identity authentication, audit, and monitoring system

    3.1 Registration and Discovery Service: Managing the Capability Catalog

    The registry maintains each agent’s identity, capability description, service location, version, and availability information. It mainly answers “what capabilities exist, where they are, and whether they are available.”

    Note that the registry usually belongs to the control plane and does not need to handle every business request. After discovery, the caller can access the target service directly, or go through a unified proxy according to security requirements.

    The capability catalog should not store plaintext keys. Access credentials should be provided by a separate credential management mechanism; the catalog only records the necessary authentication requirements or controlled references.

    3.2 Outbound Adapter: Connecting Business Orchestration to External Tasks

    The outbound adapter converts the application’s internal input into a request the target protocol can accept, then converts the response into a result the workflow can consume.

    It should also handle invocation timeouts, status queries, exception normalization, and context correlation. For long-running tasks, it must not simply treat “request accepted” as “task completed,” but should continue tracking execution status.

    3.3 Inbound Adapter: Wrapping Internal Applications as Controlled Services

    The inbound adapter handles authentication of external requests, input validation, and execution mapping, and converts internal results into the agreed response form.

    Before publishing externally, clarify whether the application supports asynchronous execution, cancellation, progress feedback, and multiple input types. Capabilities the internal application does not provide should not be claimed as supported in the external description.

    For ordinary workflows, it is better to first expose well-bounded single capabilities rather than opening up the entire internal orchestration system.

    3.4 Orchestration Layer: Retaining Business Decision Authority

    The protocol adaptation layer solves interoperability; the orchestration layer solves business flow. The two should remain separate.

    For example, “retrieve first, then analyze, and escalate to manual review if analysis fails” is an orchestration policy and should not be hardcoded into a general communication adapter. Otherwise, protocol upgrades and business changes will constrain each other.

    4. Designing Capability Descriptions for Production Use

    Capability descriptions serve both program filtering and developer understanding. At a minimum, they should cover:

    Category Information to express
    Identity Stable identifier, name, maintaining party
    Capability Tasks it can perform, applicable scope, explicit limitations
    Data Input types, required fields, output structure
    Communication Service location, protocol version, interaction mode
    Security Authentication requirements, permission scope, data-handling constraints
    Runtime Availability status, version, and lifecycle information

    These are general design dimensions, not a fixed field set of any particular protocol. In practice, follow the protocol you adopt and your internal conventions.

    Capability descriptions also need version management. If the output structure, authentication method, or task semantics change, mark the compatibility impact explicitly so callers do not keep using old logic without noticing the change.

    Health status should also be layered: network reachability does not mean dependencies are healthy, and healthy dependencies do not mean business results are valid. For critical agents, you can separately observe connectivity, execution success rate, and business validation results.

    5. Dynamic Routing: Constrain First, Then Match

    Agent selection can be split into two phases.

    Phase 1: Hard-Constraint Filtering

    First exclude candidates that do not meet requirements, for example:

    • the current identity has no access permission;
    • the protocol version is incompatible;
    • the input type is not supported;
    • the data-handling scope does not comply;
    • the service is unavailable or shutting down;
    • the task involves an operation the candidate agent explicitly forbids.

    These conditions should be enforced by deterministic rules as much as possible, not left to model judgment alone.

    Phase 2: Capability Matching and Ranking

    Within the qualified candidate set, rank by task fit, historical execution quality, response latency, and resource budget.

    A model can help understand natural-language tasks, but it should not break through the permission and data boundaries established in the previous phase. For high-risk operations, add manual confirmation or dedicated business approval.

    The following pseudocode only illustrates the processing order and does not represent an actual interface:

    1. candidates = queryCapabilityCatalog(taskType)
    2. qualified = filter(
    3. candidates,
    4. permission, version, inputType, dataConstraints, availability
    5. )
    6. if qualified is empty:
    7. return an explainable not-executable result
    8. target = selectByTaskFitAndRuntimeMetrics(qualified)
    9. result = submitTaskViaAdapter(target, input)
    10. validate result structure and business constraints

    When routing fails, clearly distinguish “no relevant capability,” “capability temporarily unavailable,” and “caller lacks permission.” These three cases require different handling and should not all be wrapped as an ordinary invocation failure.

    6. Task Lifecycle and Reliability Design

    Multi-agent collaboration often crosses multiple service boundaries, so you cannot assume every task completes within a single request.

    6.1 Establish a Clear Internal State Model

    The system can describe tasks with states such as waiting, running, succeeded, failed, and cancelled, but the specific state names and transition rules should map to the protocol you adopt.

    In particular, distinguish:

    • the request was submitted successfully;
    • the server has accepted the task;
    • the task is executing;
    • the final result has been produced;
    • the result has passed business validation.

    These phases are not equivalent. Only by distinguishing them clearly can the orchestration layer correctly decide whether to proceed to the next step.

    6.2 Propagate Deadlines and Cancellation Intent

    When an upstream task has a time budget, propagate the remaining budget downstream to avoid each stage independently waiting for a full timeout.

    If the caller cancels a task, notify downstream to stop execution as much as possible. But cancellation cannot always interrupt immediately, nor does it undo business side effects already produced. The system needs to record the actual cancellation result and keep tracking tasks that cannot be interrupted.

    6.3 Retries Must Account for Side Effects

    A network timeout only means the caller did not receive a result; it does not prove the server did not execute.

    Retrieval-type tasks are usually easy to retry; payment, approval, write, or notification tasks require idempotency control. The idempotency identifier should be tied to the specific business operation, with a clear validity period and rules for handling duplicate requests.

    Cross-service execution should generally not casually promise strict “execute exactly once.” A more realistic goal is to reduce the business impact of duplicate execution through deduplication, status queries, and compensation mechanisms.

    6.4 Control the Scale of the Collaboration Chain

    Agents calling one another can form loops. Set boundaries on maximum call depth, concurrency, and total execution budget, and record parent-child task relationships.

    When the budget is exhausted, the system should return an explainable termination reason rather than letting the task expand indefinitely.

    7. Security Governance: Do Not Trust Everything You Discover

    7.1 Authorize Registration, Discovery, and Invocation Separately

    Allowing a party to register an agent does not mean allowing it to modify other agents’ information; allowing a user to view the capability catalog does not mean allowing them to invoke every capability in it.

    Permissions should cover different operations such as catalog maintenance, capability viewing, task execution, and result reading, and should enforce tenant isolation and the principle of least privilege.

    7.2 Prevent Untrusted Service Addresses from Entering the Invocation Chain

    If registration information can influence the actual request target, a malicious address could lure the caller into accessing internal resources that should not be exposed.

    Therefore, validate the source of addresses, restrict the accessible scope, and control redirects and network egress. Capability discovery is not a reason to bypass network security boundaries.

    7.3 Treat External Results as Untrusted Input

    Text returned by an external agent may contain errors and may also carry instructions that induce additional operations.

    The orchestration layer should treat this content as data to be validated, not automatically elevate it to system instructions. When it involves tool calls, permission changes, or sending sensitive data, authorization and parameter validation must be performed again.

    7.4 Only Pass the Data Needed to Complete the Task

    Multi-agent collaboration should not share the full conversation history by default. Trim context according to the subtask, desensitize sensitive information where necessary, and control how long results are retained.

    Logs need protection too. Recording the call chain helps troubleshooting, but keys, full personal information, or sensitive business content should not be stored unconditionally.

    8. Observability, Validation, and Phased Rollout

    In production, you need to know not only “whether the call errored” but also “whether the task actually completed.”

    Recommended metrics to observe:

    • capability discovery latency and cache hit rate;
    • request success rate, task completion rate, and business validation pass rate;
    • duration of each execution phase and queue time;
    • number of timeouts, retries, cancellations, and duplicate requests;
    • anomaly distribution broken down by agent version;
    • routing selection reasons and permission-denial records.

    Each collaboration should carry a correlatable call-chain identifier so developers can trace from a top-level business task down to specific subtasks, while avoiding sensitive information in the identifier.

    Rollout can proceed in four steps:

    Step 1: Minimal closed loop. Pick a low-risk task with stable inputs and outputs, and separately validate outbound invocation and inbound service, confirming that capability descriptions, authentication, and result mapping are correct.

    Step 2: Introduce discovery. Migrate fixed addresses to controlled catalog discovery, and test cache invalidation, service shutdown, address changes, and version incompatibility.

    Step 3: Add dynamic selection. After hard constraints are clear, introduce candidate ranking, record the selection basis, and ensure the system can safely terminate or enter a preset fallback flow when no selection is possible.

    Step 4: Complete production governance. Validate asynchronous tasks, duplicate submissions, caller timeouts, cancellation propagation, dependency failures, and permission revocation. For new versions, validate on a small scale first, then gradually expand usage.

    Final acceptance should not just show one successful call chain, but prove that the system still behaves predictably under failures, changes, and restricted permissions.

    9. Summary

    The essence of bidirectional agent collaboration is establishing a stable, governable contract between internal application capabilities and external services.

    The registry makes capabilities discoverable, adapters make interactions compatible, the orchestration layer makes flows conform to business goals, and the security and observability systems make execution controllable and traceable.

    Only by incorporating capability descriptions, dynamic routing, task lifecycle, and permission governance into the design together can you prevent a multi-agent system from degrading into a large set of hard-to-maintain point-to-point interfaces, and build a reliable foundation for future expansion.