Overview
The@callable decorator marks Agent methods as remotely callable from WebSocket clients. Clients can invoke these methods via RPC and receive typed responses.
Usage
Basic Callable Method
With Description
Streaming Methods
Mark methods as streaming to send multiple responses:Decorator Options
CallableMetadata
Calling from Clients
React (useAgent)
AgentClient
Streaming Responses
Server Side
Client Side
React Streaming
StreamingResponse API
send()
Send a chunk of data to the client.unknown
required
The data to send
boolean - false if stream is already closed (no-op), true if sent
end()
End the stream and send a final value.unknown
Final value to send before closing
error()
Send an error and close the stream.string
required
Error message
isClosed
Check if the stream has been closed.Type Safety
Callable methods are type-safe when using TypeScript:Error Handling
Server Side
Throw errors in callable methods to send error responses:Client Side
Handle errors in the promise rejection:Timeout
Set a timeout for RPC calls:Security
Method Visibility
Only methods marked with@callable() can be invoked from clients. Private methods are not accessible:
Validation
Validate arguments in callable methods:Authentication
Use connection state for authentication:Best Practices
Keep Methods Small
Use Descriptive Names
Return Serializable Data
Only return JSON-serializable data:Related
- Agent Class - Agent base class
- useAgent Hook - React hook for RPC
- AgentClient - Client-side RPC