website/src/content/docs/agent-os/agent-to-agent.mdx
Agents communicate through host tools. You define a toolkit that lets one agent send work to another, and the agent calls it like any other CLI command.
This example creates a writer agent with a review tool. When the writer calls the tool, it reads the file from the writer's VM, writes it to a separate reviewer VM, and sends a review prompt.
// Tool that bridges the writer to the reviewer const reviewToolkit = toolKit({ name: "review", description: "Send code to the reviewer agent", tools: { submit: hostTool({ description: "Submit a file for code review", inputSchema: z.object({ path: z.string().describe("Path to the file to review"), }), execute: async (input) => { const client = createClient<typeof registry>("http://localhost:6420"); const writerHandle = client.writer.getOrCreate(["my-project"]); const reviewerHandle = client.reviewer.getOrCreate(["my-project"]);
// Read file from writer, write to reviewer
const content = await writerHandle.readFile(input.path);
await reviewerHandle.writeFile(input.path, content);
// Ask the reviewer to review
const session = await reviewerHandle.createSession("pi", {
env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },
});
const response = await reviewerHandle.sendPrompt(
session.sessionId,
`Review the code at ${input.path} and list any issues.`,
);
await reviewerHandle.closeSession(session.sessionId);
return { review: response };
},
}),
}, });
// Writer has the review toolkit, reviewer is plain const writer = agentOs({ options: { software: [common, pi], toolKits: [reviewToolkit] }, }); const reviewer = agentOs({ options: { software: [common, pi] }, });
export const registry = setup({ use: { writer, reviewer } }); registry.start();
```ts @nocheck client.ts
import { createClient } from "rivetkit/client";
import type { registry } from "./server";
const client = createClient<typeof registry>("http://localhost:6420");
const writerAgent = client.writer.getOrCreate(["my-project"]);
const session = await writerAgent.createSession("pi", {
env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },
});
// The writer will call `agentos-review submit --path /home/user/api.ts`
// when it's ready for a review
await writerAgent.sendPrompt(
session.sessionId,
"Write a REST API at /home/user/api.ts, then submit it for review.",
);
The writer agent sees the review tool as a CLI command:
agentos-review submit --path /home/user/api.ts
When the writer calls this, the host tool reads the file from the writer's VM, writes it to the reviewer's VM, and sends a prompt to the reviewer. The review result is returned to the writer as JSON.
Host tools are the natural communication layer between agents because: