AgentBridge API Reference¶
AgentBridge is a production-grade autonomous agent gateway system designed to enable dynamic protocol adaptation and semantic message routing between heterogeneous AI agent architectures. It facilitates distributed state coordination and robust failure recovery.
Core Modules¶
openclaw_gateway.canonical_message¶
This module defines the standardized, canonical message format used across the entire AgentBridge system, ensuring interoperability between different agent protocols.
Key Classes/Functions:
CanonicalMessage(Class)- Signature:
CanonicalMessage(sender_id: str, recipient_id: str, message_type: str, payload: dict, metadata: dict = None) - Description: Represents the standardized message structure. It encapsulates all necessary information (sender, recipient, type, and content) in a format agnostic to the underlying agent implementation.
- Example Usage:
- Signature:
openclaw_gateway.errors¶
This module centralizes custom exceptions used throughout the gateway for standardized error handling, particularly during protocol translation and routing failures.
Key Classes/Functions:
GatewayError(Base Exception)- Signature:
class GatewayError(Exception): ... - Description: The base exception class for all AgentBridge operational errors.
- Example Usage:
- Signature:
ProtocolMismatchError(Exception)- Signature:
class ProtocolMismatchError(GatewayError): ... - Description: Raised when a message cannot be successfully translated between the source and target agent protocols.
- Example Usage:
- Signature:
openclaw_gateway.adapters.base¶
This module defines the abstract interface that all specific protocol adapters must implement. This enforces a contract for message translation and interaction with heterogeneous agent systems.
Key Classes/Functions:
BaseAdapter(Abstract Class)- Signature:
class BaseAdapter(ABC): ... - Description: Defines the required methods for any protocol adapter:
to_canonical,from_canonical, and potentiallysend_message. - Methods:
to_canonical(native_message: Any) -> CanonicalMessage: Converts a native agent message format into the system's canonical format.from_canonical(canonical_message: CanonicalMessage) -> Any: Converts a canonical message back into the format expected by the specific agent.
- Example Usage (Conceptual):
- Signature:
openclaw_gateway.adapters.langchain¶
This module provides the concrete implementation for interfacing with agents utilizing the LangChain framework. It handles the translation between LangChain-specific structures (e.g., ToolCall objects) and the canonical format.
Key Classes/Functions:
LangChainAdapter(Class)- Signature:
LangChainAdapter(config: dict) - Description: Implements
BaseAdapterspecifically for LangChain agents. It manages the mapping logic for LangChain's internal message structures. - Methods:
to_canonical(langchain_message: dict) -> CanonicalMessage: Converts a LangChain message structure intoCanonicalMessage.from_canonical(canonical_message: CanonicalMessage) -> dict: Converts aCanonicalMessageinto a format consumable by a LangChain agent.
- Example Usage:
- Signature:
openclaw_gateway.adapters (General)¶
This directory houses various specialized adapters (e.g., AutoGPTAdapter, VectorContextAdapter) that implement the BaseAdapter interface for different agent architectures.
Key Classes/Functions:
AutoGPTAdapter(Conceptual Class)- Signature:
AutoGPTAdapter(config: dict) - Description: Adapts messages between the AgentBridge canonical format and the specific command structures used by AutoGPT-like agents.
- Example Usage:
- Signature:
openclaw_gateway.MessageTranslationEngine (Conceptual/Core Logic)¶
This module is the heart of the semantic routing and protocol adaptation. It utilizes AST transformation and bidirectional schema mapping tables to ensure accurate message conversion.
Key Classes/Functions:
MessageTranslationEngine(Class)- Signature:
MessageTranslationEngine(schema_map: dict, ast_transformer: ASTTransformer) - Description: Manages the translation pipeline. It uses pre-defined bidirectional schema maps to guide AST transformations, converting complex, agent-specific message structures (like LangChain tool calls or vector context queries) into the canonical format and vice-versa.
- Methods:
translate_to_canonical(native_message: Any, source_adapter: BaseAdapter) -> CanonicalMessage: Performs the translation from any native format to the standard.translate_from_canonical(canonical_message: CanonicalMessage, target_adapter: BaseAdapter) -> Any: Performs the translation from the standard format to the target agent's native format.
- Example Usage:
from openclaw_gateway.MessageTranslationEngine import MessageTranslationEngine # Assume schema_map and transformer are initialized engine = MessageTranslationEngine(schema_map, transformer) # Translate a complex LangChain structure to canonical canonical_msg = engine.translate_to_canonical(lc_input, langchain_adapter) # Translate canonical back to AutoGPT format auto_gpt_msg = engine.translate_from_canonical(canonical_msg, auto_gpt_adapter)
- Signature:
openclaw_gateway.cli¶
This module provides the command-line interface for interacting with the gateway, useful for testing, debugging, and running simple routing tasks without a full service deployment.
Key Classes/Functions:
run_gateway_cli(Function)- Signature:
run_gateway_cli(args: list) - Description: Entry point for the command-line interface. Allows users to simulate message routing, check adapter compatibility, or run diagnostic tests.
- Example Usage:
- Signature:
System Overview Diagram (Conceptual Flow)¶
- Agent $\rightarrow$ Gateway: Agent sends native message $\rightarrow$ Adapter (
to_canonical) $\rightarrow$CanonicalMessage. - Gateway Core:
MessageTranslationEngineroutes theCanonicalMessagebased on routing rules. - Gateway $\rightarrow$ Agent:
CanonicalMessage$\rightarrow$MessageTranslationEngine(translate_from_canonical) $\rightarrow$ Adapter (from_canonical) $\rightarrow$ Native Message $\rightarrow$ Agent.