@auipage/agent 0.1.0-alpha.0 → 0.1.0-alpha.2
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.
- package/CHANGELOG +1 -1
- package/README.md +79 -59
- package/package.json +9 -3
- package/src/callFuns.js +1 -1
- package/src/createTool.js +60 -0
- package/src/index.js +7 -8
- package/src/runConversation.js +4 -7
- package/types/agent.d.ts +47 -0
- package/types/create-tool.d.ts +38 -0
- package/types/index.d.ts +20 -0
- package/types/tool.d.ts +15 -0
package/CHANGELOG
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# [@auipage/agent](https://github.com/handless-ui/auipage/packages/agent/README.md)
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
智能体对话循环:在 `@auipage/model` 之上处理多轮工具调用(模型要调工具 → 执行 → 结果回灌模型 → 继续生成),并提供 `CreateTool` 把服务端工具调用桥接到浏览器页面执行。
|
|
3
4
|
|
|
4
5
|
<p>
|
|
5
6
|
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=@auipage/agent&interval=7">
|
|
@@ -15,48 +16,43 @@
|
|
|
15
16
|
|
|
16
17
|
<img src="https://nodei.co/npm/@auipage/agent.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
17
18
|
|
|
18
|
-
##
|
|
19
|
+
## 安装
|
|
19
20
|
|
|
20
21
|
```
|
|
21
22
|
npm install --save @auipage/agent
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### 快速上手
|
|
27
|
-
|
|
28
|
-
`@auipage/agent` 暴露一个 `Agent` 构造器。实例化时需要传入一个 `Model` 配置和可选的工具列表,然后调用 `generate(text)` 即可让模型基于系统提示与用户输入返回最终文本。
|
|
25
|
+
## 基本用法
|
|
29
26
|
|
|
30
27
|
```javascript
|
|
31
28
|
import { Agent } from "@auipage/agent";
|
|
32
29
|
|
|
33
30
|
const agent = new Agent({
|
|
34
31
|
model: {
|
|
35
|
-
model: "gpt-4o-mini",
|
|
36
|
-
apiKey: "your-api-key",
|
|
37
|
-
baseURL: "https://api.openai.com/v1"
|
|
32
|
+
model: "gpt-4o-mini",
|
|
33
|
+
apiKey: "your-api-key",
|
|
34
|
+
baseURL: "https://api.openai.com/v1"
|
|
38
35
|
},
|
|
39
36
|
systemPrompt: "你是一个简洁、乐于助人的助手。"
|
|
40
37
|
});
|
|
41
38
|
|
|
42
|
-
const answer = await agent.generate(
|
|
43
|
-
|
|
39
|
+
const answer = await agent.generate([
|
|
40
|
+
{ role: "user", content: "用一句话介绍 JavaScript" }
|
|
41
|
+
]);
|
|
44
42
|
```
|
|
45
43
|
|
|
46
|
-
`generate(
|
|
47
|
-
|
|
48
|
-
### 注册工具(Tool Calling)
|
|
44
|
+
`generate(messages, logback?, thinkback?)`:
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
- `messages` 为消息数组;构造时配置了非空 `systemPrompt` 才会插到队首作为 `system` 消息(会原地修改传入的数组)。
|
|
47
|
+
- `logback(delta)`:流式正文增量回调。
|
|
48
|
+
- `thinkback(reasoning)`:推理过程增量回调。
|
|
49
|
+
- 返回 `Promise<string | undefined>`;模型整轮只产出工具调用、没有正文时为 `undefined`。
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
## 注册工具
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
- `valueOf(args)`:工具真正执行的函数,参数 `args` 是模型解析后的对象,返回值可以是任意可序列化值,也可以是 `Promise`。
|
|
53
|
+
工具是 `{ description, execute }` 对象:`description` 遵循模型的 tools 描述规范,`execute(args)` 在服务端执行,可同步可返回 `Promise`,模型返回的参数会解析后传入。
|
|
56
54
|
|
|
57
55
|
```javascript
|
|
58
|
-
import { Agent } from "@auipage/agent";
|
|
59
|
-
|
|
60
56
|
const getWeather = {
|
|
61
57
|
description: {
|
|
62
58
|
type: "function",
|
|
@@ -72,63 +68,87 @@ const getWeather = {
|
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
70
|
},
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
return `${city} 今天晴,气温 25°C`;
|
|
71
|
+
execute({ city }) {
|
|
72
|
+
return `${city} 今天晴,25°C`; // 也可以 return fetch(...).then(...)
|
|
78
73
|
}
|
|
79
74
|
};
|
|
80
75
|
|
|
81
76
|
const agent = new Agent({
|
|
82
|
-
model: {
|
|
83
|
-
|
|
84
|
-
apiKey: "your-api-key",
|
|
85
|
-
baseURL: "https://api.openai.com/v1"
|
|
86
|
-
},
|
|
87
|
-
systemPrompt: "你可以使用 getWeather 工具查询天气。",
|
|
77
|
+
model: { /* 同上 */ },
|
|
78
|
+
systemPrompt: "你可以使用 getWeather 查询天气。",
|
|
88
79
|
tools: [getWeather]
|
|
89
80
|
});
|
|
90
81
|
|
|
91
|
-
const answer = await agent.generate(
|
|
92
|
-
|
|
82
|
+
const answer = await agent.generate([
|
|
83
|
+
{ role: "user", content: "南京今天天气怎么样?" }
|
|
84
|
+
]);
|
|
93
85
|
```
|
|
94
86
|
|
|
95
|
-
`
|
|
87
|
+
模型决定调用工具时,Agent 按名找到工具执行,把结果作为 `tool` 消息回灌模型继续生成,直到拿到最终回复。
|
|
88
|
+
|
|
89
|
+
## 前后端工具桥接(CreateTool)
|
|
90
|
+
|
|
91
|
+
Agent 跑在服务端、部分工具需要浏览器执行时,用 `CreateTool` 包装。它接收一个有 `send(data)` 方法的消息流(如 `@auipage/core` 的 `MessageStream`),在工具执行节点把事件推给页面,并支持页面把结果回传唤醒挂起的调用。
|
|
96
92
|
|
|
97
93
|
```javascript
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
94
|
+
import { Agent, CreateTool } from "@auipage/agent";
|
|
95
|
+
import { MessageStream } from "@auipage/core";
|
|
96
|
+
|
|
97
|
+
const ms = new MessageStream(
|
|
98
|
+
data => res.write("data: " + JSON.stringify(data) + "\n\n"),
|
|
99
|
+
() => res.end()
|
|
100
|
+
);
|
|
101
|
+
const ct = new CreateTool(ms);
|
|
102
|
+
|
|
103
|
+
const agent = new Agent({
|
|
104
|
+
model: { /* 同上 */ },
|
|
105
|
+
tools: [
|
|
106
|
+
// 后端工具:带 execute,在服务端执行
|
|
107
|
+
ct.create({
|
|
108
|
+
description: { /* ... name: "readPlain" */ },
|
|
109
|
+
execute({ filepath }) {
|
|
110
|
+
return readFile(filepath);
|
|
110
111
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
}),
|
|
113
|
+
// 前端工具:不带 execute,调用挂起,等页面回传结果
|
|
114
|
+
ct.create({
|
|
115
|
+
description: { /* ... name: "showPlain" */ }
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
});
|
|
117
119
|
```
|
|
118
120
|
|
|
119
|
-
|
|
121
|
+
`ct.create(tool)` 返回标准的 `{ description, execute }`,按是否传 `execute` 分两类:
|
|
122
|
+
|
|
123
|
+
- **后端工具**(`caller: "backend"`):执行前推 `pending`,结束后在同一事件上补 `success` / `error` 和 `result`。
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
{ type: "tool-call", status: "pending", id, name, caller: "backend", args }
|
|
127
|
+
{ type: "tool-call", status: "success", id, name, caller: "backend", args, result }
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- **前端工具**(`caller: "frontend"`):只推 `pending`,本次调用返回一个 Promise 挂起。页面处理完后把 `{ id, result }` 发回服务端,由服务端调用 `globalThis[id](result)` 唤醒,对话才继续:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
if (globalThis[data.id]) {
|
|
134
|
+
globalThis[data.id](data.result);
|
|
135
|
+
delete globalThis[data.id];
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
不走 `CreateTool` 时请直接传带 `execute` 的普通工具;没有 `execute` 的工具只在桥接场景下合法,否则执行会报错。
|
|
140
|
+
|
|
141
|
+
## 配置
|
|
120
142
|
|
|
121
143
|
| 字段 | 类型 | 必填 | 说明 |
|
|
122
144
|
| --- | --- | --- | --- |
|
|
123
|
-
| `model` | `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `systemPrompt` | `string` | 否 | 系统提示词,会作为首条 `system` 消息发送给模型 |
|
|
128
|
-
| `tools` | `Tool[]` | 否 | 工具列表,每项需提供 `description` 和 `valueOf` |
|
|
145
|
+
| `model` | `{ model, apiKey, baseURL }` | 是 | 透传给 `@auipage/model` |
|
|
146
|
+
| `systemPrompt` | `string` | 否 | 系统提示词,默认空字符串 |
|
|
147
|
+
| `stream` | `boolean` | 否 | 默认 `false` |
|
|
148
|
+
| `tools` | `AgentTool[]` | 否 | 工具列表,默认 `[]`;直接给 Agent 的工具必须带 `execute`,省略 `execute` 只在 `CreateTool` 桥接场景合法 |
|
|
129
149
|
|
|
130
150
|
## 版权
|
|
131
151
|
|
|
132
152
|
MIT License
|
|
133
153
|
|
|
134
|
-
Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
|
|
154
|
+
Copyright (c) [zxl20070701](https://zxl20070701.github.io/notebook/home.html) 走一步,再走一步
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auipage/agent",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "@auipage/agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"url": "git+https://github.com/handless-ui/auipage.git",
|
|
16
16
|
"directory": "packages/agent"
|
|
17
17
|
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"ui",
|
|
20
|
+
"page",
|
|
21
|
+
"agent"
|
|
22
|
+
],
|
|
18
23
|
"author": {
|
|
19
24
|
"name": "zxl20070701",
|
|
20
25
|
"url": "https://zxl20070701.github.io/notebook/home.html"
|
|
@@ -25,7 +30,8 @@
|
|
|
25
30
|
},
|
|
26
31
|
"homepage": "https://github.com/handless-ui/auipage#readme",
|
|
27
32
|
"dependencies": {
|
|
28
|
-
"@auipage/
|
|
29
|
-
"@auipage/
|
|
33
|
+
"@auipage/model": "^0.1.0-alpha.2",
|
|
34
|
+
"@auipage/types": "^0.1.0-alpha.2",
|
|
35
|
+
"oipage": "^2.1.0"
|
|
30
36
|
}
|
|
31
37
|
}
|
package/src/callFuns.js
CHANGED
|
@@ -19,7 +19,7 @@ export default function callFuns(_this, tool_calls) {
|
|
|
19
19
|
|
|
20
20
|
let result;
|
|
21
21
|
try {
|
|
22
|
-
result = tool.
|
|
22
|
+
result = tool.execute(JSON.parse(call.function.arguments));
|
|
23
23
|
} catch (e) {
|
|
24
24
|
return Promise.resolve("参数解析失败:" + e);
|
|
25
25
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { initOption } from "oipage/web/option/index.js";
|
|
2
|
+
|
|
3
|
+
function CreateTool(ms) {
|
|
4
|
+
this.ms = ms;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
CreateTool.prototype.create = function ({ description, execute }) {
|
|
8
|
+
let _this = this;
|
|
9
|
+
return {
|
|
10
|
+
description,
|
|
11
|
+
execute: async function (args) {
|
|
12
|
+
let toolInfo = {
|
|
13
|
+
type: "tool-call",
|
|
14
|
+
status: "pending",
|
|
15
|
+
id: Date.now().toString()+"_"+Math.random().toString(36).substring(2).toUpperCase(),
|
|
16
|
+
name: description.function.name,
|
|
17
|
+
caller: execute ? "backend" : "frontend",
|
|
18
|
+
args
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// 后端工具调用
|
|
22
|
+
if (execute) {
|
|
23
|
+
_this.ms.send(toolInfo); // 开始调用工具
|
|
24
|
+
|
|
25
|
+
let result, status;
|
|
26
|
+
try {
|
|
27
|
+
result = await execute(args);
|
|
28
|
+
status = "success"; // 调用成功
|
|
29
|
+
} catch (error) {
|
|
30
|
+
result = error;
|
|
31
|
+
status = "error"; // 调用失败
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_this.ms.send(initOption({ // 结束调用工具
|
|
35
|
+
status,
|
|
36
|
+
result
|
|
37
|
+
}, toolInfo));
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 前端工具调用
|
|
43
|
+
else {
|
|
44
|
+
let _resolve = null;
|
|
45
|
+
globalThis[toolInfo.id] = function (result) {
|
|
46
|
+
_resolve(result);
|
|
47
|
+
delete globalThis[toolInfo.id];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
_this.ms.send(toolInfo); // 开始调用工具
|
|
51
|
+
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
_resolve = resolve;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default CreateTool;
|
package/src/index.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { Model } from "@auipage/model";
|
|
2
2
|
import runConversation from "./runConversation.js";
|
|
3
|
+
import CreateTool from "./createTool.js";
|
|
3
4
|
|
|
4
5
|
function Agent(option) {
|
|
5
6
|
this.model = new Model(option.model);
|
|
6
7
|
this.tools = option.tools || [];
|
|
7
8
|
this.systemPrompt = option.systemPrompt || "";
|
|
9
|
+
this.stream = option.stream || false;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
Agent.prototype.generate = function (
|
|
11
|
-
|
|
12
|
+
Agent.prototype.generate = function (messages, logback, thinkback) {
|
|
13
|
+
if (this.systemPrompt) messages.unshift({
|
|
12
14
|
role: "system",
|
|
13
15
|
content: this.systemPrompt
|
|
14
|
-
}
|
|
15
|
-
role: "user",
|
|
16
|
-
content: text
|
|
17
|
-
}];
|
|
16
|
+
});
|
|
18
17
|
|
|
19
|
-
return runConversation(this, messages);
|
|
18
|
+
return runConversation(this, messages, logback, thinkback);
|
|
20
19
|
};
|
|
21
20
|
|
|
22
|
-
export { Agent };
|
|
21
|
+
export { Agent, CreateTool };
|
package/src/runConversation.js
CHANGED
|
@@ -31,19 +31,15 @@ function appendAssistantMessage(messages, result) {
|
|
|
31
31
|
* 1. 调用模型获取响应
|
|
32
32
|
* 2. 若返回工具调用,依次执行工具并将结果追加到 messages,继续循环
|
|
33
33
|
* 3. 否则将最终内容 resolve 给调用方
|
|
34
|
-
*
|
|
35
|
-
* @param {Object} _this Agent 实例
|
|
36
|
-
* @param {Array} messages 当前对话消息列表(会被原地修改)
|
|
37
|
-
* @returns {Promise<string>} 最终 assistant 的文本内容
|
|
38
34
|
*/
|
|
39
|
-
export default async function runConversation(_this, messages) {
|
|
35
|
+
export default async function runConversation(_this, messages, logback, thinkback) {
|
|
40
36
|
|
|
41
37
|
while (true) {
|
|
42
38
|
const result = await _this.model.completions({
|
|
43
39
|
messages,
|
|
44
40
|
tools: _this.tools,
|
|
45
|
-
stream:
|
|
46
|
-
});
|
|
41
|
+
stream: _this.stream,
|
|
42
|
+
}, logback, thinkback);
|
|
47
43
|
|
|
48
44
|
const hasToolCalls = appendAssistantMessage(messages, result);
|
|
49
45
|
|
|
@@ -52,6 +48,7 @@ export default async function runConversation(_this, messages) {
|
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
const toolResults = await callFuns(_this, result.tool_calls);
|
|
51
|
+
|
|
55
52
|
result.tool_calls.forEach((call, i) => {
|
|
56
53
|
messages.push(toToolMessage(call, toolResults[i]));
|
|
57
54
|
});
|
package/types/agent.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent 构造器:模型对话循环 + 工具调用编排
|
|
3
|
+
*/
|
|
4
|
+
import type { ChatMessage, ModelConfig } from "@auipage/types";
|
|
5
|
+
import type { Model } from "@auipage/model";
|
|
6
|
+
import type { AgentTool } from "./tool.js";
|
|
7
|
+
|
|
8
|
+
/** 流式正文回调,参数为模型本次给出的文本(增量) */
|
|
9
|
+
export type Logback = (text: string) => void;
|
|
10
|
+
|
|
11
|
+
/** 流式思维链 / 推理过程回调,参数为本次增量文本 */
|
|
12
|
+
export type Thinkback = (text: string) => void;
|
|
13
|
+
|
|
14
|
+
export interface AgentOptions {
|
|
15
|
+
/** 透传给 @auipage/model 的模型配置 */
|
|
16
|
+
model: ModelConfig;
|
|
17
|
+
/** 系统提示词,会作为首条 system 消息发送,默认 "" */
|
|
18
|
+
systemPrompt?: string;
|
|
19
|
+
/** 工具列表,默认 [] */
|
|
20
|
+
tools?: AgentTool[];
|
|
21
|
+
/** 是否开启流式输出,默认 false */
|
|
22
|
+
stream?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare class Agent {
|
|
26
|
+
constructor(options: AgentOptions);
|
|
27
|
+
|
|
28
|
+
/** 底层模型实例 */
|
|
29
|
+
model: Model;
|
|
30
|
+
tools: AgentTool[];
|
|
31
|
+
systemPrompt: string;
|
|
32
|
+
stream: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 执行对话循环:模型请求 → 工具调用 → 结果回传 → 继续请求,直至拿到最终文本。
|
|
36
|
+
*
|
|
37
|
+
* @param messages 本轮对话消息数组;配置了非空 systemPrompt 时会自动插到最前(原地修改)
|
|
38
|
+
* @param logback 流式正文增量回调
|
|
39
|
+
* @param thinkback 流式思维链增量回调
|
|
40
|
+
* @returns 模型最终回复;只产出工具调用而无文本时可能为 undefined
|
|
41
|
+
*/
|
|
42
|
+
generate(
|
|
43
|
+
messages: ChatMessage[],
|
|
44
|
+
logback?: Logback,
|
|
45
|
+
thinkback?: Thinkback
|
|
46
|
+
): Promise<string | undefined>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CreateTool:前后端工具桥接器
|
|
3
|
+
*
|
|
4
|
+
* 运行在服务端的 Agent 通过消息流把工具调用状态推送给页面,
|
|
5
|
+
* 页面执行完“前端工具”后再把结果回传,唤醒挂起的调用。
|
|
6
|
+
*/
|
|
7
|
+
import type {
|
|
8
|
+
StreamEvent,
|
|
9
|
+
ToolDescription,
|
|
10
|
+
ToolExecutor
|
|
11
|
+
} from "@auipage/types";
|
|
12
|
+
import type { AgentTool } from "./tool.js";
|
|
13
|
+
|
|
14
|
+
/** 消息流发送端(结构与 @auipage/core 的 MessageStream 兼容) */
|
|
15
|
+
export interface MessageSender {
|
|
16
|
+
send(event: StreamEvent): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** ct.create 的入参:execute 缺省即“前端工具”,调用会挂起等待页面回传 */
|
|
20
|
+
export interface CreateToolInput {
|
|
21
|
+
description: ToolDescription;
|
|
22
|
+
/** 后端工具:在 Agent 所在服务端执行;缺省则为前端工具 */
|
|
23
|
+
execute?: ToolExecutor;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export declare class CreateTool {
|
|
27
|
+
constructor(ms: MessageSender);
|
|
28
|
+
|
|
29
|
+
/** 构造时传入的消息流发送端 */
|
|
30
|
+
ms: MessageSender;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 包装一个工具为标准 AgentTool:
|
|
34
|
+
* - 有 execute:执行前后通过消息流推送 pending / success / error;
|
|
35
|
+
* - 无 execute:只推送 pending,随后挂起,等待 globalThis[id](result) 唤醒。
|
|
36
|
+
*/
|
|
37
|
+
create(input: CreateToolInput): AgentTool;
|
|
38
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @auipage/agent 类型入口
|
|
3
|
+
*
|
|
4
|
+
* 智能体对话循环:工具调用编排、思维链回调,以及前后端工具桥接。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
Agent,
|
|
9
|
+
type AgentOptions,
|
|
10
|
+
type Logback,
|
|
11
|
+
type Thinkback
|
|
12
|
+
} from "./agent.js";
|
|
13
|
+
|
|
14
|
+
export type { AgentTool } from "./tool.js";
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
CreateTool,
|
|
18
|
+
type MessageSender,
|
|
19
|
+
type CreateToolInput
|
|
20
|
+
} from "./create-tool.js";
|
package/types/tool.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent 直接执行的工具形态
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDescription, ToolExecutor } from "@auipage/types";
|
|
5
|
+
|
|
6
|
+
export interface AgentTool {
|
|
7
|
+
/** 符合模型 tools 规范的描述对象 */
|
|
8
|
+
description: ToolDescription;
|
|
9
|
+
/**
|
|
10
|
+
* 工具执行函数。
|
|
11
|
+
* 注意:普通工具必须提供;只有经 CreateTool 桥接的“前端工具”
|
|
12
|
+
* 才允许在创建时缺省(由 CreateTool.create 补齐 execute)。
|
|
13
|
+
*/
|
|
14
|
+
execute: ToolExecutor;
|
|
15
|
+
}
|