# This file was auto-generated by Fern from our API Definition.

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel
from .tool_execution_response_model_tool_call_details import ToolExecutionResponseModelToolCallDetails


class ToolExecutionResponseModel(UncheckedBaseModel):
    tool_id: str = pydantic.Field()
    """
    The ID of the tool that was executed
    """

    tool_request_id: str = pydantic.Field()
    """
    The request/call ID associated with this tool execution
    """

    conversation_id: str = pydantic.Field()
    """
    The ID of the conversation where the tool was executed
    """

    agent_id: str = pydantic.Field()
    """
    The ID of the agent that ran the tool
    """

    branch_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The branch ID if the agent has branches
    """

    timestamp: float = pydantic.Field()
    """
    Unix timestamp when the tool was executed
    """

    latency_secs: float = pydantic.Field()
    """
    How long the tool execution took
    """

    is_error: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether the tool execution failed
    """

    request_payload: typing.Optional[str] = pydantic.Field(default=None)
    """
    LLM-extracted parameters sent to the tool (JSON string)
    """

    response_payload: typing.Optional[str] = pydantic.Field(default=None)
    """
    Response returned by the tool
    """

    error_message: typing.Optional[str] = pydantic.Field(default=None)
    """
    Error message if the tool execution failed
    """

    error_type: typing.Optional[str] = pydantic.Field(default=None)
    """
    Error category (internal, customer_config, customer_auth, external_server, external_client, client_timeout, unknown)
    """

    id: str
    tool_call_details: typing.Optional[ToolExecutionResponseModelToolCallDetails] = None

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
