← 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
77%
Pass
PASS
Graded By
-
Graded At
-
Cost
Input Tokens
168
Output Tokens
1,640
Est. USD
-
Result
{
"code": "```typescript\n// EN: ACP agent-to-agent choreography module for marketplace agents. // VI: Mô-đun biên đạo ACP agent-to-agent cho các agent trên thị trường. // ES: Módulo de coreografía ACP agent-to-agent para agentes de mercado.\n// SPEC: AI-05\n\nimport { z } from \"zod\";\nimport { NextResponse } from \"next/server\";\n\n// EN: Define Zod schema for Buyer Agent. // VI: Định nghĩa lược đồ Zod cho Buyer Agent. // ES: Define el esquema Zod para el Agente Comprador.\nconst BuyerAgentSchema = z.object({\n id: z.string(),\n name: z.string(),\n budget: z.number().positive(),\n preferences: z.array(z.string()),\n});\n\n// EN: Define Zod schema for Seller Agent. // VI: Định nghĩa lược đồ Zod cho Seller Agent. // ES: Define el esquema Zod para el Agente Vendedor.\nconst SellerAgentSchema = z.object({\n id: z.string(),\n name: z.string(),\n inventory: z.array(\n z.object({\n item: z.string(),\n price: z.number().positive(),\n quantity: z.number().int().positive(),\n })\n ),\n});\n\n// EN: Define Zod schema for Marketplace Agent. // VI: Định nghĩa lược đồ Zod cho Marketplace Agent. // ES: Define el esquema Zod para el Agente de Mercado.\nconst MarketplaceAgentSchema = z.object({\n id: z.string(),\n name: z.string(),\n rules: z.array(z.string()),\n});\n\n// EN: Type definitions based on Zod schemas. // VI: Định nghĩa kiểu dựa trên lược đồ Zod. // ES: Definiciones de tipo basadas en esquemas Zod.\ntype BuyerAgent = z.infer<typeof BuyerAgentSchema>;\ntype SellerAgent = z.infer<typeof SellerAgentSchema>;\ntype MarketplaceAgent = z.infer<typeof MarketplaceAgentSchema>;\n\n// EN: ACP (Agent Communication Protocol) message schema. // VI: Lược đồ tin nhắn ACP (Agent Communication Protocol). // ES: Esquema de mensaje ACP (Protocolo de Comunicación de Agentes).\nconst ACPMessageSchema = z.object({\n senderId: z.string(),\n receiverId: z.string(),\n type: z.enum([\"offer\", \"request\", \"accept\", \"reject\", \"query\"]),\n content: z.record(z.any()), // EN: Allow any content for flexibility. // VI: Cho phép bất kỳ nội dung nào để linh hoạt. // ES: Permite cualquier contenido para flexibilidad.\n});\n\ntype ACPMessage = z.infer<typeof ACPMessageSchema>;\n\n// EN: Function to simulate sending an ACP message. // VI: Hàm mô phỏng việc gửi tin nhắn ACP. // ES: Función para simular el envío de un mensaje ACP.\nasync function sendMessage(message: ACPMessage): Promise<NextResponse> {\n // EN: In a real implementation, this would involve network communication. // VI: Trong một triển khai thực tế, điều này sẽ liên quan đến giao tiếp mạng. // ES: En una implementación real, esto implicaría la comunicación de red.\n console.log(`Sending message from ${message.senderId} to ${message.receiverId}:`, message);\n\n const parsedMessage = ACPMessageSchema.safeParse(message);\n\n if (!parsedMessage.success) {\n console.error(\"Invalid ACP Message:\", parsedMessage.error);\n return NextResponse.json({ error: \"Invalid ACP Message\", details: parsedMessage.error }, { status: 400 });\n }\n\n return NextResponse.json({ status: \"message sent\", message: parsedMessage.data }, { status: 200 });\n}\n\n// EN: Example agent choreography. // VI: Ví dụ về biên đạo agent. // ES: Ejemplo de coreografía de agentes.\nasync function agentChoreography() {\n // EN: Example Buyer and Seller agents. // VI: Ví dụ về các agent Buyer và Seller. // ES: Ejemplos de agentes Comprador y Vendedor.\n const buyer: BuyerAgent = {\n id: \"buyer123\",\n name: \"Alice\",\n budget: 100,\n preferences: [\"laptop\", \"mouse\"],\n };\n\n const seller: SellerAgent = {\n id: \"seller456\",\n name: \"Bob\",\n inventory: [\n { item: \"laptop\", price: 80, quantity: 5 },\n { item: \"mouse\", price: 15, quantity: 10 },\n ],\n };\n\n // EN: Simulate buyer sending a request for a laptop. // VI: Mô phỏng người mua gửi yêu cầu về máy tính xách tay. // ES: Simular que el comprador envía una solicitud de una computadora portátil.\n const requestMessage: ACPMessage = {\n senderId: buyer.id,\n receiverId: seller.id,\n type: \"request\",\n content: {\n item: \"laptop\",\n quantity: 1,\n },\n };\n\n const requestResponse = await sendMessage(requestMessage);\n console.log(\"Request response:\", requestResponse);\n\n if (requestResponse.status !== 200) {\n return;\n }\n\n // EN: Simulate seller sending an offer for the laptop. // VI: Mô phỏng người bán gửi một lời đề nghị cho máy tính xách tay. // ES: Simular que el vendedor envía una oferta por la computadora portátil.\n const offerMessage: ACPMessage = {\n senderId: seller.id,\n receiverId: buyer.id,\n type: \"offer\",\n content: {\n item: \"laptop\",\n price: 80,\n quantity: 1,\n },\n };\n\n const offerResponse = await sendMessage(offerMessage);\n console.log(\"Offer response:\", offerResponse);\n\n if (offerResponse.status !== 200) {\n return;\n }\n\n // EN: Simulate buyer accepting the offer. // VI: Mô phỏng người mua chấp nhận lời đề nghị. // ES: Simular que el comprador acepta la oferta.\n const acceptMessage: ACPMessage = {\n senderId: buyer.id,\n receiverId: seller.id,\n type: \"accept\",\n content: {\n item: \"laptop\",\n price: 80,\n quantity: 1,\n },\n };\n\n const acceptResponse = await sendMessage(acceptMessage);\n console.log(\"Accept response:\", acceptResponse);\n}\n\n// EN: Export functions and types. // VI: Xuất các hàm và kiểu. // ES: Exportar funciones y tipos.\nexport {\n BuyerAgentSchema,\n SellerAgentSchema,\n MarketplaceAgentSchema,\n ACPMessageSchema,\n type BuyerAgent,\n type SellerAgent,\n type MarketplaceAgent,\n type ACPMessage,\n sendMessage,\n agentChoreography,\n};\n\n// EN: Example Usage (can be removed for production). // VI: Ví dụ sử dụng (có thể được loại bỏ cho sản xuất). // ES: Ejemplo de uso (se puede eliminar para producción).\n// agentChoreography();\n```",
"spec_id": "AI-05"
}Audit Trail (2)
25d agotask_completedVertex Flash
25d agotask_createdfoundry_race
Task ID: dd65267f-a7b3-47b9-8a19-abea8b8e88cc