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

Aperta
#170 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia leggendo l’implementazione di chat.register_tool() e la gestione esistente delle annotazioni degli strumenti, quindi esamina le problematiche correlate nell’issue #169. La modifica è completa quando le annotazioni possono essere dichiarate sulla funzione dello strumento con un decoratore e register_tool() può usare la funzione decorata senza annotazioni fornite separatamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
179
Fork
32
Merge medio
1g 3h
PR unite (30g)
10

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di posit-dev/chatlas

Tutte le issue di posit-dev/chatlas

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.