import { z } from "zod"; import { defineTool } from "@mariozechner/lemmy"; import type { LemmyTool } from "../types.js"; /** * Task/Agent tool for launching sub-agents * Note: This is a placeholder implementation. In a real system, this would * integrate with an agent framework or spawn actual sub-agents. */ export const taskTool: LemmyTool = defineTool({ name: "Task", description: `Launch a new agent that has access to the following tools: Bash, Glob, Grep, LS, Read, Edit, MultiEdit, Write, NotebookRead, NotebookEdit, WebFetch, TodoRead, TodoWrite, WebSearch, mcp__ide__getDiagnostics, mcp__ide__executeCode, mcp__snap-happy__GetLastScreenshot, mcp__snap-happy__TakeScreenshot, mcp__snap-happy__ListWindows. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries, use the Agent tool to perform the search for you. When to use the Agent tool: - If you are searching for a keyword like "config" or "logger", or for questions like "which file does X?", the Agent tool is strongly recommended When NOT to use the Agent tool: - If you want to read a specific file path, use the Read or Glob tool instead of the Agent tool, to find the match more quickly - If you are searching for a specific class definition like "class Foo", use the Glob tool instead, to find the match more quickly - If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead of the Agent tool, to find the match more quickly Usage notes: 1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses 2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result. 3. Each agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you. 4. The agent's outputs should generally be trusted 5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent`, category: "productivity", schema: z.object({ description: z.string().describe("A short (3-5 word) description of the task"), prompt: z.string().describe("The task for the agent to perform"), }), execute: async (args, signal) => { const { description, prompt } = args; if (signal?.aborted) { throw new Error("Task execution was cancelled"); } // This is a placeholder implementation // In a real system, this would: // 1. Spawn a new agent instance // 2. Provide it with the specified tools // 3. Execute the prompt // 4. Return the agent's response // For now, we'll simulate this process const startTime = Date.now(); // Simulate agent processing time await new Promise((resolve) => setTimeout(resolve, 1000)); if (signal?.aborted) { throw new Error("Task execution was cancelled"); } // Mock response based on the task description let mockResponse = ""; if (prompt.toLowerCase().includes("search") || prompt.toLowerCase().includes("find")) { mockResponse = `Agent completed search task: "${description}" The agent performed the requested search operation. In a real implementation, this would: - Use Glob and Grep tools to search for files and content - Analyze the results and provide structured findings - Return specific file paths, line numbers, and relevant context Task prompt: ${prompt.slice(0, 200)}${prompt.length > 200 ? "..." : ""} Note: This is a placeholder response. The actual implementation would spawn a real agent with access to all specified tools.`; } else if (prompt.toLowerCase().includes("read") || prompt.toLowerCase().includes("analyze")) { mockResponse = `Agent completed analysis task: "${description}" The agent performed the requested analysis. In a real implementation, this would: - Read the specified files using the Read tool - Analyze the content according to the prompt - Provide structured insights and findings - Include relevant code snippets or data Task prompt: ${prompt.slice(0, 200)}${prompt.length > 200 ? "..." : ""} Note: This is a placeholder response. The actual implementation would execute the analysis using real tools.`; } else if (prompt.toLowerCase().includes("write") || prompt.toLowerCase().includes("create")) { mockResponse = `Agent completed creation task: "${description}" The agent performed the requested creation task. In a real implementation, this would: - Use Write and Edit tools to create or modify files - Follow best practices and coding standards - Ensure the created content meets the requirements - Report on what was created or modified Task prompt: ${prompt.slice(0, 200)}${prompt.length > 200 ? "..." : ""} Note: This is a placeholder response. The actual implementation would perform real file operations.`; } else { mockResponse = `Agent completed task: "${description}" The agent processed the request and would normally: - Use appropriate tools based on the task requirements - Perform the requested operations autonomously - Return structured results and findings - Provide actionable information Task prompt: ${prompt.slice(0, 200)}${prompt.length > 200 ? "..." : ""} Note: This is a placeholder response. The actual implementation would execute the task using real agent capabilities.`; } const endTime = Date.now(); return { task_id: `task_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, description, prompt, status: "completed", execution_time: endTime - startTime, agent_response: mockResponse, tools_available: [ "Bash", "Glob", "Grep", "LS", "Read", "Edit", "MultiEdit", "Write", "NotebookRead", "NotebookEdit", "WebFetch", "TodoRead", "TodoWrite", "WebSearch", "mcp__ide__getDiagnostics", "mcp__ide__executeCode", "mcp__snap-happy__GetLastScreenshot", "mcp__snap-happy__TakeScreenshot", "mcp__snap-happy__ListWindows", ], note: "This is a placeholder implementation. In a real system, this would spawn an actual agent with access to all specified tools and execute the task autonomously.", }; }, }) as LemmyTool;