Skip to content

tool_call_info

Class info

Classes

Name Children Inherits
ToolCallInfo
llmling_agent.tools.tool_call_info
Information about an executed tool call.

    🛈 DocStrings

    Tool management for LLMling agents.

    ToolCallInfo

    Bases: BaseModel

    Information about an executed tool call.

    Source code in src/llmling_agent/tools/tool_call_info.py
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    class ToolCallInfo(BaseModel):
        """Information about an executed tool call."""
    
        tool_name: str
        """Name of the tool that was called."""
    
        args: dict[str, Any]
        """Arguments passed to the tool."""
    
        result: Any
        """Result returned by the tool."""
    
        agent_name: str
        """Name of the calling agent."""
    
        tool_call_id: str = Field(default_factory=lambda: str(uuid4()))
        """ID provided by the model (e.g. OpenAI function call ID)."""
    
        timestamp: datetime = Field(default_factory=get_now)
        """When the tool was called."""
    
        message_id: str | None = None
        """ID of the message that triggered this tool call."""
    
        context_data: Any | None = None
        """Optional context data that was passed to the agent's run() method."""
    
        error: str | None = None
        """Error message if the tool call failed."""
    
        timing: float | None = None
        """Time taken for this specific tool call in seconds."""
    
        agent_tool_name: str | None = None
        """If this tool is agent-based, the name of that agent."""
    
        model_config = ConfigDict(use_attribute_docstrings=True, extra="forbid")
    
        def format(
            self,
            style: FormatStyle = "simple",
            *,
            template: str | None = None,
            variables: dict[str, Any] | None = None,
            show_timing: bool = True,
            show_ids: bool = False,
        ) -> str:
            """Format tool call information with configurable style.
    
            Args:
                style: Predefined style to use:
                    - simple: Compact single-line format
                    - detailed: Multi-line with all details
                    - markdown: Formatted markdown with syntax highlighting
                template: Optional custom template (required if style="custom")
                variables: Additional variables for template rendering
                show_timing: Whether to include execution timing
                show_ids: Whether to include tool_call_id and message_id
    
            Returns:
                Formatted tool call information
    
            Raises:
                ValueError: If style is invalid or custom template is missing
            """
            from jinjarope import Environment
    
            # Select template
            if template:
                template_str = template
            elif style in TEMPLATES:
                template_str = TEMPLATES[style]
            else:
                msg = f"Invalid style: {style}"
                raise ValueError(msg)
    
            # Prepare template variables
            vars_ = {
                "tool_name": self.tool_name,
                "args": self.args,  # No pre-formatting needed
                "result": self.result,
                "error": self.error,
                "agent_name": self.agent_name,
                "timestamp": self.timestamp,
                "timing": self.timing if show_timing else None,
                "agent_tool_name": self.agent_tool_name,
            }
    
            if show_ids:
                vars_.update({
                    "tool_call_id": self.tool_call_id,
                    "message_id": self.message_id,
                })
    
            if variables:
                vars_.update(variables)
    
            # Render template
            env = Environment(trim_blocks=True, lstrip_blocks=True)
            env.filters["repr"] = repr  # Add repr filter
            template_obj = env.from_string(template_str)
            return template_obj.render(**vars_)
    

    agent_name instance-attribute

    agent_name: str
    

    Name of the calling agent.

    agent_tool_name class-attribute instance-attribute

    agent_tool_name: str | None = None
    

    If this tool is agent-based, the name of that agent.

    args instance-attribute

    args: dict[str, Any]
    

    Arguments passed to the tool.

    context_data class-attribute instance-attribute

    context_data: Any | None = None
    

    Optional context data that was passed to the agent's run() method.

    error class-attribute instance-attribute

    error: str | None = None
    

    Error message if the tool call failed.

    message_id class-attribute instance-attribute

    message_id: str | None = None
    

    ID of the message that triggered this tool call.

    result instance-attribute

    result: Any
    

    Result returned by the tool.

    timestamp class-attribute instance-attribute

    timestamp: datetime = Field(default_factory=get_now)
    

    When the tool was called.

    timing class-attribute instance-attribute

    timing: float | None = None
    

    Time taken for this specific tool call in seconds.

    tool_call_id class-attribute instance-attribute

    tool_call_id: str = Field(default_factory=lambda: str(uuid4()))
    

    ID provided by the model (e.g. OpenAI function call ID).

    tool_name instance-attribute

    tool_name: str
    

    Name of the tool that was called.

    format

    format(
        style: FormatStyle = "simple",
        *,
        template: str | None = None,
        variables: dict[str, Any] | None = None,
        show_timing: bool = True,
        show_ids: bool = False,
    ) -> str
    

    Format tool call information with configurable style.

    Parameters:

    Name Type Description Default
    style FormatStyle

    Predefined style to use: - simple: Compact single-line format - detailed: Multi-line with all details - markdown: Formatted markdown with syntax highlighting

    'simple'
    template str | None

    Optional custom template (required if style="custom")

    None
    variables dict[str, Any] | None

    Additional variables for template rendering

    None
    show_timing bool

    Whether to include execution timing

    True
    show_ids bool

    Whether to include tool_call_id and message_id

    False

    Returns:

    Type Description
    str

    Formatted tool call information

    Raises:

    Type Description
    ValueError

    If style is invalid or custom template is missing

    Source code in src/llmling_agent/tools/tool_call_info.py
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    def format(
        self,
        style: FormatStyle = "simple",
        *,
        template: str | None = None,
        variables: dict[str, Any] | None = None,
        show_timing: bool = True,
        show_ids: bool = False,
    ) -> str:
        """Format tool call information with configurable style.
    
        Args:
            style: Predefined style to use:
                - simple: Compact single-line format
                - detailed: Multi-line with all details
                - markdown: Formatted markdown with syntax highlighting
            template: Optional custom template (required if style="custom")
            variables: Additional variables for template rendering
            show_timing: Whether to include execution timing
            show_ids: Whether to include tool_call_id and message_id
    
        Returns:
            Formatted tool call information
    
        Raises:
            ValueError: If style is invalid or custom template is missing
        """
        from jinjarope import Environment
    
        # Select template
        if template:
            template_str = template
        elif style in TEMPLATES:
            template_str = TEMPLATES[style]
        else:
            msg = f"Invalid style: {style}"
            raise ValueError(msg)
    
        # Prepare template variables
        vars_ = {
            "tool_name": self.tool_name,
            "args": self.args,  # No pre-formatting needed
            "result": self.result,
            "error": self.error,
            "agent_name": self.agent_name,
            "timestamp": self.timestamp,
            "timing": self.timing if show_timing else None,
            "agent_tool_name": self.agent_tool_name,
        }
    
        if show_ids:
            vars_.update({
                "tool_call_id": self.tool_call_id,
                "message_id": self.message_id,
            })
    
        if variables:
            vars_.update(variables)
    
        # Render template
        env = Environment(trim_blocks=True, lstrip_blocks=True)
        env.filters["repr"] = repr  # Add repr filter
        template_obj = env.from_string(template_str)
        return template_obj.render(**vars_)