Skip to content

Ask the docs

Answers come only from these docs and are written by an AI model (Gemini), so check the linked pages. Your question is not kept. Do not include personal details or keys.

Claude Agent SDK

Claude Agent SDK · Claude Agent SDK WhatsApp · Claude agent Telegram bot · Claude iMessage agent · Anthropic agent WhatsApp API · connect Claude to WhatsApp

Run a Claude agent for each message and deliver its streamed answer.

Run a Claude agent for each incoming message and deliver its answer as chat bubbles. Your agent keeps its tools; Flow handles the channel connection.

// npm install @flow-engineer/messaging @anthropic-ai/claude-agent-sdk
import { query } from "@anthropic-ai/claude-agent-sdk";
import { FlowMessaging, contentText } from "@flow-engineer/messaging";
const flow = new FlowMessaging();
for await (const event of flow.events.stream({ types: ["message.received"] })) {
const run = query({
prompt: contentText(event.data.message.content),
options: {
systemPrompt: "You are the assistant for Asha's Bakery. Answer customers in short messages.",
tools: [], // no built-in tools (Bash, file access); list the ones your agent may use
includePartialMessages: true, // stream text as it is written
},
});
await event.conversation.reply(run); // sends the agent's text, skips tool and system messages
}
  • reply() reads the query() iterator: with includePartialMessages it sends text as it streams, otherwise each assistant message’s text. Tool calls, results and system messages are not sent to the person.
  • Each assistant turn becomes its own bubble, which reads naturally in chat (“Let me check that…” then the answer).
  • tools: [] turns off Claude Code’s built-in tools, which a customer-facing agent should not have by default; allowedTools only pre-approves tools and does not restrict them.
  • Keep one Claude session per Flow conversation (conversation.id) to carry context between messages: remember each run’s session_id and pass it as resume next time (the full example does this).
  • Your production agent talks to Flow through the SDK or HTTP. The hosted MCP server is a separate build-time tool for coding agents; whether a project adds it is the project owner’s decision.
  • To see each turn’s model and tool calls and get every reply graded, send this agent’s traces to Flow Observe: Traces from agent frameworks.

examples/claude-agent-sdk on GitHub.