Multi-Agent System Design
Scriptonia uses specialized AI agents driven by LLM calls (OpenRouter). Two modes:- Sequential (stages 1–3): One agent per stage — IdeaProcessor → IntentAnalyzer → PlatformSelector.
- Parallel (execution): Multiple execution agents (ProductManager, FrontendDev, BackendDev, DevOpsEngineer, ToolManager) generate files in parallel based on platform templates.
lib/openai.ts (executeX402Workflow) and lib/platform-templates.ts (generatePlatformDeliverables). The X402 workflow and A2A helpers in lib/x402.ts and lib/a2a.ts support coordination and future extensions.
Agent Roles and Responsibilities
Defined inlib/x402.ts as AGENT_ROLES:
| Agent | Stage | Responsibility |
|---|---|---|
| CEO | idea_input | Entry; routes to X402Agent and other agents (conceptual in current flow). |
| X402Agent | execution | Orchestrator for X402 execution, payment, platform. |
| IdeaProcessor | idea_input | Analyzes idea → analysis, clarifying_questions. |
| IntentAnalyzer | intent_analysis | Refines idea + answers → refined_requirements. |
| PlatformSelector | platform_selection | Maps requirements → platform_options, recommended. |
| PaymentValidator | payment_processing | Validates wallet/balance (in lib/solana and payment API). |
| ProductManager | execution | PRD, PLAN, requirements; coordinates with Frontend/Backend, ToolManager. |
| FrontendDev | execution | UI, pages, components; coordinates with Backend, ToolManager. |
| BackendDev | execution | APIs, DB, services; coordinates with Frontend, AIEngineer, ToolManager. |
| AIEngineer | execution | AI pipelines, RAG, prompts (in AGENT_ROLES; execution file assignment may omit). |
| DevOpsEngineer | execution | Infra, CI/CD, deployment; coordinates with ToolManager. |
| ToolManager | execution | GitHub, meta, export, external services; coordinates with all. |
Communication Patterns
Sequential (Idea → Intent → Platform)
- IdeaProcessor: Input:
idea. Output:analysis,clarifying_questions. No inter-agent call. - IntentAnalyzer: Input:
idea,answers. Output:refined_requirements. No inter-agent call. - PlatformSelector: Input:
refined_requirements. Output:platform_options,recommended. No inter-agent call.
WorkflowContext (DB or in-memory). Each step is a single LLM request.
Parallel (Execution)
- File–agent mapping:
getAgentForFileinlib/platform-templates.ts:PRD,PLAN,requirements→ ProductManagerfrontend,components,pages→ FrontendDevbackend,api,database→ BackendDevinfra,deployment,ci_cd→ DevOpsEngineergithub,meta,export→ ToolManager
- Coordination:
generateFileContentWithAgentreceivesexistingDeliverablesandworkflowContext(idea, analysis, answers, platform, payment). Agent-specific system prompts and “related files” from other agents are included so output stays consistent. - Parallelism: Files are grouped by agent; agents run in parallel (
Promise.all). Within an agent, files are processed in batches (e.g. 5) with small delays to reduce duplicate content and respect rate limits.
Coordination Mechanisms
- WorkflowContext — Single source of truth for idea, analysis, answers,
refinedRequirements,platformOptions,selectedPlatform,paymentDetails,supabaseIntegration. Passed intogeneratePlatformDeliverablesandgenerateFileContentWithAgent. - Platform templates —
getWebsiteTemplate,getWebAppTemplate,getAndroidTemplate,getIOSTemplatedefinefolderStructureandtechStack.generatePlatformDeliverableswalks the tree, assigns each file to an agent, and runs generation. - Agent system prompts — In
generateFileContentWithAgent, each execution agent has a short system prompt (e.g. “Coordinate with FrontendDev and BackendDev”) so generated specs and contracts stay aligned. - A2A (optional) —
lib/a2a.tsprovidessendA2ARequest,sendA2AResponse,shareA2AData,sendA2ANotification, andA2AWorkflowIntegration. Used for tests and can be used for richer agent-to-agent calls during execution. - Review step —
reviewDeliverablesinopenai.tschecks structure and completeness and setsreview_passed/review_issueson the execution result. - Deduplication —
deduplicateContentregenerates content for duplicate deliverables to improve uniqueness.