Run one turn of the framework-chat agent for an AI sequence node. Persists the conversation and returns the result inline.
ai_chat_sessions row keyed by (user, campaign, node), appends the user’s chat message, runs the Claude multi-step agent with updateSkeleton + searchWeb tools, persists any new skeleton, and returns the assistant reply + the latest skeleton inline.
Requirements:
draft statusnode_id must belong to this campaign AND have type: "ai"sample_leads, the server auto-samples up to 5 prospects from the campaign so the agent can ground its examples in real data.
(user_id, campaign_id, node_id) — there is at most one persistent chat per AI node. The server creates it lazily on the first call; subsequent calls continue the same thread. Store session_id from the response if you want to cross-reference the ai_chat_sessions row directly.Skeleton lifecycle. skeleton_updated: true means the agent produced a new framework during this turn. When that happens, any previously cached generated_examples on the session are cleared server-side — you’ll need to regenerate examples before the skeleton can be used to seed prospect drafts.Quality gate. The agent’s updateSkeleton tool runs a judge pass (em-dash check + rules validator) before accepting the skeleton. If the judge fails, the tool returns status: "failed" to the agent so it can self-correct within the same turn; the final skeleton returned to you is always the last one that passed (or null if none ever did).Single-writer — 409 means try again. A concurrent call on the same session returns 409 with Session is busy (chat_processing). Wait and retry — the session releases when the turn completes or errors out.Follow-ups. After a satisfactory skeleton, call POST /api/campaigns/{id}/ai-chat-sessions/{id}/generate-examples to produce per-prospect example emails, then POST /api/campaigns/{id}/generate-messages with action: "resolve" to seed draft messages for launch.Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Campaign UUID
^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$A single chat turn. The server appends it to the persisted conversation, runs the framework-chat agent synchronously, and returns the result.
UUID of the sequence node being drafted. Must belong to this campaign and have type === 'ai'.
^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$User-authored chat turn — natural-language instructions to the framework-chat agent.
1Optional ground-truth examples for the AI. When omitted, the server pulls up to 5 prospects from the campaign.
Optional structured context about sibling nodes, used by the prompt to avoid duplication.
Chat turn complete. The session row has been updated and the returned skeleton is the latest version.
Synchronous framework-chat result. The ai_chat_sessions row has already been updated with the new turn + skeleton.
The ai_chat_sessions row identifier. Persist this to continue the same conversation on future turns.
^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$Plain-text assistant reply. Render as the AI's chat message.
Structured email framework produced by the AI. Persisted on the ai_chat_sessions row and returned verbatim.
True iff the agent produced a new skeleton during this turn. When true, any previously cached generated_examples on the session are cleared server-side.