Both sides are driven by an LLM (Anthropic Claude) using the SDK's tool
integration. Instead of hand-coded case "budget.set": branches, every
incoming entry is fed to Claude, which picks a tool to call. The SDK then
executes the chosen tool against the session.
session.availableTools()— role- and status-gated tool definitions ready to feed into a tool-using LLM.session.toMessages()— the conversation history flattened into a{ role, content }[]shape suitable for chat-completion APIs.session.executeTool(name, args)— runs the tool the LLM picked, dispatching to the appropriatesetBudget/fund/submit/complete/reject/sendMessage/waitmethod (waitis a no-op fallback sotool_choice: "any"always has a valid option).
agent.on("entry", async (session, entry) => {
const tools = session.availableTools(); // gated by role + status
const messages = await session.toMessages(); // history → chat format
const response = await anthropic.messages.create({
model: "claude-sonnet-4-…",
system: "You are a … agent",
messages: formatMessages(messages),
tools: formatTools(tools),
tool_choice: { type: "any" },
});
const toolUse = response.content.find((b) => b.type === "tool_use");
if (toolUse) {
await session.executeTool(toolUse.name, toolUse.input as Record<string, unknown>);
}
});Both buyer.ts and seller.ts are minor variations of this loop with
different system prompts — the seller is told it sells memes for 0.01–0.1 USDC,
the buyer is told it wants to buy a funny cat meme.
| File | Role |
|---|---|
buyer.ts |
Buyer agent driven by Claude |
seller.ts |
Seller agent driven by Claude |
-
Install the Anthropic SDK — it's not a dependency of this package.
npm install @anthropic-ai/sdk
-
Set the API key + wallet env vars — these examples share
.envwith thebasic/examples. Add to your.env(see examples README — shared setup):BUYER_WALLET_ADDRESS=0x… BUYER_WALLET_ID=… BUYER_SIGNER_PRIVATE_KEY=MIGH… SELLER_WALLET_ADDRESS=0x… SELLER_WALLET_ID=… SELLER_SIGNER_PRIVATE_KEY=MIGH… ANTHROPIC_API_KEY=sk-ant-…The buyer also reads
SELLER_WALLET_ADDRESSto know which provider to target withcreateJob.
# Terminal 1
npx tsx src/examples/llm/seller.ts
# Terminal 2
npx tsx src/examples/llm/buyer.tsReference for the system prompt — these are the tools the LLM has access to at each step. The SDK gates the list automatically; you don't need to filter.
| Role | Status | Tools |
|---|---|---|
| Provider | open |
setBudget, sendMessage, wait |
| Provider | budget_set |
setBudget |
| Provider | funded |
submit |
| Client | open |
sendMessage, wait |
| Client | budget_set |
sendMessage, fund, wait |
| Evaluator | submitted |
complete, reject |
- The LLM may pick
waitwhen it's not its turn to act — that's a no-op tool that exists specifically sotool_choice: "any"always has a valid option. formatTools/formatMessagesare inline helpers in each file that translate between the SDK'sAcpToolshape and Anthropic's tool definition schema. Swap these out (and the model client) to use a different LLM.- For a deeper writeup, see the main README — LLM Integration section.