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

未关闭
#170 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python

调研方向

首先阅读 chat.register_tool() 的实现和现有的工具注解处理逻辑,然后查看 issue #169 中的相关问题。当可以通过装饰器在工具函数上声明注解,并且 register_tool() 可以在不单独提供注解的情况下使用经过装饰的函数时,此更改即告完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
179
派生
32
平均合并
1 天 3 小时
30 天内合并 PR
10

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

posit-dev/chatlas 的其他 Issue

查看 posit-dev/chatlas 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。