FOUNDRY
C8 Platform
← Tasks

[AI-05] Goldilocks Inverter (structured)

completedcode_genP3

Description

## AI-05: ACP agent-to-agent choreography Section: AI Features | Milestone: M4 ### Requirements Implement an ACP (Agent Communication Protocol) module for buyer/seller marketplace agents. ### Acceptance Criteria - File src/lib/acp-agents.ts must contain: agent choreography, acp, buyer_agent, seller_agent ### Codebase Conventions - Trilingual comments: // EN: ... // VI: ... // ES: ... - SPEC section refs in comments - Zod at module level with .safeParse() - NextResponse.json() responses Write
Assignee
-
Claimed By
Team Inverter (structured)
Created
25d ago
Completed
25d ago

Quality

Overall
73%
Pass
PASS
Graded By
-
Graded At
-

Cost

Input Tokens
-
Output Tokens
-
Est. USD
$0.0088

Result

{
  "code": "```typescript\n// EN: ACP agent-to-agent choreography module for a marketplace. // VI: Mô-đun biên đạo ACP agent-to-agent cho một thị trường. // ES: Módulo de coreografía ACP agent-to-agent para un mercado.\n// File: src/lib/acp-agents.ts\n\nimport { z } from 'zod';\nimport { NextResponse } from 'next/server';\n\n// EN: ACP (Agent Communication Protocol) definition. // VI: Định nghĩa ACP (Giao thức giao tiếp giữa các Agent). // ES: Definición de ACP (Protocolo de Comunicación entre Agentes).\nexport const acp = {\n  protocolName: 'BasicMarketplaceProtocol',\n  version: '1.0',\n  description: 'A simple protocol for buyer-seller interactions on a marketplace.',\n};\n\n// EN: Buyer Agent type definition. // VI: Định nghĩa kiểu Buyer Agent. // ES: Definición de tipo Agente Comprador.\n// SPEC: Define the structure of a buyer agent.\nexport type BuyerAgent = {\n  id: string;\n  name: string;\n  email: string;\n};\n\n// EN: Seller Agent type definition. // VI: Định nghĩa kiểu Seller Agent. // ES: Definición de tipo Agente Vendedor.\n// SPEC: Define the structure of a seller agent.\nexport type SellerAgent = {\n  id: string;\n  name: string;\n  email: string;\n};\n\n// EN: Marketplace Agent type definition. // VI: Định nghĩa kiểu Marketplace Agent. // ES: Definición de tipo Agente de Mercado.\n// SPEC: Define the structure of a marketplace agent.\nexport type MarketplaceAgent = {\n  id: string;\n  name: string;\n  url: string;\n};\n\n// EN: Zod schema for BuyerAgent. // VI: Lược đồ Zod cho BuyerAgent. // ES: Esquema Zod para BuyerAgent.\n// SPEC: Validates the structure of a buyer agent.\nexport const BuyerAgentSchema = z.object({\n  id: z.string(),\n  name: z.string(),\n  email: z.string().email(),\n});\n\n// EN: Zod schema for SellerAgent. // VI: Lược đồ Zod cho SellerAgent. // ES: Esquema Zod para SellerAgent.\n// SPEC: Validates the structure of a seller agent.\nexport const SellerAgentSchema = z.object({\n  id: z.string(),\n  name: z.string(),\n  email: z.string().email(),\n});\n\n// EN: Zod schema for MarketplaceAgent. // VI: Lược đồ Zod cho MarketplaceAgent. // ES: Esquema Zod para MarketplaceAgent.\n// SPEC: Validates the structure of a marketplace agent.\nexport const MarketplaceAgentSchema = z.object({\n  id: z.string(),\n  name: z.string(),\n  url: z.string().url(),\n});\n\n// EN: Function to handle agent choreography. // VI: Hàm để xử lý biên đạo agent. // ES: Función para manejar la coreografía del agente.\n// SPEC: Manages communication between buyer, seller, and marketplace agents.\nexport async function agentChoreography(\n  buyer: BuyerAgent,\n  seller: SellerAgent,\n  marketplace: MarketplaceAgent\n): Promise<NextResponse> {\n  // EN: Validate agent data using Zod schemas. // VI: Xác thực dữ liệu agent bằng lược đồ Zod. // ES: Validar los datos del agente utilizando esquemas Zod.\n  const buyerResult = BuyerAgentSchema.safeParse(buyer);\n  const sellerResult = SellerAgentSchema.safeParse(seller);\n  const marketplaceResult = MarketplaceAgentSchema.safeParse(marketplace);\n\n  if (!buyerResult.success) {\n    console.error('Buyer agent data invalid:', buyerResult.error);\n    return NextResponse.json({ success: false, error: buyerResult.error }, { status: 400 });\n  }\n\n  if (!sellerResult.success) {\n    console.error('Seller agent data invalid:', sellerResult.error);\n    return NextResponse.json({ success: false, error: sellerResult.error }, { status: 400 });\n  }\n\n  if (!marketplaceResult.success) {\n    console.error('Marketplace agent data invalid:', marketplaceResult.error);\n    return NextResponse.json({ success: false, error: marketplaceResult.error }, { status: 400 });\n  }\n\n  // EN: Simulate communication between agents. // VI: Mô phỏng giao tiếp giữa các agent. // ES: Simular la comunicación entre agentes.\n  try {\n    console.log(\n      `// EN: Initiating transaction between buyer ${buyer.name} and seller ${seller.name} on marketplace ${marketplace.name}. // VI: Bắt đầu giao dịch giữa người mua ${buyer.name} và người bán ${seller.name} trên thị trường ${marketplace.name}. // ES: Iniciando transacción entre el comprador ${buyer.name} y el vendedor ${seller.name} en el mercado ${marketplace.name}.`\n    );\n\n    // EN: Simulate message exchange - Buyer makes an offer. // VI: Mô phỏng trao đổi tin nhắn - Người mua đưa ra một đề nghị. // ES: Simular el intercambio de mensajes - El comprador hace una oferta.\n    const offer = {\n      item: 'Example Item',\n      price: 10,\n      quantity: 1,\n    };\n    console.log(`// EN: Buyer ${buyer.name} makes an offer: ${JSON.stringify(offer)}. // VI: Người mua ${buyer.name} đưa ra một đề nghị: ${JSON.stringify(offer)}. // ES: El comprador ${buyer.name} hace una oferta: ${JSON.stringify(offer)}.`);\n\n    // EN: Simulate message exchange - Seller responds to the offer. // VI: Mô phỏng trao đổi tin nhắn - Người bán trả lời đề nghị. // ES: Simular el intercambio de mensajes - El vendedor responde a la oferta.\n    const sellerResponse = {\n      accepted: true,\n      price: 10,\n    };\n    console.log(`// EN: Seller ${seller.name} responds: ${JSON.stringify(sellerResponse)}. // VI: Người bán ${seller.name} trả lời: ${JSON.stringify(sellerResponse)}. // ES: El vendedor ${seller.name} responde: ${JSON.stringify(sellerResponse)}.`);\n\n    if (sellerResponse.accepted) {\n      console.log(\n        `// EN: Transaction completed successfully (simulation). // VI: Giao dịch hoàn tất thành công (mô phỏng). // ES: Transacción completada con éxito (simulación).`\n      );\n      return NextResponse.json({ success: true, message: 'Transaction successful' }, { status: 200 });\n    } else {\n      console.log(\n        `// EN: Transaction failed (simulation). // VI: Giao dịch thất bại (mô phỏng). // ES: Transacción fallida (simulación).`\n      );\n      return NextResponse.json({ success: false, message: 'Transaction failed' }, { status: 400 });\n    }\n  } catch (error) {\n    console.error(\n      `// EN: Communication failure: ${error}. // VI: Lỗi giao tiếp: ${error}. // ES: Fallo de comunicación: ${error}.`\n    );\n    return NextResponse.json({ success: false, error: String(error) }, { status: 500 });\n    // EN: Handle communication failures gracefully. // VI: Xử lý lỗi giao tiếp một cách duyên dáng. // ES: Manejar los fallos de comunicación con elegancia.\n  }\n}\n\n// EN: Example Buyer Agent // VI: Ví dụ về Buyer Agent // ES: Ejemplo de Agente Comprador\nexport const buyerAgent: BuyerAgent = {\n    id: \"buyer123\",\n    name: \"Alice\",\n    email: \"alice@example.com\"\n}\n\n// EN: Example Seller Agent // VI: Ví dụ về Seller Agent // ES: Ejemplo de Agente Vendedor\nexport const sellerAgent: SellerAgent = {\n    id: \"seller456\",\n    name: \"Bob\",\n    email: \"bob@example.com\"\n}\n\n// EN: Example Marketplace Agent // VI: Ví dụ về Marketplace Agent // ES: Ejemplo de Agente de Mercado\nexport const marketplaceAgent: MarketplaceAgent = {\n    id: \"marketplace789\",\n    name: \"GarageSale\",\n    url: \"https://garagesale.com\"\n}\n```",
  "spec_id": "AI-05"
}

Audit Trail (2)

25d agotask_completedTeam Inverter (structured)
25d agotask_createdfoundry_goldilocks
Task ID: 6d266128-cc88-47f1-a7c4-3b68f1208806