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.

OpenAI Agents SDK

OpenAI Agents SDK · OpenAI Agents SDK WhatsApp · OpenAI agent Telegram · OpenAI Agents SDK iMessage · connect OpenAI agent to WhatsApp · ChatGPT agent WhatsApp API

Receive messages and send an OpenAI Agents SDK run back as chat bubbles.

Run your OpenAI Agents SDK agent for each incoming message and pass its stream to Flow’s reply(). The messaging integration is the same on each connected channel.

// npm install @flow-engineer/messaging @openai/agents
import { Agent, run } from "@openai/agents";
import { FlowMessaging, contentText } from "@flow-engineer/messaging";
const flow = new FlowMessaging();
const agent = new Agent({
name: "Bakery assistant",
instructions: "You help customers of Asha's Bakery with orders and delivery. Keep answers short.",
model: "gpt-4.1-mini",
});
for await (const event of flow.events.stream({ types: ["message.received"] })) {
const result = await run(agent, contentText(event.data.message.content), { stream: true });
await event.conversation.reply(result); // reads result.toTextStream()
}
  • In TypeScript, run(agent, input, { stream: true }) returns a streamed result; reply() reads its text stream and sends bubbles while the agent runs.
  • In Python, answer the webhook with {} at once and send the agent’s final_output afterwards. Text longer than the channel’s limit (4096 characters on Telegram) is refused, so split long answers at paragraph breaks (the bubble rule) and send each part with its own Idempotency-Key.
  • Give the agent the conversation’s history from GET /v0/conversations/{conversation_id}/messages, or keep your own session keyed by conversation.id.
  • Verify webhook signatures as shown in Events and webhooks.
  • 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/openai-agents on GitHub.