Agent class includes a powerful RPC (Remote Procedure Call) system that allows you to expose methods as callable Actions. This brings a structured, ergonomic, and type-safe approach to agent communication, moving beyond simple message passing.
What is an Action?
An Action is a Python method on yourAgent subclass that is decorated with @action. This decorator registers the method with the agent’s RPC system, making it callable by external clients (HTTP, WebSocket) and other agents.
How to Call Actions
Actions can be called through multiple transports, making them highly versatile.1. Via REST API (HTTP)
AgentServer and AgentRouter automatically create a REST endpoint for each action.
- URL:
POST /agent/{agent_id}/action/{action_name} - Body: JSON payload with action parameters.
2. Via WebSocket
For stateful clients, actions can be called over an existing WebSocket connection.action_result event with the same call_id upon completion.
3. Agent-to-Agent (Location Transparent RPC)
Useself.call() to get a type-safe proxy for communicating with another agent, regardless of whether it’s running locally or on a remote server.
Local Example:
support-agent-1 is deployed as a serverless function. With the Agent Registry, your ManagerAgent code does not change.
self.call("support-agent-1") inside ManagerAgent is automatically routed over HTTP, but your business logic remains clean and unaware of the network. This is Location Transparency.
Multi-User Metadata (Connection State)
A key feature of the RPC system is its awareness of the caller. You can store metadata on a per-connection basis without polluting the agent’s main state.How it Works
on_connect: When a client connects, you can store information inconnection.state.self.context: When an action is executed,self.context.connectionprovides access to the state of the specific client who made the call.
Example: A Multi-User Chat Room
who_am_i action, they will each get their own user_id back, because the agent can distinguish between them using self.context.