← Tasks
[AI-05] ACP choreography (Vertex Flash)
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
Vertex Flash
Created
25d ago
Completed
25d ago
Quality
Overall
88%
Pass
PASS
Graded By
-
Graded At
-
Cost
Input Tokens
168
Output Tokens
1,899
Est. USD
-
Result
{
"code": "```typescript\n// EN: ACP agent-to-agent choreography module. // VI: Mô-đun biên đạo giữa các tác nhân ACP. // ES: Módulo de coreografía agente a agente ACP.\n// File: src/lib/acp-agents.ts\n\nimport { z } from \"zod\";\nimport { NextResponse } from \"next/server\";\n\n// EN: Zod schema for Buyer Agent. // VI: Lược đồ Zod cho Tác nhân Mua hàng. // ES: Esquema Zod para Agente Comprador.\nconst BuyerAgentSchema = z.object({\n id: z.string(),\n type: z.literal(\"buyer\"),\n preferences: z.object({\n productCategory: z.string(),\n maxPrice: z.number(),\n }),\n});\n\n// EN: Zod schema for Seller Agent. // VI: Lược đồ Zod cho Tác nhân Bán hàng. // ES: Esquema Zod para Agente Vendedor.\nconst SellerAgentSchema = z.object({\n id: z.string(),\n type: z.literal(\"seller\"),\n inventory: z.array(\n z.object({\n productName: z.string(),\n productCategory: z.string(),\n price: z.number(),\n quantity: z.number(),\n })\n ),\n});\n\n// EN: Zod schema for Marketplace Agent. // VI: Lược đồ Zod cho Tác nhân Thị trường. // ES: Esquema Zod para Agente de Mercado.\nconst MarketplaceAgentSchema = z.object({\n id: z.string(),\n type: z.literal(\"marketplace\"),\n listings: z.array(\n z.object({\n sellerId: z.string(),\n productName: z.string(),\n productCategory: z.string(),\n price: z.number(),\n quantity: z.number(),\n })\n ),\n});\n\n// EN: TypeScript types derived from Zod schemas. // VI: Các kiểu TypeScript được suy ra từ lược đồ Zod. // ES: Tipos de TypeScript derivados de esquemas Zod.\nexport type BuyerAgent = z.infer<typeof BuyerAgentSchema>;\nexport type SellerAgent = z.infer<typeof SellerAgentSchema>;\nexport type MarketplaceAgent = z.infer<typeof MarketplaceAgentSchema>;\n\n// EN: Agent Communication Protocol (ACP) functions. // VI: Các hàm Giao thức Giao tiếp Tác nhân (ACP). // ES: Funciones del Protocolo de Comunicación de Agentes (ACP).\nexport const acp = {\n // EN: Buyer agent sends a request for a product. // VI: Tác nhân mua hàng gửi yêu cầu về một sản phẩm. // ES: El agente comprador envía una solicitud de un producto.\n requestProduct: (\n buyer: BuyerAgent,\n productCategory: string,\n maxPrice: number\n ) => {\n // EN: Simulate sending the request. // VI: Mô phỏng việc gửi yêu cầu. // ES: Simular el envío de la solicitud.\n console.log(\n `Buyer ${buyer.id} requesting product category: ${productCategory} with max price: ${maxPrice}`\n );\n return {\n buyerId: buyer.id,\n productCategory,\n maxPrice,\n };\n },\n\n // EN: Seller agent responds with available products. // VI: Tác nhân bán hàng trả lời với các sản phẩm có sẵn. // ES: El agente vendedor responde con los productos disponibles.\n respondWithProducts: (seller: SellerAgent, productCategory: string) => {\n const availableProducts = seller.inventory.filter(\n (item) => item.productCategory === productCategory\n );\n\n // EN: Simulate sending the response. // VI: Mô phỏng việc gửi phản hồi. // ES: Simular el envío de la respuesta.\n console.log(\n `Seller ${seller.id} responding with available products for category: ${productCategory}`\n );\n console.log(availableProducts);\n return availableProducts;\n },\n\n // EN: Marketplace agent lists available products. // VI: Tác nhân thị trường liệt kê các sản phẩm có sẵn. // ES: El agente del mercado enumera los productos disponibles.\n listProducts: (marketplace: MarketplaceAgent) => {\n // EN: Simulate listing products. // VI: Mô phỏng việc liệt kê sản phẩm. // ES: Simular la lista de productos.\n console.log(`Marketplace ${marketplace.id} listing available products.`);\n console.log(marketplace.listings);\n return marketplace.listings;\n },\n\n // EN: Add a listing to the marketplace. // VI: Thêm một danh sách vào thị trường. // ES: Agregar un listado al mercado.\n addListing: (\n marketplace: MarketplaceAgent,\n sellerId: string,\n productName: string,\n productCategory: string,\n price: number,\n quantity: number\n ) => {\n const newListing = {\n sellerId,\n productName,\n productCategory,\n price,\n quantity,\n };\n marketplace.listings.push(newListing);\n console.log(`Marketplace ${marketplace.id} added listing:`, newListing);\n return newListing;\n },\n};\n\n// EN: Example usage (Agent Choreography). // VI: Ví dụ sử dụng (Biên đạo Tác nhân). // ES: Ejemplo de uso (Coreografía de Agentes).\nexport const agentChoreography = async () => {\n // EN: Create buyer and seller agents. // VI: Tạo các tác nhân mua và bán. // ES: Crear agentes compradores y vendedores.\n const buyerAgentResult = BuyerAgentSchema.safeParse({\n id: \"buyer123\",\n type: \"buyer\",\n preferences: {\n productCategory: \"electronics\",\n maxPrice: 500,\n },\n });\n\n const sellerAgentResult = SellerAgentSchema.safeParse({\n id: \"seller456\",\n type: \"seller\",\n inventory: [\n {\n productName: \"Laptop\",\n productCategory: \"electronics\",\n price: 450,\n quantity: 10,\n },\n {\n productName: \"Keyboard\",\n productCategory: \"electronics\",\n price: 75,\n quantity: 20,\n },\n ],\n });\n\n const marketplaceAgentResult = MarketplaceAgentSchema.safeParse({\n id: \"marketplace789\",\n type: \"marketplace\",\n listings: [],\n });\n\n if (!buyerAgentResult.success || !sellerAgentResult.success || !marketplaceAgentResult.success) {\n console.error(\"Error parsing agent data:\", buyerAgentResult.error, sellerAgentResult.error, marketplaceAgentResult.error);\n return NextResponse.json({ error: \"Invalid agent data\" }, { status: 400 });\n }\n\n const buyerAgent = buyerAgentResult.data;\n const sellerAgent = sellerAgentResult.data;\n const marketplaceAgent = marketplaceAgentResult.data;\n\n // EN: Buyer requests a product. // VI: Người mua yêu cầu một sản phẩm. // ES: El comprador solicita un producto.\n const request = acp.requestProduct(\n buyerAgent,\n buyerAgent.preferences.productCategory,\n buyerAgent.preferences.maxPrice\n );\n\n // EN: Seller responds with available products. // VI: Người bán trả lời với các sản phẩm có sẵn. // ES: El vendedor responde con los productos disponibles.\n const products = acp.respondWithProducts(\n sellerAgent,\n request.productCategory\n );\n\n // EN: Add the products to the marketplace. // VI: Thêm các sản phẩm vào thị trường. // ES: Agregar los productos al mercado.\n products.forEach((product) => {\n acp.addListing(\n marketplaceAgent,\n sellerAgent.id,\n product.productName,\n product.productCategory,\n product.price,\n product.quantity\n );\n });\n\n // EN: List the available products in the marketplace. // VI: Liệt kê các sản phẩm có sẵn trên thị trường. // ES: Listar los productos disponibles en el mercado.\n const listings = acp.listProducts(marketplaceAgent);\n\n return NextResponse.json({ request, products, listings });\n};\n```",
"spec_id": "AI-05"
}Audit Trail (2)
25d agotask_completedVertex Flash
25d agotask_createdfoundry_race
Task ID: dd49c136-0c08-4d9c-88d0-b769ea581535