#270

Tool parameters lose descriptions from Annotated[...] and docstring Args sections

Openjaygupta17opened 2mo ago

Problem

@ai.tool builds the parameter schema with get_type_hints(fn), which strips Annotated metadata. The most natural typed-tool patterns therefore produce undocumented arguments:

from typing import Annotated
from pydantic import Field

@ai.tool
async def get_weather(
    city: Annotated[str, Field(description="City name")],
    days: Annotated[int, Field(ge=1, le=7, description="Forecast length")] = 3,
) -> str:
    """Get the weather forecast.

    Args:
        city: City to forecast for.
    """
    return "sunny"

Today neither the Field(description=...) nor the Args: entry for city reaches the JSON schema the model sees. Descriptions materially affect tool selection and argument quality, so this hurts most in exactly the multi-tool workspaces the agent loop targets.

Suggested behavior

  • resolve hints with get_type_hints(fn, include_extras=True) so Field metadata survives into model_json_schema() (pydantic already supports this; no new dependency)
  • additionally fill missing property descriptions from a Google-style Args: docstring section, with Field taking precedence
  • schemas for tools that use neither mechanism stay byte-identical

Happy to take this one.

Activity

0

No activity yet.