A 7-agent Python pipeline that researches prospects, builds strategy, writes proposals, self-reviews, and remembers what it learned

Brain Service — Multi-Agent Orchestration

A 7-agent Python pipeline that researches prospects, builds strategy, writes proposals, self-reviews, and remembers what it learned.

The 7-Agent Pipeline

Step Agent Model What It Does
1 Context Node Loads org brain, client intelligence (psychographics + deal history), runs pgvector similarity search for similar past clients. Detects cold start vs returning client.
2 Research Node Scrapes prospect website via Jina Reader. Extracts industry, services, tone, size signals. Caches in prospect_intelligence. Never blocks pipeline on failure.
3 Strategist Node Claude Sonnet Analyzes all context: client history + research + org knowledge. Outputs positioning, tone, key themes, pricing strategy, risks to address.
4 Writer Node Claude Sonnet Generates full ProposalData JSON: cover, summary, problem, features, architecture, tech stack, timeline, pricing, about, next steps. Matches org voice.
5 Reviewer Node Claude Haiku Validates completeness against proposal heuristics. Flags gaps. Soft pass on parse failure — never blocks delivery. Loops back to Writer if gaps found.
6 Commit Node Writes final proposal JSON to Supabase. Sets brain_status = 'content_generated'. Marks needs_human_review if reviewer didn't pass.
7 Memory Node Non-fatal write-back. Upserts client_intelligence with psychographics and deal entry. Generates OpenAI embedding for future vector search.
Feedback Loop: Steps 4 and 5 (Writer + Reviewer) form a feedback loop. If the Reviewer finds gaps, it sends structured feedback back to the Writer for a second pass. This self-correction happens within the pipeline — no human intervention needed.

Production Safety Patterns

300s Wall-Clock Timeout

The entire pipeline is wrapped in asyncio.wait_for() with a 300-second hard limit. If any agent hangs, the pipeline is killed cleanly.

Resume-From-Step

Writer output is cached in cached_writer_output. If the reviewer or commit fails, the next attempt skips directly to the cached checkpoint.

Non-Fatal Memory

The Memory Node runs after the proposal is committed. If embedding generation or intelligence upsert fails, the proposal is still delivered.

Atomic Job Claiming

FOR UPDATE SKIP LOCKED prevents duplicate processing. Multiple brain instances can poll simultaneously without conflict.

Multi-Model Strategy: The brain uses different Claude models for different tasks. Sonnet for writing and strategy (creative, long-form). Haiku for review (fast validation, 80% cheaper). This optimizes for both quality and cost.

Ready to create AI-powered proposals?

Start Free