analyze_logs
Analyze confirmation history logs to identify patterns in user interactions, success rates, and temporal trends for protocol optimization.
Instructions
Perform statistical analysis on confirmation history logs
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| startDate | No | Start date for analysis (ISO 8601 format) | |
| endDate | No | End date for analysis (ISO 8601 format) | |
| groupBy | No | Group analysis by field | confirmationType |
Implementation Reference
- src/index.ts:1250-1292 (handler)Main handler function for the analyze_logs tool. Parses arguments, reads and filters log entries, computes statistics and grouped analysis, formats the result, and returns it as tool output.private async handleAnalyzeLogs(args: Record<string, unknown>) { try { const startDate = typeof args.startDate === "string" ? args.startDate : undefined; const endDate = typeof args.endDate === "string" ? args.endDate : undefined; const groupBy = typeof args.groupBy === "string" ? args.groupBy : "confirmationType"; const entries = await this.readLogEntries(); const filteredEntries = this.filterByDateRange( entries, startDate, endDate ); const stats = this.calculateBasicStats(filteredEntries); const groupedData = this.groupLogsByField(filteredEntries, groupBy); const groupAnalysis = this.formatGroupAnalysis(groupedData); const analysisText = this.formatAnalysisResult( stats, groupAnalysis, groupBy, startDate, endDate ); return { content: [ { type: "text", text: analysisText, }, ], }; } catch (error) { return this.createErrorResponse( `Log analysis failed: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:464-490 (schema)Tool definition including name, description, and input schema (parameters for date range and grouping).private createAnalyzeLogsTool(): Tool { return { name: "analyze_logs", description: "Perform statistical analysis on confirmation history logs", inputSchema: { type: "object", properties: { startDate: { type: "string", description: "Start date for analysis (ISO 8601 format)", format: "date-time", }, endDate: { type: "string", description: "End date for analysis (ISO 8601 format)", format: "date-time", }, groupBy: { type: "string", description: "Group analysis by field", enum: ["confirmationType", "success", "hour", "day"], default: "confirmationType", }, }, }, }; }
- src/index.ts:231-242 (registration)Registers the analyze_logs tool in the list of available tools by calling createAnalyzeLogsTool().private getToolDefinitions(): Tool[] { return [ this.createAskYesNoTool(), this.createConfirmActionTool(), this.createClarifyIntentTool(), this.createVerifyUnderstandingTool(), this.createCollectRatingTool(), this.createElicitCustomTool(), this.createSearchLogsTool(), this.createAnalyzeLogsTool(), ]; }
- src/index.ts:517-537 (registration)Dispatch registration in executeToolCall switch statement that routes analyze_logs calls to handleAnalyzeLogs.switch (name) { case "ask_yes_no": return await this.handleAskYesNo(args); case "confirm_action": return await this.handleConfirmAction(args); case "clarify_intent": return await this.handleClarifyIntent(args); case "verify_understanding": return await this.handleVerifyUnderstanding(args); case "collect_rating": return await this.handleCollectRating(args); case "elicit_custom": return await this.handleElicitCustom(args); case "search_logs": return await this.handleSearchLogs(args); case "analyze_logs": return await this.handleAnalyzeLogs(args); default: throw new Error(`Unknown tool: ${name}`); } }
- src/index.ts:1383-1418 (helper)Helper function to group log entries by specified field (confirmationType, success, hour, day) for analysis.private groupLogsByField( entries: ConfirmationLogEntry[], field: string ): Record<string, ConfirmationLogEntry[]> { const groups: Record<string, ConfirmationLogEntry[]> = {}; entries.forEach((entry) => { let key: string; switch (field) { case "confirmationType": key = entry.confirmationType; break; case "success": key = entry.success ? "Success" : "Failed"; break; case "hour": key = new Date(entry.timestamp).getHours().toString().padStart(2, "0") + ":00"; break; case "day": key = new Date(entry.timestamp).toISOString().split("T")[0]; break; default: key = "Unknown"; } if (!groups[key]) { groups[key] = []; } groups[key].push(entry); }); return groups; }