This directory contains a basic example of how to use ProtoLink to create a multi-agent system with HTTP transport. The example demonstrates:
- Registry: A central service for agent discovery and registration
- Weather Agent: An agent that provides weather data
- Alert Agent: An agent that processes weather data and sends alerts
registry.ipynb- Sets up the HTTP registry for agent discoveryweather_agent.ipynb- Creates a weather agent with mock weather dataalert_agent.ipynb- Creates an alert agent that communicates with the weather agent
┌─────────────────┐ HTTP REST API ┌─────────────────┐
│ Registry │◄──────────────────►│ Alert Agent │
│ (localhost: │ │ (localhost: │
│ 9010) │ │ 8020) │
└─────────────────┘ └─────────────────┘
▲ ▲
│ │
│ HTTP REST API │ HTTP REST API
│ │
┌─────────────────┐ ┌─────────────────┐
│ Weather Agent │◄──────────────────►│ Alert Agent │
│ (localhost: │ │ │
│ 8010) │ │ │
└─────────────────┘ └─────────────────┘
First, run the registry.ipynb notebook to start the registry service:
from protolink.discovery import Registry
REGISTRY_URL = "http://localhost:9010"
# Create and start registry (uses HTTP transport by default)
registry = Registry(transport="http", url=REGISTRY_URL)
await registry.start()The registry exposes these endpoints:
- GET
/agents- List all registered agents - POST
/agents- Register a new agent - DELETE
/agents/{agent_url}- Unregister an agent - GET
/status- View registry status and registered agents
Run the weather_agent.ipynb notebook:
from protolink.agents import Agent
from protolink.models import AgentCard, Task
URL = "http://localhost:8010"
REGISTRY_URL = "http://localhost:9010"
class WeatherAgent(Agent):
async def handle_task(self, task: Task):
result = await self.call_tool("get_weather", city="Geneva")
return task.complete(f"Weather data: {result}")
card = AgentCard(url=URL, name="WeatherAgent", description="Produces weather data")
# Using transport type strings - the agent will create HTTP transports internally
agent = WeatherAgent(card=card, transport="http", registry="http", registry_url=REGISTRY_URL)
@agent.tool(name="get_weather", description="Return weather data for a city")
async def get_weather(city: str):
return {"city": city, "temperature": 28, "condition": "sunny"}
await agent.start(register=True)Run the alert_agent.ipynb notebook:
from protolink.agents import Agent
from protolink.models import Message, Task
from protolink.transport import HTTPTransport
URL = "http://localhost:8020"
REGISTRY_URL = "http://localhost:9010"
class AlertAgent(Agent):
async def handle_task(self, task: Task):
data = task.payload
if data["temperature"] > 25:
await self.call_tool("alert_tool", message=f"Hot weather in {data['city']}! {data['temperature']}°C")
return task
# Using HTTPTransport instances directly (alternate approach)
transport = HTTPTransport(url=URL)
registry = HTTPTransport(url=REGISTRY_URL)
card = {"url": URL, "name": "AlertAgent", "description": "Sends alerts based on data"}
agent = AlertAgent(card=card, transport=transport, registry=registry)
@agent.tool(name="alert_tool", description="Send an alert")
async def send_alert(message: str):
print(f"ALERT: {message}")
return {"status": "sent", "message": message}
await agent.start(register=True)- Purpose: Central service for agent discovery and registration
- Transport: Accepts either a transport type string (
"http") or aTransportinstance - Endpoints: Provides agent management and status endpoints
- Transport: Can use transport type strings (
"http") orHTTPTransportinstances - Registration: Agents can pass registry as a string, transport instance, or transport type with separate URL
- Tools: Agents can define native tools using the
@tooldecorator - Task Handling: Agents implement
handle_taskto process incoming tasks
- Agent-to-Registry: HTTP REST API for registration and discovery
- Agent-to-Agent: HTTP client-server for task delegation and responses
- Tool Calling: Agents can call their own tools and receive results
Once all agents are running:
- Check Registry Status: Visit
http://localhost:9010/status - Check Agent Status:
- Weather Agent:
http://localhost:8010/status - Alert Agent:
http://localhost:8020/status
- Weather Agent:
- Send Tasks: Use the Alert Agent to send tasks to the Weather Agent and observe the alert system
- Registry: 9010
- Weather Agent: 8010
- Alert Agent: 8020
Make sure these ports are available before starting the system.