jx-react-agent 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jx_react_agent-0.1.0/MANIFEST.in +1 -0
- jx_react_agent-0.1.0/PKG-INFO +231 -0
- jx_react_agent-0.1.0/README.md +205 -0
- jx_react_agent-0.1.0/pyproject.toml +45 -0
- jx_react_agent-0.1.0/setup.cfg +4 -0
- jx_react_agent-0.1.0/setup.py +17 -0
- jx_react_agent-0.1.0/src/jx_react_agent.egg-info/PKG-INFO +231 -0
- jx_react_agent-0.1.0/src/jx_react_agent.egg-info/SOURCES.txt +21 -0
- jx_react_agent-0.1.0/src/jx_react_agent.egg-info/dependency_links.txt +1 -0
- jx_react_agent-0.1.0/src/jx_react_agent.egg-info/requires.txt +21 -0
- jx_react_agent-0.1.0/src/jx_react_agent.egg-info/top_level.txt +1 -0
- jx_react_agent-0.1.0/src/jx_react_agent_autoload.pth +1 -0
- jx_react_agent-0.1.0/src/rewardkit_react/__init__.py +13 -0
- jx_react_agent-0.1.0/src/rewardkit_react/agent.py +537 -0
- jx_react_agent-0.1.0/src/rewardkit_react/registry.py +152 -0
- jx_react_agent-0.1.0/src/rewardkit_react/tool.py +86 -0
- jx_react_agent-0.1.0/src/rewardkit_react/tools/__init__.py +14 -0
- jx_react_agent-0.1.0/src/rewardkit_react/tools/documents.py +436 -0
- jx_react_agent-0.1.0/src/rewardkit_react/tools/files.py +325 -0
- jx_react_agent-0.1.0/src/rewardkit_react/tools/shell.py +80 -0
- jx_react_agent-0.1.0/tests/test_agent.py +171 -0
- jx_react_agent-0.1.0/tests/test_plugins.py +30 -0
- jx_react_agent-0.1.0/tests/test_tools.py +66 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include src/jx_react_agent_autoload.pth
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jx-react-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An extensible ReAct judge with native model tool calling.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: harbor-rewardkit==0.2.0
|
|
9
|
+
Provides-Extra: documents
|
|
10
|
+
Requires-Dist: markitdown[docx,pdf,pptx,xls,xlsx]>=0.1; extra == "documents"
|
|
11
|
+
Requires-Dist: openpyxl>=3.1; extra == "documents"
|
|
12
|
+
Requires-Dist: Pillow>=10; extra == "documents"
|
|
13
|
+
Requires-Dist: pymupdf>=1.24; extra == "documents"
|
|
14
|
+
Requires-Dist: python-docx>=1.1; extra == "documents"
|
|
15
|
+
Requires-Dist: python-pptx>=1.0; extra == "documents"
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
18
|
+
Provides-Extra: all
|
|
19
|
+
Requires-Dist: markitdown[docx,pdf,pptx,xls,xlsx]>=0.1; extra == "all"
|
|
20
|
+
Requires-Dist: openpyxl>=3.1; extra == "all"
|
|
21
|
+
Requires-Dist: Pillow>=10; extra == "all"
|
|
22
|
+
Requires-Dist: pymupdf>=1.24; extra == "all"
|
|
23
|
+
Requires-Dist: python-docx>=1.1; extra == "all"
|
|
24
|
+
Requires-Dist: python-pptx>=1.0; extra == "all"
|
|
25
|
+
Requires-Dist: pytest>=8; extra == "all"
|
|
26
|
+
|
|
27
|
+
# JX ReAct Agent
|
|
28
|
+
|
|
29
|
+
一个轻量、可扩展的 ReAct judge。Agent 通过模型原生的 `tools/tool_calls`
|
|
30
|
+
检查工作目录,在收集证据后调用 `submit_score` 提交结构化评分。
|
|
31
|
+
|
|
32
|
+
它自带文本、图片、PDF、Word、PowerPoint 和 Excel 检查工具,也支持按任务加载
|
|
33
|
+
自定义 Python 工具。默认工具均为只读;shell 需要显式开启,不提供编辑工具。
|
|
34
|
+
|
|
35
|
+
模型或内部网关需要支持 Chat Completions 风格的 function tools。本项目不要求模型
|
|
36
|
+
支持 `response_format=json_schema`。
|
|
37
|
+
|
|
38
|
+
## 安装
|
|
39
|
+
|
|
40
|
+
安装包含文档读取能力的版本:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python3 -m pip install 'jx-react-agent[documents]'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
只需要文本工具时可安装核心包:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
python3 -m pip install jx-react-agent
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## RewardKit 集成
|
|
53
|
+
|
|
54
|
+
安装后,常规 `rewardkit` 命令会直接识别 `judge = "react"`。Reward TOML 示例:
|
|
55
|
+
|
|
56
|
+
```toml
|
|
57
|
+
[judge]
|
|
58
|
+
judge = "react"
|
|
59
|
+
model = "openai/doubao-seed-2.1-turbo"
|
|
60
|
+
timeout = 300
|
|
61
|
+
mode = "batched"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
运行方式不变:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
rewardkit "$reward_dir" \
|
|
68
|
+
--workspace "$workspace" \
|
|
69
|
+
--output /logs/verifier/reward.json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
模型由 LiteLLM 调用,`OPENAI_API_KEY`、`OPENAI_BASE_URL` 等标准环境变量继续
|
|
73
|
+
有效。也可以只为本 Agent 设置:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
export REACT_JUDGE_API_KEY=...
|
|
77
|
+
export REACT_JUDGE_API_BASE=...
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
RewardKit 0.2.0 的 agent registry 只存在于当前进程,而且不会自动扫描第三方
|
|
81
|
+
agent entry points。这个 wheel 在 Python 的 site-packages 根目录安装
|
|
82
|
+
`jx_react_agent_autoload.pth`,新进程启动时执行:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import rewardkit_react
|
|
86
|
+
rewardkit_react.install()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
因此配置被解析前,`react` backend 已经注册,无需修改 RewardKit 源码或换用另一条
|
|
90
|
+
命令。`pip` 和 `rewardkit` 必须来自同一个 Python 环境。
|
|
91
|
+
|
|
92
|
+
## 随任务目录上传
|
|
93
|
+
|
|
94
|
+
如果不从 PyPI 安装,可以把整个目录上传后,在评分前运行一次 `entry_point.sh`:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
REWARDKIT_PYTHON="$(command -v python3)"
|
|
98
|
+
REWARDKIT_PYTHON="$REWARDKIT_PYTHON" /tests/react-judge/entry_point.sh
|
|
99
|
+
rewardkit "$reward_dir" --workspace "$workspace"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
bootstrap 会在指定的 Python 环境中构建、安装并验证注册。默认安装 `documents`
|
|
103
|
+
extra;远端镜像已经包含依赖或只检查文本时可关闭:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
REACT_JUDGE_EXTRAS= \
|
|
107
|
+
REWARDKIT_PYTHON="$REWARDKIT_PYTHON" \
|
|
108
|
+
/tests/react-judge/entry_point.sh
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`REACT_JUDGE_CACHE_DIR` 可调整安装缓存目录。源码、Python 解释器或 extras 变化时会
|
|
112
|
+
自动重新安装。
|
|
113
|
+
|
|
114
|
+
## 轨迹日志
|
|
115
|
+
|
|
116
|
+
每次 judge attempt 只保存一个轨迹文件。文件中的 `request` 是最后一轮发给模型的
|
|
117
|
+
完整请求,包含此前累积的 messages、tools 和图片 data URL/base64;`response` 是
|
|
118
|
+
这次请求对应的最终 assistant 响应,包含 `submit_score` tool call 和评分参数;
|
|
119
|
+
`events` 记录模型 tool call、工具 observation 和最终提交。这样可以直接查看完整
|
|
120
|
+
请求及最终答案,又不会重复保存每一轮请求或图片。API key 和 Authorization 凭证
|
|
121
|
+
不会写入文件。
|
|
122
|
+
|
|
123
|
+
默认目录为:
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
/logs/verifier/judge_agents_trajs
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
文件名形如 `trajectory.react.batched-1.<uuid>.json`,路径也会写入 RewardKit 的
|
|
130
|
+
`reward-details.json`。可用环境变量覆盖目录:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
export REACT_JUDGE_LOG_DIR=/custom/judge/trajs
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 内置工具
|
|
137
|
+
|
|
138
|
+
默认暴露以下工具:
|
|
139
|
+
|
|
140
|
+
- `view`:查看两层目录或带行号的文本文件窗口。
|
|
141
|
+
- `list_files`:按指定深度列出文件和大小。
|
|
142
|
+
- `search_files`:在文本文件中搜索并返回文件名、行号和匹配行。
|
|
143
|
+
- `inspect_file`:读取文本、图片、PDF、DOCX、PPTX 和 XLSX。
|
|
144
|
+
- `render_document`:把 PDF 页面转成图片;安装 LibreOffice 后也能渲染
|
|
145
|
+
PPT/PPTX/DOC/DOCX。
|
|
146
|
+
- `submit_score`:根据本次评分 schema 动态生成,用于提交最终结果。
|
|
147
|
+
|
|
148
|
+
图片会作为真正的 `image_url` content block 送入下一轮模型消息。
|
|
149
|
+
|
|
150
|
+
`shell` 已内置但默认关闭。需要运行测试或其他命令时显式开启:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
export REACT_JUDGE_TOOLS=view,list_files,search_files,inspect_file,render_document,shell
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
也可以在默认工具基础上开启:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
export REACT_JUDGE_ENABLE_SHELL=1
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
常用限制:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
export REACT_JUDGE_MAX_STEPS=20
|
|
166
|
+
export REACT_JUDGE_MAX_TOOL_CHARS=40000
|
|
167
|
+
export REACT_JUDGE_MAX_IMAGE_BYTES=8388608
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 自定义工具
|
|
171
|
+
|
|
172
|
+
工具继承公开的 `Tool` 类:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from typing import Any
|
|
176
|
+
|
|
177
|
+
from rewardkit_react.tool import Tool, ToolContext, ToolResult
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class CountFiles(Tool):
|
|
181
|
+
name = "count_files"
|
|
182
|
+
description = "Count files in a workspace directory."
|
|
183
|
+
parameters = {
|
|
184
|
+
"type": "object",
|
|
185
|
+
"properties": {"path": {"type": "string", "default": "."}},
|
|
186
|
+
"additionalProperties": False,
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async def execute(
|
|
190
|
+
self, arguments: dict[str, Any], context: ToolContext
|
|
191
|
+
) -> ToolResult:
|
|
192
|
+
path = context.resolve_workspace_path(arguments.get("path", "."))
|
|
193
|
+
count = sum(child.is_file() for child in path.rglob("*"))
|
|
194
|
+
return ToolResult(text=str(count), metadata={"count": count})
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
TOOLS = [CountFiles()]
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
任务本地工具可以直接从文件加载,无需重新构建主包:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
export REACT_JUDGE_TOOL_MODULES=/tests/tools/count_files.py
|
|
204
|
+
rewardkit /tests/rewards/t1 --workspace /workspace
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
工具模块可以提供 `TOOLS`、`get_tools()` 或 `register_tools(registry)`。多个路径使用
|
|
208
|
+
系统 path separator 或逗号分隔。
|
|
209
|
+
|
|
210
|
+
可复用工具也可以发布为单独的 wheel:
|
|
211
|
+
|
|
212
|
+
```toml
|
|
213
|
+
[project.entry-points."rewardkit_react.tools"]
|
|
214
|
+
count_files = "my_rewardkit_tools:CountFiles"
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Agent 启动时会通过 `importlib.metadata.entry_points()` 自动加载这个分组。
|
|
218
|
+
|
|
219
|
+
## 文档依赖
|
|
220
|
+
|
|
221
|
+
Python extra 可以安装 PyMuPDF、Pillow、python-pptx 等依赖,但无法安装
|
|
222
|
+
LibreOffice。需要把 PPTX/DOCX 渲染成图片时,应在运行环境中安装 LibreOffice。
|
|
223
|
+
只提取文字和结构时,`python-pptx` 与 `python-docx` 已经足够。
|
|
224
|
+
|
|
225
|
+
本地构建和测试:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
python3 -m pytest
|
|
229
|
+
python3 -m build
|
|
230
|
+
python3 -m pip install 'dist/jx_react_agent-0.1.0-py3-none-any.whl[documents]'
|
|
231
|
+
```
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# JX ReAct Agent
|
|
2
|
+
|
|
3
|
+
一个轻量、可扩展的 ReAct judge。Agent 通过模型原生的 `tools/tool_calls`
|
|
4
|
+
检查工作目录,在收集证据后调用 `submit_score` 提交结构化评分。
|
|
5
|
+
|
|
6
|
+
它自带文本、图片、PDF、Word、PowerPoint 和 Excel 检查工具,也支持按任务加载
|
|
7
|
+
自定义 Python 工具。默认工具均为只读;shell 需要显式开启,不提供编辑工具。
|
|
8
|
+
|
|
9
|
+
模型或内部网关需要支持 Chat Completions 风格的 function tools。本项目不要求模型
|
|
10
|
+
支持 `response_format=json_schema`。
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
安装包含文档读取能力的版本:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
python3 -m pip install 'jx-react-agent[documents]'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
只需要文本工具时可安装核心包:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
python3 -m pip install jx-react-agent
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## RewardKit 集成
|
|
27
|
+
|
|
28
|
+
安装后,常规 `rewardkit` 命令会直接识别 `judge = "react"`。Reward TOML 示例:
|
|
29
|
+
|
|
30
|
+
```toml
|
|
31
|
+
[judge]
|
|
32
|
+
judge = "react"
|
|
33
|
+
model = "openai/doubao-seed-2.1-turbo"
|
|
34
|
+
timeout = 300
|
|
35
|
+
mode = "batched"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
运行方式不变:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
rewardkit "$reward_dir" \
|
|
42
|
+
--workspace "$workspace" \
|
|
43
|
+
--output /logs/verifier/reward.json
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
模型由 LiteLLM 调用,`OPENAI_API_KEY`、`OPENAI_BASE_URL` 等标准环境变量继续
|
|
47
|
+
有效。也可以只为本 Agent 设置:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
export REACT_JUDGE_API_KEY=...
|
|
51
|
+
export REACT_JUDGE_API_BASE=...
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
RewardKit 0.2.0 的 agent registry 只存在于当前进程,而且不会自动扫描第三方
|
|
55
|
+
agent entry points。这个 wheel 在 Python 的 site-packages 根目录安装
|
|
56
|
+
`jx_react_agent_autoload.pth`,新进程启动时执行:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import rewardkit_react
|
|
60
|
+
rewardkit_react.install()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
因此配置被解析前,`react` backend 已经注册,无需修改 RewardKit 源码或换用另一条
|
|
64
|
+
命令。`pip` 和 `rewardkit` 必须来自同一个 Python 环境。
|
|
65
|
+
|
|
66
|
+
## 随任务目录上传
|
|
67
|
+
|
|
68
|
+
如果不从 PyPI 安装,可以把整个目录上传后,在评分前运行一次 `entry_point.sh`:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
REWARDKIT_PYTHON="$(command -v python3)"
|
|
72
|
+
REWARDKIT_PYTHON="$REWARDKIT_PYTHON" /tests/react-judge/entry_point.sh
|
|
73
|
+
rewardkit "$reward_dir" --workspace "$workspace"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
bootstrap 会在指定的 Python 环境中构建、安装并验证注册。默认安装 `documents`
|
|
77
|
+
extra;远端镜像已经包含依赖或只检查文本时可关闭:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
REACT_JUDGE_EXTRAS= \
|
|
81
|
+
REWARDKIT_PYTHON="$REWARDKIT_PYTHON" \
|
|
82
|
+
/tests/react-judge/entry_point.sh
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`REACT_JUDGE_CACHE_DIR` 可调整安装缓存目录。源码、Python 解释器或 extras 变化时会
|
|
86
|
+
自动重新安装。
|
|
87
|
+
|
|
88
|
+
## 轨迹日志
|
|
89
|
+
|
|
90
|
+
每次 judge attempt 只保存一个轨迹文件。文件中的 `request` 是最后一轮发给模型的
|
|
91
|
+
完整请求,包含此前累积的 messages、tools 和图片 data URL/base64;`response` 是
|
|
92
|
+
这次请求对应的最终 assistant 响应,包含 `submit_score` tool call 和评分参数;
|
|
93
|
+
`events` 记录模型 tool call、工具 observation 和最终提交。这样可以直接查看完整
|
|
94
|
+
请求及最终答案,又不会重复保存每一轮请求或图片。API key 和 Authorization 凭证
|
|
95
|
+
不会写入文件。
|
|
96
|
+
|
|
97
|
+
默认目录为:
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
/logs/verifier/judge_agents_trajs
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
文件名形如 `trajectory.react.batched-1.<uuid>.json`,路径也会写入 RewardKit 的
|
|
104
|
+
`reward-details.json`。可用环境变量覆盖目录:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export REACT_JUDGE_LOG_DIR=/custom/judge/trajs
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 内置工具
|
|
111
|
+
|
|
112
|
+
默认暴露以下工具:
|
|
113
|
+
|
|
114
|
+
- `view`:查看两层目录或带行号的文本文件窗口。
|
|
115
|
+
- `list_files`:按指定深度列出文件和大小。
|
|
116
|
+
- `search_files`:在文本文件中搜索并返回文件名、行号和匹配行。
|
|
117
|
+
- `inspect_file`:读取文本、图片、PDF、DOCX、PPTX 和 XLSX。
|
|
118
|
+
- `render_document`:把 PDF 页面转成图片;安装 LibreOffice 后也能渲染
|
|
119
|
+
PPT/PPTX/DOC/DOCX。
|
|
120
|
+
- `submit_score`:根据本次评分 schema 动态生成,用于提交最终结果。
|
|
121
|
+
|
|
122
|
+
图片会作为真正的 `image_url` content block 送入下一轮模型消息。
|
|
123
|
+
|
|
124
|
+
`shell` 已内置但默认关闭。需要运行测试或其他命令时显式开启:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
export REACT_JUDGE_TOOLS=view,list_files,search_files,inspect_file,render_document,shell
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
也可以在默认工具基础上开启:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
export REACT_JUDGE_ENABLE_SHELL=1
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
常用限制:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
export REACT_JUDGE_MAX_STEPS=20
|
|
140
|
+
export REACT_JUDGE_MAX_TOOL_CHARS=40000
|
|
141
|
+
export REACT_JUDGE_MAX_IMAGE_BYTES=8388608
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 自定义工具
|
|
145
|
+
|
|
146
|
+
工具继承公开的 `Tool` 类:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from typing import Any
|
|
150
|
+
|
|
151
|
+
from rewardkit_react.tool import Tool, ToolContext, ToolResult
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class CountFiles(Tool):
|
|
155
|
+
name = "count_files"
|
|
156
|
+
description = "Count files in a workspace directory."
|
|
157
|
+
parameters = {
|
|
158
|
+
"type": "object",
|
|
159
|
+
"properties": {"path": {"type": "string", "default": "."}},
|
|
160
|
+
"additionalProperties": False,
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async def execute(
|
|
164
|
+
self, arguments: dict[str, Any], context: ToolContext
|
|
165
|
+
) -> ToolResult:
|
|
166
|
+
path = context.resolve_workspace_path(arguments.get("path", "."))
|
|
167
|
+
count = sum(child.is_file() for child in path.rglob("*"))
|
|
168
|
+
return ToolResult(text=str(count), metadata={"count": count})
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
TOOLS = [CountFiles()]
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
任务本地工具可以直接从文件加载,无需重新构建主包:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
export REACT_JUDGE_TOOL_MODULES=/tests/tools/count_files.py
|
|
178
|
+
rewardkit /tests/rewards/t1 --workspace /workspace
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
工具模块可以提供 `TOOLS`、`get_tools()` 或 `register_tools(registry)`。多个路径使用
|
|
182
|
+
系统 path separator 或逗号分隔。
|
|
183
|
+
|
|
184
|
+
可复用工具也可以发布为单独的 wheel:
|
|
185
|
+
|
|
186
|
+
```toml
|
|
187
|
+
[project.entry-points."rewardkit_react.tools"]
|
|
188
|
+
count_files = "my_rewardkit_tools:CountFiles"
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Agent 启动时会通过 `importlib.metadata.entry_points()` 自动加载这个分组。
|
|
192
|
+
|
|
193
|
+
## 文档依赖
|
|
194
|
+
|
|
195
|
+
Python extra 可以安装 PyMuPDF、Pillow、python-pptx 等依赖,但无法安装
|
|
196
|
+
LibreOffice。需要把 PPTX/DOCX 渲染成图片时,应在运行环境中安装 LibreOffice。
|
|
197
|
+
只提取文字和结构时,`python-pptx` 与 `python-docx` 已经足够。
|
|
198
|
+
|
|
199
|
+
本地构建和测试:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
python3 -m pytest
|
|
203
|
+
python3 -m build
|
|
204
|
+
python3 -m pip install 'dist/jx_react_agent-0.1.0-py3-none-any.whl[documents]'
|
|
205
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "jx-react-agent"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "An extensible ReAct judge with native model tool calling."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"harbor-rewardkit==0.2.0",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[project.optional-dependencies]
|
|
13
|
+
documents = [
|
|
14
|
+
"markitdown[pdf,docx,pptx,xlsx,xls]>=0.1",
|
|
15
|
+
"openpyxl>=3.1",
|
|
16
|
+
"Pillow>=10",
|
|
17
|
+
"pymupdf>=1.24",
|
|
18
|
+
"python-docx>=1.1",
|
|
19
|
+
"python-pptx>=1.0",
|
|
20
|
+
]
|
|
21
|
+
dev = [
|
|
22
|
+
"pytest>=8",
|
|
23
|
+
]
|
|
24
|
+
all = [
|
|
25
|
+
"markitdown[pdf,docx,pptx,xlsx,xls]>=0.1",
|
|
26
|
+
"openpyxl>=3.1",
|
|
27
|
+
"Pillow>=10",
|
|
28
|
+
"pymupdf>=1.24",
|
|
29
|
+
"python-docx>=1.1",
|
|
30
|
+
"python-pptx>=1.0",
|
|
31
|
+
"pytest>=8",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["setuptools>=77", "wheel"]
|
|
36
|
+
build-backend = "setuptools.build_meta"
|
|
37
|
+
|
|
38
|
+
[tool.setuptools]
|
|
39
|
+
include-package-data = true
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
where = ["src"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Build hook that installs the Python startup registration file."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from shutil import copyfile
|
|
5
|
+
|
|
6
|
+
from setuptools import setup
|
|
7
|
+
from setuptools.command.build_py import build_py
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BuildPyWithAutoload(build_py):
|
|
11
|
+
def run(self) -> None:
|
|
12
|
+
super().run()
|
|
13
|
+
source = Path(__file__).parent / "src" / "jx_react_agent_autoload.pth"
|
|
14
|
+
copyfile(source, Path(self.build_lib) / source.name)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
setup(cmdclass={"build_py": BuildPyWithAutoload})
|