← Tasks
[AI-05] ACP choreography (Swiss HF)
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
Swiss HF
Created
25d ago
Completed
25d ago
Quality
Overall
71%
Pass
PASS
Graded By
-
Graded At
-
Cost
Input Tokens
168
Output Tokens
1,084
Est. USD
-
Result
{
"code": "```typescript\nimport * as z from 'zod';\nimport { NextResponse } from 'next/server';\n\n// EN: Define Zod schemas for the different types of agents\n// VI: Xác định các lược đồ Zod cho các loại đại lý khác nhau\n// ES: Definir esquemas Zod para los diferentes tipos de agentes\nconst BuyerAgentSchema = z.object({\n id: z.string().uuid(),\n name: z.string(),\n email: z.string().email(),\n budget: z.number().positive(),\n});\n\nconst SellerAgentSchema = z.object({\n id: z.string().uuid(),\n name: z.string(),\n email: z.string().email(),\n products: z.array(z.object({ id: z.string(), name: z.string(), price: z.number().positive() })),\n});\n\nconst MarketplaceAgentSchema = z.object({\n id: z.string().uuid(),\n name: z.string(),\n buyers: z.array(BuyerAgentSchema),\n sellers: z.array(SellerAgentSchema),\n});\n\n// EN: Define the ACP (Agent Communication Protocol) functions\n// VI: Xác định các hàm ACP (Giao thức giao tiếp đại lý)\n// ES: Definir las funciones ACP (Protocolo de comunicación de agentes)\ntype ACPFunction = (agent: BuyerAgent | SellerAgent, message: string) => Promise<NextResponse>;\n\nconst acp: Record<string, ACPFunction> = {\n sendOffer: async (agent: BuyerAgent | SellerAgent, message: string): Promise<NextResponse> => {\n // EN: Simulate sending an offer to another agent\n // VI: Giả lập việc gửi một đề nghị đến đại lý khác\n // ES: Simular el envío de una oferta a otro agente\n return NextResponse.json({ success: true, message: `Offer sent to ${agent.name}` });\n },\n acceptOffer: async (agent: BuyerAgent | SellerAgent, message: string): Promise<NextResponse> => {\n // EN: Simulate accepting an offer from another agent\n // VI: Giả lập việc chấp nhận một đề nghị từ đại lý khác\n // ES: Simular la aceptación de una oferta de otro agente\n return NextResponse.json({ success: true, message: `Offer accepted from ${agent.name}` });\n },\n rejectOffer: async (agent: BuyerAgent | SellerAgent, message: string): Promise<NextResponse> => {\n // EN: Simulate rejecting an offer from another agent\n // VI: Giả lập việc từ chối một đề nghị từ đại lý khác\n // ES: Simular el rechazo de una oferta de otro agente\n return NextResponse.json({ success: true, message: `Offer rejected from ${agent.name}` });\n },\n};\n\n// EN: Define the agent choreography\n// VI: Xác định kịch bản đại lý\n// ES: Definir la coreografía del agente\ninterface AgentChoreography {\n [key: string]: (agent: BuyerAgent | SellerAgent, message: string) => Promise<NextResponse>;\n}\n\nconst agentChoreography: AgentChoreography = {\n sendOffer: acp.sendOffer,\n acceptOffer: acp.acceptOffer,\n rejectOffer: acp.rejectOffer,\n};\n\n// EN: Define the agent types\n// VI: Xác định các loại đại lý\n// ES: Definir los tipos de agentes\ntype BuyerAgent = z.infer<typeof BuyerAgentSchema>;\ntype SellerAgent = z.infer<typeof SellerAgentSchema>;\ntype MarketplaceAgent = z.infer<typeof MarketplaceAgentSchema>;\n\n// EN: Export the necessary components\n// VI: Xuất các thành phần cần thiết\n// ES: Exportar los componentes necesarios\nexport { agentChoreography, acp, BuyerAgent, SellerAgent, MarketplaceAgent };\n\n// EN: Example usage\n// VI: Ví dụ về cách sử dụng\n// ES: Ejemplo de uso\n(async () => {\n const buyer = BuyerAgentSchema.safeParse({\n id: '123e4567-e89b-12d3-a456-426614174000',\n name: 'John Doe',\n email: 'john.doe@example.com',\n budget: 1000,\n });\n\n const seller = SellerAgentSchema.safeParse({\n id: '123e4567-e89b-12d3-a456-426614174001',\n name: 'Jane Smith',\n email: 'jane.smith@example.com',\n products: [\n { id: '1', name: 'Laptop', price: 1200 },\n { id: '2', name: 'Smartphone', price: 800 },\n ],\n });\n\n if (buyer.success && seller.success) {\n const response = await agentChoreography.sendOffer(buyer.data, 'I would like to buy your Laptop.');\n console.log(response.json());\n }\n})();\n```",
"spec_id": "AI-05"
}Audit Trail (2)
25d agotask_completedSwiss HF
25d agotask_createdfoundry_race
Task ID: 03359b15-fbf7-4d84-a519-da5500e81898