Documentation menu
Documentation

Inter-agent communication

Call a separately bound agent by durable name with typed RPC.

Use this.agent inside Ayjnt Agent

The protected this.agent() helper is Ayjnt’s typed wrapper around Cloudflare getAgentByName(). The target has its own top-level Durable Object namespace and storage.

agents/orders/agent.ts
import { Agent } from "ayjnt";
import InventoryAgent from "../inventory/agent";

export default class OrdersAgent extends Agent {
  async reserve(sku: string, quantity: number) {
    const inventory = await this.agent(InventoryAgent, "primary");
    return inventory.reserve(sku, quantity);
  }
}

Outside an Agent

Import getAgent<T>() from ayjnt when calling from a Worker handler or other framework code. Browser code should use callable methods instead of a Durable Object binding.

Internal agent RPC does not need @callable(). Public methods are callable through the typed Durable Object stub.