Skip to main content
Glama

aida_log_deviation

Log AI output deviations from user expectations to analyze root causes and improve code generation accuracy through pattern codification.

Instructions

当 AI 产出与用户预期不符时调用。记录偏差用于后续分析。当 rootCause 为 rule-missing 时,修复后如果属于项目级技术规范(非业务逻辑),应询问用户是否沉淀为规则。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYes偏差描述
rootCauseNo根因分类
categoryNo偏差类别

Implementation Reference

  • The handler function `handleLogDeviation` which implements the logic for the `aida_log_deviation` tool.
    function handleLogDeviation(args: any): any {
      const rootCause = args.rootCause || 'other';
      const category = args.category || 'other';
      const { path, data } = ensureRunJson();
      const id = nextId(data.deviations, 'DEV');
      const deviation: DeviationItem = {
        deviationId: id,
        title: args.title,
        rootCauseCategory: rootCause as DeviationItem['rootCauseCategory'],
        deviationCategory: category as DeviationItem['deviationCategory'],
        aiOutput: '',
        expectedOutput: '',
        files: [],
        ruleSedimented: null,
        detectedAt: now(),
        fixedAt: null,
      };
      data.deviations.push(deviation);
      data.summary.deviationCount = data.deviations.length;
      addEvent(data, 'deviation_created', { deviationId: id });
      addTimeline(data, 'deviation', `${id}: ${args.title}`);
      save(path, data);
    
      const result: any = { success: true, deviationId: id, message: `${id} 已记录: ${args.title}` };
    
      // When rootCause is rule-missing, check for pattern and hint rule sedimentation
      if (rootCause === 'rule-missing') {
        const sameCategoryCount = data.deviations.filter(
          d => d.deviationCategory === category && d.rootCauseCategory === 'rule-missing',
        ).length;
    
        if (sameCategoryCount >= 2) {
          result.ruleHint = `同类偏差已出现 ${sameCategoryCount} 次(${category} / rule-missing)。如果修复方案属于项目级技术规范(非业务逻辑),请询问用户是否沉淀为规则:调用 aida_log_rule 工具,传入 content="<规则描述>" category="${category}" sourceDeviation="${id}"`;
        } else {
          result.ruleHint = `rootCause 为 rule-missing,修复后如果属于项目级技术规范(非业务逻辑),请询问用户是否沉淀为规则:调用 aida_log_rule 工具,传入 content="<规则描述>" category="${category}" sourceDeviation="${id}"`;
        }
      }
    
      return result;
    }
  • Tool registration for `aida_log_deviation` in the `TOOLS` array.
      name: 'aida_log_deviation',
      description: '当 AI 产出与用户预期不符时调用。记录偏差用于后续分析。当 rootCause 为 rule-missing 时,修复后如果属于项目级技术规范(非业务逻辑),应询问用户是否沉淀为规则。',
      inputSchema: {
        type: 'object',
        properties: {
          title: { type: 'string', description: '偏差描述' },
          rootCause: { type: 'string', enum: [...ROOT_CAUSE_VALUES], description: '根因分类' },
          category: { type: 'string', enum: [...DEVIATION_CAT_VALUES], description: '偏差类别' },
        },
        required: ['title'],
      },
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full disclosure burden. It mentions the persistence aspect ('记录') and a specific behavioral side effect ('应询问用户是否沉淀为规则'), which adds context. However, it omits other behavioral traits like return values, idempotency, or failure modes that agents need for mutation/logging tools.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The three-sentence structure is efficient and front-loaded: trigger condition first, purpose second, and conditional workflow third. Each sentence earns its place. The Chinese phrasing is professional and compact, though a slightly more structured format (e.g., bullet points for the conditional logic) could improve scanning.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a logging tool with no output schema, the description adequately covers the logging intent, categorization parameters, and the specific rule-missing workflow. However, it lacks information about return confirmation, error handling, or how logged deviations are subsequently accessed (e.g., via aida_log_review or similar), which would complete the usage context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the baseline is 3. The description adds valuable semantic context for 'rootCause' by explaining the specific workflow when this value is 'rule-missing', helping agents understand how to populate this enum. It does not add significant details for 'title' or 'category' beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the trigger condition ('当 AI 产出与用户预期不符时调用'), the action ('记录偏差'), and the purpose ('用于后续分析'). It partially distinguishes from siblings by specifying the deviation scenario and referencing the rule precipitation workflow (connecting to aida_log_rule), though it could explicitly contrast with aida_log_bug.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides specific guidance for the 'rootCause' enum value ('当 rootCause 为 rule-missing 时...') and a follow-up workflow, but lacks explicit 'when-not-to-use' guidance or clear distinction from sibling logging tools like aida_log_bug. The alternative action (asking about rule creation) is described rather than alternative tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LWTlong/ai-dev-analytics'

If you have feedback or need assistance with the MCP directory API, please join our Discord server