Files
SneakyCode/app/models/tool_call.py
2026-03-11 07:21:21 -05:00

38 lines
1.3 KiB
Python

"""Tool call and result models following OpenAI function-calling spec."""
from enum import StrEnum
from pydantic import BaseModel, Field
class ToolCallFunction(BaseModel):
"""Function details within a tool call."""
name: str = Field(description="Name of the tool function to call")
arguments: str = Field(description="JSON-encoded string of function arguments")
class ToolCall(BaseModel):
"""A single tool call from the LLM, per OpenAI spec."""
id: str = Field(description="Unique identifier for this tool call")
type: str = Field(default="function", description="Type of tool call")
function: ToolCallFunction = Field(description="Function to invoke")
class ToolResultStatus(StrEnum):
"""Status of a tool execution result."""
SUCCESS = "success"
ERROR = "error"
class ToolResult(BaseModel):
"""Result of executing a tool call."""
tool_call_id: str = Field(description="ID of the tool call this result corresponds to")
tool_name: str = Field(description="Name of the tool that was executed")
status: ToolResultStatus = Field(description="Whether the tool execution succeeded or failed")
output: str = Field(default="", description="Tool output on success")
error: str | None = Field(default=None, description="Error message on failure")