generate_response
Generate AI-powered responses by integrating DeepSeek's structured reasoning with Claude 3.5 Sonnet’s advanced output creation. Enhances accuracy and context understanding for user prompts.
Instructions
Generate a response using DeepSeek's reasoning and Claude's response generation through OpenRouter.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clearContext | No | Clear conversation history before this request | |
| includeHistory | No | Include Cline conversation history for context | |
| prompt | Yes | The user's input prompt | |
| showReasoning | No | Whether to include reasoning in response |
Implementation Reference
- src/index.ts:307-336 (registration)Registration of the 'generate_response' tool in the ListToolsRequestSchema handler, including name, description, and JSON input schema.{ name: "generate_response", description: "Generate a response using DeepSeek's reasoning and Claude's response generation through OpenRouter.", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "The user's input prompt", }, showReasoning: { type: "boolean", description: "Whether to include reasoning in response", default: false, }, clearContext: { type: "boolean", description: "Clear conversation history before this request", default: false, }, includeHistory: { type: "boolean", description: "Include Cline conversation history for context", default: true, }, }, required: ["prompt"], }, },
- src/index.ts:54-59 (schema)TypeScript interface defining the input arguments for generate_response.interface GenerateResponseArgs { prompt: string; showReasoning?: boolean; clearContext?: boolean; includeHistory?: boolean; }
- src/index.ts:98-106 (helper)Type guard/validator function for GenerateResponseArgs used in the handler.const isValidGenerateResponseArgs = (args: any): args is GenerateResponseArgs => typeof args === "object" && args !== null && typeof args.prompt === "string" && (args.showReasoning === undefined || typeof args.showReasoning === "boolean") && (args.clearContext === undefined || typeof args.clearContext === "boolean") && (args.includeHistory === undefined || typeof args.includeHistory === "boolean");
- src/index.ts:355-401 (handler)Entry point handler for generate_response tool call: validates arguments, initializes asynchronous task status, starts background processing via processTask, and returns taskId immediately for polling.if (request.params.name === "generate_response") { if (!isValidGenerateResponseArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, "Invalid generate_response arguments" ); } const taskId = uuidv4(); const { prompt, showReasoning, clearContext, includeHistory } = request.params.arguments; // Initialize task status with les propriétés de suivi pour le polling this.activeTasks.set(taskId, { status: "pending", prompt, showReasoning, timestamp: Date.now(), lastChecked: Date.now(), nextCheckDelay: INITIAL_STATUS_CHECK_DELAY_MS, checkAttempts: 0 }); // Start processing in background this.processTask(taskId, clearContext, includeHistory).catch( (error) => { log("Error processing task:", error); this.activeTasks.set(taskId, { ...this.activeTasks.get(taskId)!, status: "error", error: error.message, }); } ); // Return task ID immediately return { content: [ { type: "text", text: JSON.stringify({ taskId, suggestedWaitTime: Math.round(INITIAL_STATUS_CHECK_DELAY_MS / 1000) // Temps suggéré en secondes }), }, ], };
- src/index.ts:511-590 (handler)Core asynchronous processor for generate_response: fetches conversation history, generates reasoning with DeepSeek, generates final response with DeepSeek, updates task status throughout, and adds to conversation context.private async processTask( taskId: string, clearContext?: boolean, includeHistory?: boolean ): Promise<void> { const task = this.activeTasks.get(taskId); if (!task) { throw new Error(`No task found with ID: ${taskId}`); } try { if (clearContext) { this.context.entries = []; } // Update status to reasoning this.activeTasks.set(taskId, { ...task, status: "reasoning", }); // Get Cline conversation history if requested let history: ClaudeMessage[] | null = null; if (includeHistory !== false) { history = await findActiveConversation(); } // Get DeepSeek reasoning with limited history const reasoningHistory = history ? formatHistoryForModel(history, true) : ""; const reasoningPrompt = reasoningHistory ? `${reasoningHistory}\n\nNew question: ${task.prompt}` : task.prompt; const reasoning = await this.getDeepseekReasoning(reasoningPrompt); // Update status with reasoning this.activeTasks.set(taskId, { ...task, status: "responding", reasoning, }); // Get final response with full history const responseHistory = history ? formatHistoryForModel(history, false) : ""; const fullPrompt = responseHistory ? `${responseHistory}\n\nCurrent task: ${task.prompt}` : task.prompt; const response = await this.getFinalResponse(fullPrompt, reasoning); // Add to context after successful response this.addToContext({ timestamp: Date.now(), prompt: task.prompt, reasoning, response, model: DEEPSEEK_MODEL, // Utiliser DEEPSEEK_MODEL au lieu de CLAUDE_MODEL }); // Update status to complete this.activeTasks.set(taskId, { ...task, status: "complete", reasoning, response, timestamp: Date.now(), }); } catch (error) { // Update status to error this.activeTasks.set(taskId, { ...task, status: "error", error: error instanceof Error ? error.message : "Unknown error", timestamp: Date.now(), }); throw error; } }