Documentation menu
Documentation

Callable methods

Expose a deliberately small typed RPC surface to browser and mobile clients.

Start from a fresh project

This guide is self-contained. Create an empty Ayjnt project, then replace the starter agent with the files shown below. Run commands from the new project directory unless a step says otherwise.

terminal
bunx ayjnt new try-callable-methods --empty
cd try-callable-methods
bun install

# remove agents/alive once you are ready to add the guide's files

Use @callable for external clients

Decorate methods that a browser should call through agent.stub. Arguments and return values must be serializable. Plain public methods remain available to internal Durable Object RPC without becoming browser-callable.

example
import { Agent, callable } from "ayjnt";

export default class ReviewAgent extends Agent {
  @callable({ description: "Submit a document for review." })
  async submit(documentId: string): Promise<{ accepted: true }> {
    await this.queue("review", { documentId });
    return { accepted: true };
  }

  // Internal RPC only: no decorator.
  async review(payload: { documentId: string }) {
    // ...
  }
}

Streaming and failures

Use @callable({ streaming: true }) with StreamingResponse for incremental results. Throwing rejects the client call; prefer stable, structured error shapes for failures a UI is expected to handle.

Callable RPC travels over the Agent WebSocket protocol. Agent-to-agent calls use Durable Object RPC instead, which is more direct and does not require the decorator.

Run it and verify the result

Open the co-located browser UI and call the decorated method through agent.stub. TypeScript should autocomplete its arguments and return type.

terminal
bun run build
bun run dev

# the local app is now available at http://localhost:8787