Developer Docs
architecture · spec · sdk
Handlers & Bridges6 min read
Writing a Custom Protocol Bridge
Step-by-step guide to adding a new protocol handler in under 50 lines of Python.
How to Write a Custom Protocol Bridge
#To create a bridge for a new protocol (e.g. LangGraph), follow this 3-step contract. No prior core team approval is needed.
Step 1: Subclass AgentHandler
#Create a new handler file in services/superagent/src/superagent/handlers/langgraph_handler.py:
python
from superagent.handlers.base import AgentHandler
import requests
class LangGraphHandler(AgentHandler):
"""Bridge for orchestrating LangGraph multi-agent workflows."""
def send_task(self, agent_manifest: dict, task_input: dict) -> str:
endpoint = agent_manifest.get("endpoint")
auth_token = self.get_vault_credential(agent_manifest["did"])
try:
response = requests.post(
f"{endpoint}/threads/runs",
json={"input": task_input},
headers={"Authorization": f"Bearer {auth_token}"},
timeout=30
)
response.raise_for_status()
return response.json().get("output", "")
except Exception as e:
# Prefix fatal errors with Error: for verifier detection
return f"Error: LangGraph execution failed - {str(e)}"Step 2: Register Protocol in Dispatch Pipeline
#Add your handler to middleware/pipeline.py:
python
if protocol == "LANGGRAPH":
handler = LangGraphHandler(vault=self.vault)
output = handler.send_task(manifest, step_input)Step 3: Add Registry Adapter
#Update emerge.yaml validation rules so protocol.type: LANGGRAPH passes schema checks.
Contribute Your Bridge
Open a Pull Request with the branch name feat/bridge-<protocol-slug> (e.g., feat/bridge-langgraph or feat/bridge-n8n). Templates are located in templates/your-first-bridge/.