Skip to main content

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
string
Optional description of what the method does
boolean
default:"false"
Whether the method supports streaming responses

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
Returns: 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: