Skip to main content
Glama

log_tool_execution

Record tool executions to help AI systems learn from user corrections and automatically update configuration files based on detected patterns.

Instructions

Log tool execution for learning

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsYes
resultYes
tool_nameYes

Implementation Reference

  • Main handler function for log_tool_execution tool. Extracts patterns using PatternExtractor and delegates to autologger for logging if significant, returns logging status and detected patterns.
    async def _log_tool_execution(self, tool_name: str, args: Dict[str, Any], result: Any) -> Dict[str, Any]:
        """Log tool execution for learning"""
        try:
            # ALWAYS extract patterns first (regardless of significance)
            # Pattern learning happens even for low-significance events if they contain corrections
            patterns = self.pattern_extractor.extract_patterns(
                tool_name,
                args,
                result,
                project_path=args.get("project_path", "") if isinstance(args, dict) else ""
            )
    
            # Then use autologger for high-significance events
            log_id = self.autologger.log_tool_execution(tool_name, args, result)
    
            if log_id is None:
                # Low significance for logging, but may have detected patterns
                return {
                    "success": True,
                    "skipped_logging": True,
                    "reason": "Low significance for full logging",
                    "patterns_detected": len(patterns),
                    "patterns": [p.get("description", p.get("pattern_key")) for p in patterns] if patterns else []
                }
    
            return {
                "success": True,
                "logged": True,
                "log_id": log_id,
                "patterns_detected": len(patterns),
                "patterns": [p.get("description", p.get("pattern_key")) for p in patterns] if patterns else []
            }
        except Exception as e:
            return {"success": False, "error": str(e)}
  • Registration of the log_tool_execution tool in list_tools(), including name, description, and input schema definition.
    Tool(
        name="log_tool_execution",
        description="Log tool execution for learning",
        inputSchema={
            "type": "object",
            "properties": {
                "tool_name": {"type": "string"},
                "args": {"type": "object"},
                "result": {"type": "object"},
            },
            "required": ["tool_name", "args", "result"],
        },
    ),
  • Input schema for log_tool_execution tool: requires tool_name (str), args (object), result (object).
    inputSchema={
        "type": "object",
        "properties": {
            "tool_name": {"type": "string"},
            "args": {"type": "object"},
            "result": {"type": "object"},
        },
        "required": ["tool_name", "args", "result"],
    },
  • Core helper function in AutoLogger that performs the actual database logging of significant tool executions, including significance check, insertion into tool_logs table, and optional episode extraction.
    def log_tool_execution(
        self, 
        tool_name: str, 
        args: Dict[str, Any], 
        result: Any,
        session_id: Optional[str] = None
    ) -> Optional[int]:
        """Log tool execution if significant"""
        significance = self.should_log(tool_name, args)
        
        if significance < 0.3:  # Skip low significance
            return None
            
        with sqlite3.connect(self.db_path) as conn:
            cursor = conn.execute("""
                INSERT INTO tool_logs (tool_name, args, result, significance, session_id)
                VALUES (?, ?, ?, ?, ?)
            """, (
                tool_name,
                json.dumps(args),
                json.dumps(str(result)[:1000]),  # Truncate large results
                significance,
                session_id or "default"
            ))
            
            log_id = cursor.lastrowid
            
            # Extract episode if highly significant
            if significance > 0.6:
                episode = self._extract_episode(tool_name, args, result)
                if episode:
                    conn.execute("""
                        INSERT INTO episodes (name, content, source, tool_log_id, tags)
                        VALUES (?, ?, ?, ?, ?)
                    """, (
                        episode["name"],
                        episode["content"],
                        episode["source"],
                        log_id,
                        json.dumps(episode.get("tags", []))
                    ))
                    
                    # Update FTS index
                    conn.execute("""
                        INSERT INTO episodes_fts (name, content, tags)
                        VALUES (?, ?, ?)
                    """, (
                        episode["name"],
                        episode["content"],
                        " ".join(episode.get("tags", []))
                    ))
            
            conn.commit()
            return log_id
Behavior1/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Log tool execution for learning' implies a write operation (logging) but doesn't specify whether this is safe, reversible, or has side effects. It lacks details on permissions, rate limits, or what 'learning' entails (e.g., storage, analysis). This is inadequate for a tool with potential mutation implications.

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 description is very concise with a single phrase, 'Log tool execution for learning', which is front-loaded and wastes no words. However, it's arguably too brief, bordering on under-specification, but within the scope of conciseness, it's efficient if not fully informative.

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

Completeness2/5

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

Given the complexity (3 parameters with nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain the tool's role in the learning system, what happens after logging, or how to interpret inputs. For a tool that likely involves data mutation and integration with other learning tools, more context is needed to guide effective use.

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

Parameters2/5

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

Schema description coverage is 0%, so the schema provides no parameter details. The description mentions 'tool execution' which hints at 'tool_name', 'args', and 'result', but doesn't explain their meanings, formats, or constraints. For example, it doesn't clarify what 'args' and 'result' should contain or how they relate to learning. This adds minimal value beyond the parameter names.

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

Purpose2/5

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

The description 'Log tool execution for learning' states a general purpose (logging for learning) but is vague about what specifically gets logged and how it differs from other logging or learning tools. It doesn't clearly distinguish from sibling tools like 'get_learned_preferences' or 'list_recent', which might also involve learning-related operations. The phrase 'tool execution' is somewhat specific but lacks detail about scope or mechanism.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, timing (e.g., after tool use), or exclusions. With siblings like 'get_learned_preferences' and 'list_recent' that might overlap in learning contexts, there's no differentiation, leaving the agent to guess based on names alone.

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/airmcp-com/mcp-standards'

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