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.

Build

Choose a model and configure your messaging agent's runtime behavior.

Configure the model and createAgent options in src/agent.ts. The starter already connects the agent to its tools, test people and hosting environment.

openAICompatible works with OpenAI-compatible APIs. With no explicit apiKey or baseURL, it uses the first non-empty key in this order:

OrderEnvironment variableProvider
1OPENROUTER_API_KEYOpenRouter
2OPENAI_API_KEYOpenAI
3ANTHROPIC_API_KEYAnthropic
4GEMINI_API_KEYGemini
5FLOW_KEYFlow’s hosted models

With no key, it stops immediately and names the supported variables.

import { openAICompatible } from "@flow-engineer/flow";
const model = openAICompatible({ model: process.env.MODEL });

Use your local server’s address and model id in the second example. A server that needs a key can also receive apiKey explicitly.

MODEL sets the default model id. The starter passes CAFE_MODEL when set. Otherwise each provider has a default in src/model.ts. Set contextTokens to tell Flow the model’s context-window size.

Available in Framework 0.18.0.

const model = openAICompatible({
model: "anthropic/claude-haiku-5.5",
maxTokens: 4000, // sent as max_tokens
reasoning: "low", // "minimal", "low", "medium" or "high"
});
OptionWhat it does
maxTokensThe most tokens one reply may use, sent as max_tokens. Unset, providers such as OpenRouter take the model’s maximum and hold credit for it on every call
reasoningHow hard a reasoning model thinks before it answers, sent as OpenRouter’s reasoning: { effort }. Unset, the model’s default

Expected result: each model request carries max_tokens: 4000 and reasoning: { effort: "low" }. Leave reasoning unset for a model that does not reason.

flow setup writes FLOW_KEY, which can use the account’s $2 of trial model credit. A provider key takes priority over it. flow status reports the remaining credit without printing the key.

flowModel({ model }) explicitly selects Flow’s hosted models; its default is anthropic/claude-haiku-5.5. GET /models on the configured Flow model server lists the models it offers. Set FLOW_MODEL_URL to use another Flow model server. On Flow’s hosting, pass model: flowModel(): a provider key sent as a secret would otherwise win over FLOW_KEY (what the hosted agent gets).

Rotation and exhausted trial credit

flow setup --rotate key replaces FLOW_KEY. The old key works for another 24 hours; --now ends it immediately. Neither command prints the full key.

Exhausted credit returns trial_credit_used with a next step. Add your own provider key to continue with that provider.

For a local audio file named voice.ogg:

Transcription
import { readFile } from "node:fs/promises";
import { flowTranscribe } from "@flow-engineer/flow";
const audio = await readFile("voice.ogg");
const { text } = await flowTranscribe(audio, {
filename: "voice.ogg",
mimeType: "audio/ogg",
});
console.log(text);

This uses the same Flow key and model-server address. It accepts a Blob, File, Buffer, Uint8Array or ArrayBuffer, up to 15 MB. language is optional and detected when omitted. Errors include a message, next step, code and HTTP status.

From Framework 0.17.1 the agent reacts 👀 to a video the moment it arrives, before the video is downloaded, described or watched, and the turn that answers it shows no typing on that channel (none on arrival, none while the agent works or writes). It is on by default and needs no code. Where the channel has reactions, the person sees 👀 on their video at once, then the reply once the agent has seen or read it. To have a video type on arrival instead:

src/agent.ts
import { createAgent } from "@flow-engineer/flow";
const agent = createAgent({
// ...your dir, model, tools and channels
videoReaction: false,
});

With it off, a video types on arrival, kept up while it is described. Photos, voice notes and documents type on arrival either way.

Channels, failures and events
  • WhatsApp and web: the reaction is sent. On WhatsApp the blue ticks still show on arrival: the read receipt goes by itself (no typing indicator) with the reaction.
  • Telegram: only Telegram’s own bot reaction emoji, 👀 among them. A string videoReaction is another emoji; on Telegram one outside that set is not sent, and that turn types instead.
  • iMessage: iOS 18 and later show 👀 as a reaction; iPhones on iOS 17 or older may show it as a line of text. The read receipt still goes when the turn takes the message.
  • SMS, and channels without reactions: no reaction; the turn types as before.
  • A reaction that fails is logged as a warning and never fails the turn; that turn types instead.
  • It is sent as the react tool’s reaction is ({ type: "reaction", emoji, messageId }), with a reaction event marked arrival: true. If the agent reacts to the same message itself later, its reaction replaces this one where the channel allows.

A model that can’t watch videos gets a description of each one instead. describeVideoWith has a video model describe it through the agent’s model key (FLOW_KEY, an OpenRouter key or a Gemini key; OpenAI’s and Anthropic’s APIs take no video):

src/agent.ts
import { createAgent, describeVideoWith } from "@flow-engineer/flow";
const agent = createAgent({
// ...your dir, model, tools and channels
describeVideo: describeVideoWith("google/gemini-3.8-flash"),
});

From Framework 0.17.0 the agent can also ask about a video later, with the built-in ask_about_video tool. When a buyer asks “is there a scratch near the charging port?” about a video sent earlier, the agent calls it and a video model watches the video again:

The agent's call
{
"question": "Is there a scratch near the charging port?",
"message": "m3"
}
The result it reads
{
"video": "m3",
"answer": "Yes, a short scratch just left of the charging port."
}

message is the id of the message the video came in; without it, the latest video. The answer comes from the describer’s ask(video, question) (describeVideoWith’s has one), or else, for a model that watches videos (openAICompatible({ videos: true })), from the agent’s own model.

When it is offered, limits and your own describer
  • Offered only while the conversation has a video the agent can’t see now (one described, or one its model saw turns ago), and its channel can fetch the file again: Flow Messaging, the simulators, flow test, or your own channel with file(ref).
  • The video is fetched again for each question, up to 10 MB, and never kept. 3 questions a turn and 10 a video. A video the channel no longer keeps, or a video model that fails, is a ToolError the agent reads (“Ask them to send it again”) and an attachment.failed event.
  • Each question is a video model call on your key. To keep descriptions only, pass a describer without ask: const described = describeVideoWith(...), then describeVideo: (video) => described(video).
  • Your own describer answers questions when it has ask too: Object.assign(async ({ mime, data }) => text, { ask: async ({ mime, data }, question) => text }).
  • A tool of your own named ask_about_video is hidden while the built-in one is offered: rename it.

The tables below cover common options. The TypeScript AgentOptions definition is the complete contract.

OptionPurpose
dirFolder containing AGENTS.md and skills/
filesSupply those files as text when there is no folder
modelA Model, usually from openAICompatible
toolsYour tool definitions
groupsTool groups offered only on their channels (toolGroup). See one channel only
inlineSkillsInclude every skill in the prompt rather than loading on demand
OptionPurpose
channelswhatsapp(), sms(), customUI(), webChat() or provider channel definitions
resolveResolve a channel identity to your account key
testPeoplePeople the playground may play, as [{ name, phone }]
profileAccount data fetched on demand through get_user_profile
contextSmall facts added before every turn; keep slow lookups out of it
timeZoneThe business time zone, used when the person’s is unknown
quietHoursHours to hold business-started messages; false disables them
transcribeSpeech-to-text for incoming voice notes
describeVideoText for videos the model can’t watch, and answers to ask_about_video (videos)
videoReaction👀 on a video the moment it arrives, and no typing for its turn; on by default, false types on arrival instead (videos)

See messaging and people for identity and time-zone behavior, and reminders and nudges for delivery rules.

OptionPurpose
databaseDurable storage; defaults to an in-memory SQLite database
storeSupply your own store instead of a database
recordsCollections of the agent’s own small records, kept in the same store (records)
wakeUpsfalse removes the model’s wake_me_up and cancel_wake_up tools and their list from its prompt; wake-ups set by code still run (wake-ups)
hostHosting options passed as host: options.host from buildAgent
routesYour HTTP handlers, keyed by exact path, answered by agent.fetch(request); on Flow’s hosting they are served at the agent’s public URL (webhooks and callbacks)
eventsEvent sinks receiving runtime events
tracesTrace export settings; defaults come from the environment

Self-hosting covers persistence and restart handling. See Deployment for Flow hosting and Traces for observability.

OptionDefaultPurpose
debounceMs300Quiet time after a message before a reply starts
deadlineMs60,000How long a reply waits for a tool before moving it to the background
partialAfterMs5,000How long a finished tool result waits for other tools in that response
maxSteps8Model steps per turn
history.maxTokens60% of contextTokens, else 50,000History carried into each model call
history.toolResultChars12,000Limit for a tool result in history

Durations are milliseconds. A tool’s own deadlineMs overrides the agent’s value for that tool.

OptionPurpose
beforeSendChange or refuse the final message before validation, sending and recording
interceptAnswer an incoming message without a model call
templatesYour declared WhatsApp templates
fallbackTemplateThe template used when a nudge meets a closed WhatsApp window
shareUpdatesEnable, disable or customize live status guidance in web and app interfaces
writingReplace (a string) or leave out (false) the guidance on how messages read (details); from 0.12.0
beforeSend return values

beforeSend(message, { channel, address, info, origin }) runs for messages, carousels and templates on every channel. Return nothing to send the input, another message to replace it, or { refuse: "why" } to tell the agent to try again.

It runs before platform content checks. History, transcripts and test judges see what was actually sent.

An edit’s new text runs through it too, as a message with only text, and context.edit.messageId names the message being edited. A replacement is what goes out; a refusal sends nothing.

Edits, unsends and message ids

On channels whose info has edits and unsends (Telegram and iMessage on Flow Messaging, or a custom UI with editMessage and unsendMessage), the agent is offered edit_message ({ message_id, text }) and unsend_message ({ message_id }). Its send results there name each message ({"delivered":true,"channel":"imessage","message_id":"msg_..."}). WhatsApp and SMS offer neither tool.

The platform decides how late an edit or unsend may come. Flow Messaging refuses a late one when it is made (422 unsupported_content with edit_window_closed, unsend_window_closed, first_message_not_editable or not_on_sms), and the agent gets that refusal as its tool result, for example Not edited: unsupported_content (edit_window_closed, on imessage): iMessage allows edits within 15 minutes of sending; .... Nothing is sent instead.

Your own code gets the id too: a send’s SendReceipt.messageId, the messageId on message.out events, and a sent nudge’s NudgeResult.messageId. message.edited and message.unsent events record each change. Requires @flow-engineer/flow 0.7.0 or later.

intercept and keyword messages

intercept(conversationId, text, message) sees the incoming channel and any STOP, START or HELP classification in message.keyword.

Its answer is stored in history and the transcript. STOP and START are enforced even if the hook returns an answer or throws. See keyword handling.