Agent communication
Agents work together by calling each other’s methods through typed clients. An agent can also wait for something outside Golem, such as a person’s approval or a webhook from a payment provider, and programs outside Golem can call agents directly. Golem delivers these calls reliably, so an application needs no message queue, job scheduler, or callback service between its agents.
Calling another agent
Every agent type has a generated client. A caller gets a client for a specific agent from its constructor arguments and calls its methods. If the target agent does not exist yet, Golem creates it.
A call can be made in three ways:
| Call | What the caller does |
|---|---|
| Await | Waits for the result |
| Trigger | Sends the call and continues without waiting |
| Schedule | Sends the call to run at a given time, and gets a token to cancel it |
TypeScript
// Excerpt: inside a method of ReportAgent
const reviewer = ReviewerAgent.client.get({ team: "finance" });
// Await the result
const review = await reviewer.review({ draft: this.draftText });
// Trigger without waiting
reviewer.review.trigger({ draft: this.draftText });
// Schedule for one hour from now, then cancel
const inOneHour = { seconds: BigInt(Math.floor(Date.now() / 1000) + 3600), nanoseconds: 0 };
const token = reviewer.review.schedule(inOneHour, { draft: this.draftText });
token.cancel();Agent-to-agent calls execute exactly once. Golem records each call in the caller’s oplog and attaches a key derived from it, so retries and recovery after a failure never make the target run the call twice. Scheduled calls are stored durably until they run or are cancelled. A recurring job is a method that schedules its own next run.
Each agent processes one call at a time. A call that arrives while the agent is busy waits in its queue, so a long-running method delays later calls to the same agent; read-only methods can be answered from a cache without waiting. Two agents that await each other at the same moment would wait forever, so use trigger for one direction in such cases.
Calling across languages
An agent can call agent types from other components, including components written in another language. You declare the dependency in golem.yaml, and golem build generates a typed client in the caller’s language from the target’s interface. A TypeScript agent can call a Rust agent with TypeScript types, and the call has the same guarantees as any other agent call.
Waiting for people and external events
A promise is a durable slot that an agent creates (createPromise) and waits on (awaitPromise). Another agent, or an external system through the REST API, completes it with a value; the Quickstart uses one for an approval. A webhook is a promise with a one-time URL: an HTTP POST to the URL completes the promise with the request body. Use a webhook when an external service, such as a payment provider, calls back over HTTP.
TypeScript
// Excerpt: ReportAgent waits for a manager's approval
const webhook = createWebhook();
await sendApprovalEmail(webhook.getUrl()); // your own function
const payload = await webhook; // the agent is suspended here
const decision = payload.json();While an agent is only waiting, Golem unloads it from memory, so a wait of minutes or months uses no compute. The wait is recorded in the oplog, so it survives server restarts and redeployments. When the promise completes, Golem loads the agent again and the await returns.
Open full-size image in a new tab.
Open full-size image in a new tab.Deadlines and reminders are ordinary code built from these pieces. For an approval with a deadline, the waiting agent can schedule a call that completes the same promise with a default answer; whichever completion comes first wins.
Streaming
Methods can accept and return streams of values or bytes, in both directions at once: for example, a client can stream audio into an agent while the agent streams text back, or an agent can stream model output token by token. The stream belongs to the agent, not to a network connection: if a client disconnects, the agent keeps running, and the client reconnects and continues from the last item it received. Generated client libraries and the CLI stream over a resumable WebSocket session; HTTP endpoints use the Durable Streams protocol, described in Artifacts.
Calling agents from outside Golem
Programs outside Golem can call agents through:
- Generated client libraries (also called bridges) in your application’s language, for example in a Next.js server or a Rust service.
- The REST API.
- HTTP endpoints and MCP servers that you define, described in Artifacts.
- The CLI, with
golem agent invoke.
Discovering agents and tools at runtime
An agent can list the agent types and tools available to it, read their method schemas, and call them without a generated client. AI agent loops use this to offer tools to a model. Golem still applies the caller’s permissions to every call.
Next
Artifacts: how agents serve APIs, web front-ends, files, and streams.
Related guides: