Building a single-agent demo is straightforward. Coordinating four specialized agents, persisting intermediate state, skipping completed work on retries, and keeping the API responsive while models think is where the plumbing gets interesting.
Clause AI analyzes rental and lease agreements using a four-agent pipeline built with Mastra, a TypeScript orchestration framework. Each agent has a focused responsibility: parsing structure, summarizing clauses, flagging risk, and answering user questions via RAG. The implementation exposes real orchestration challenges: state handoff, partial failure recovery, and type-safe communication across agent boundaries.
Why Four Agents Instead of One Prompt
A monolithic prompt that tries to extract entities, summarize clauses, score risk, and answer questions in one pass creates brittle failure modes:
Worker crashes mid-pipeline force full re-runs, burning API quota on already-completed steps






