chore: fix ruff linting issues in tools module
Some checks failed
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Notify Downstream / notify-downstream (push) Has been cancelled
Update Test Durations / update-durations (3.13) (push) Has been cancelled
Update Test Durations / update-durations (3.10) (push) Has been cancelled
Update Test Durations / update-durations (3.11) (push) Has been cancelled
Update Test Durations / update-durations (3.12) (push) Has been cancelled

linting, args_schema default, and validator check
This commit is contained in:
Greyson LaLonde
2025-09-22 13:13:23 -04:00
committed by GitHub
parent db5f565dea
commit cb0efd05b4
8 changed files with 54 additions and 50 deletions

View File

@@ -1,7 +1,8 @@
import asyncio
from abc import ABC, abstractmethod
from collections.abc import Callable
from inspect import signature
from typing import Any, Callable, Type, get_args, get_origin, Optional, List
from typing import Any, get_args, get_origin
from pydantic import (
BaseModel,
@@ -19,7 +20,7 @@ class EnvVar(BaseModel):
name: str
description: str
required: bool = True
default: Optional[str] = None
default: str | None = None
class BaseTool(BaseModel, ABC):
@@ -32,10 +33,10 @@ class BaseTool(BaseModel, ABC):
"""The unique name of the tool that clearly communicates its purpose."""
description: str
"""Used to tell the model how/when/why to use the tool."""
env_vars: List[EnvVar] = []
env_vars: list[EnvVar] = []
"""List of environment variables used by the tool."""
args_schema: Type[PydanticBaseModel] = Field(
default_factory=_ArgsSchemaPlaceholder, validate_default=True
args_schema: type[PydanticBaseModel] = Field(
default=_ArgsSchemaPlaceholder, validate_default=True
)
"""The schema for the arguments that the tool accepts."""
description_updated: bool = False
@@ -52,9 +53,9 @@ class BaseTool(BaseModel, ABC):
@field_validator("args_schema", mode="before")
@classmethod
def _default_args_schema(
cls, v: Type[PydanticBaseModel]
) -> Type[PydanticBaseModel]:
if not isinstance(v, cls._ArgsSchemaPlaceholder):
cls, v: type[PydanticBaseModel]
) -> type[PydanticBaseModel]:
if v != cls._ArgsSchemaPlaceholder:
return v
return type(
@@ -139,7 +140,7 @@ class BaseTool(BaseModel, ABC):
# Infer args_schema from the function signature if not provided
func_signature = signature(tool.func)
annotations = func_signature.parameters
args_fields = {}
args_fields: dict[str, Any] = {}
for name, param in annotations.items():
if name != "self":
param_annotation = (
@@ -247,7 +248,7 @@ class Tool(BaseTool):
# Infer args_schema from the function signature if not provided
func_signature = signature(tool.func)
annotations = func_signature.parameters
args_fields = {}
args_fields: dict[str, Any] = {}
for name, param in annotations.items():
if name != "self":
param_annotation = (