docs(sdk): custom-tools 'register_tool' example passes a factory function, which raises TypeError

未关闭 适合新手
#1,068 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
文档
描述清晰度
基本清楚
活跃度
活跃
技术栈
documentation, python
领域
documentation

调研方向

从 sdk/guides/custom-tools.mdx 开始,查看“Tool Registration”和“Factory Functions”小节以及 BashAndGrepToolSet 示例。然后检查 openhands-sdk/openhands/sdk/tool/registry.py,确认 register_tool 只接受 ToolDefinition 实例或其子类。同时审查 sdk/guides/agent-server/custom-tools.mdx 和 sdk/arch/tool-system.mdx 中是否存在相同模式。完成的标准是:每个示例都以受支持的形式注册工具,并且文档中不再将工厂函数传递给 register_tool。

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

描述

Problem

sdk/guides/custom-tools.mdx documents registering a factory function with register_tool():

# Register a factory function that creates multiple tools
register_tool("BashAndGrepToolSet", _make_bash_and_grep_tools)

But the current SDK signature only accepts a ToolDefinition instance or a ToolDefinition subclass:

# openhands-sdk/openhands/sdk/tool/registry.py
def register_tool(
    name: str,
    factory: ToolDefinition | type[ToolDefinition],
) -> None:
    ...
    else:
        raise TypeError(
            "register_tool(...) only accepts: (1) a ToolDefinition instance with "
            ".executor, or (2) a ToolDefinition subclass with .create(**params)"
        )

So the documented pattern raises at runtime:

TypeError: register_tool(...) only accepts: (1) a ToolDefinition instance with .executor,
or (2) a ToolDefinition subclass with .create(**params)
Where
  • sdk/guides/custom-tools.mdx — "Good to know → Tool Registration" and "Factory Functions" sections,
    plus the full BashAndGrepToolSet example.
  • Likely also sdk/guides/agent-server/custom-tools.mdx and sdk/arch/tool-system.mdx.
Suggested fix
  • Register each ToolDefinition subclass/instance individually (or loop over a list) instead of passing a
    factory function.
  • If the "tool set" pattern is still desired, show it via TaskToolSet/ToolSet rather than a raw factory.
Reported by

A user (Epsilon Software Inc) hit this following the docs; confirmed against openhands-sdk source.

This issue was created by an AI agent (OpenHands) on behalf of the maintainer.

主要语言
MDX
星标
19
派生
104
平均合并
2 天 12 小时
30 天内合并 PR
80

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

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

OpenHands/docs 的其他 Issue

查看 OpenHands/docs 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

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