Skip to main content

Multi-Agent System Design

Scriptonia uses specialized AI agents driven by LLM calls (OpenRouter). Two modes:
  1. Sequential (stages 1–3): One agent per stage — IdeaProcessor → IntentAnalyzer → PlatformSelector.
  2. Parallel (execution): Multiple execution agents (ProductManager, FrontendDev, BackendDev, DevOpsEngineer, ToolManager) generate files in parallel based on platform templates.
Orchestration is implemented in 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 in lib/x402.ts as AGENT_ROLES:
AgentStageResponsibility
CEOidea_inputEntry; routes to X402Agent and other agents (conceptual in current flow).
X402AgentexecutionOrchestrator for X402 execution, payment, platform.
IdeaProcessoridea_inputAnalyzes idea → analysis, clarifying_questions.
IntentAnalyzerintent_analysisRefines idea + answers → refined_requirements.
PlatformSelectorplatform_selectionMaps requirements → platform_options, recommended.
PaymentValidatorpayment_processingValidates wallet/balance (in lib/solana and payment API).
ProductManagerexecutionPRD, PLAN, requirements; coordinates with Frontend/Backend, ToolManager.
FrontendDevexecutionUI, pages, components; coordinates with Backend, ToolManager.
BackendDevexecutionAPIs, DB, services; coordinates with Frontend, AIEngineer, ToolManager.
AIEngineerexecutionAI pipelines, RAG, prompts (in AGENT_ROLES; execution file assignment may omit).
DevOpsEngineerexecutionInfra, CI/CD, deployment; coordinates with ToolManager.
ToolManagerexecutionGitHub, 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.
Data flows via WorkflowContext (DB or in-memory). Each step is a single LLM request.

Parallel (Execution)

  • File–agent mapping: getAgentForFile in lib/platform-templates.ts:
    • PRD, PLAN, requirementsProductManager
    • frontend, components, pagesFrontendDev
    • backend, api, databaseBackendDev
    • infra, deployment, ci_cdDevOpsEngineer
    • github, meta, exportToolManager
  • Coordination: generateFileContentWithAgent receives existingDeliverables and workflowContext (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

  1. WorkflowContext — Single source of truth for idea, analysis, answers, refinedRequirements, platformOptions, selectedPlatform, paymentDetails, supabaseIntegration. Passed into generatePlatformDeliverables and generateFileContentWithAgent.
  2. Platform templatesgetWebsiteTemplate, getWebAppTemplate, getAndroidTemplate, getIOSTemplate define folderStructure and techStack. generatePlatformDeliverables walks the tree, assigns each file to an agent, and runs generation.
  3. 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.
  4. A2A (optional)lib/a2a.ts provides sendA2ARequest, sendA2AResponse, shareA2AData, sendA2ANotification, and A2AWorkflowIntegration. Used for tests and can be used for richer agent-to-agent calls during execution.
  5. Review stepreviewDeliverables in openai.ts checks structure and completeness and sets review_passed / review_issues on the execution result.
  6. DeduplicationdeduplicateContent regenerates content for duplicate deliverables to improve uniqueness.