posit-dev / posit-dev/chatlas

Set tool annotations by decorating the tool function, not in `chat.register_tool()`

Open
#170 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
176
Forks
28
Avg merge
18h 42m
Merged PRs (30d)
16

Description

Tool annotations should be attached to the tool definition as closely as possible. It's currently awkward to create to a tool function that has annotations because those annotations need to be passed to chat.register_tool() at registration, which might be in a different place than where the tool is defined. (The tool could be in packaged code and the registration in user code.)

Instead of this

import faicons
from chatlas import ChatOpenAI


def get_weather_forecast(
    lat: float, lon: float, location_name: str
) -> ContentToolResult:
    """Get the weather forecast for a location."""
    # Mocked weather data for demonstration purposes
    return {"temperature_2m": 18, "condition": "Partly Cloudy"}


# Create chat client and register tool
chat_client = ChatOpenAI(model="gpt-4.1-nano")
chat_client.register_tool(
    get_weather_forecast,
    annotations={  # << THIS COULD HAPPEN FAR FROM TOOL DEL
        "title": "Weather Forecast",
        "icon": faicons.icon_svg("cloud"),
    },
)

Maybe this

import faicons
from chatlas import ChatOpenAI, add_tool_annotations

@add_tool_annotations(
  title="Weather Forecast",
  icon=faicons.icon_svg("cloud")
)
def get_weather_forecast(
    lat: float, lon: float, location_name: str
) -> ContentToolResult:
    """Get the weather forecast for a location."""
    # Mocked weather data for demonstration purposes
    return {"temperature_2m": 18, "condition": "Partly Cloudy"}


# Create chat client and register tool
chat_client = ChatOpenAI(model="gpt-4.1-nano")
chat_client.register_tool(get_weather_forecast)

Advantages

This would also resolve some of the underlying issue in #169 where known standard MCP Tool Annotation properties could be named arguments that are documented, but additional kwargs are just added as tool annotations.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the implementation of chat.register_tool() and the existing tool annotation handling, then review the related concerns in issue #169. The change is complete when annotations can be declared on the tool function with a decorator and register_tool() can use the decorated function without separately supplied annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.