@auipage/agent 0.2.0-beta.0 → 0.2.0
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/AUTHORS.txt +6 -6
- package/CHANGELOG +30 -30
- package/README.md +136 -136
- package/dist/index.cjs +1 -1
- package/dist/index.js +964 -964
- package/dist/index.min.js +1 -1
- package/package.json +3 -3
- package/src/callFuns.js +44 -44
- package/src/createTool.js +101 -101
- package/src/index.js +41 -41
- package/src/runConversation.js +65 -65
- package/types/agent.d.ts +58 -58
- package/types/create-tool.d.ts +44 -44
- package/types/index.d.ts +20 -20
- package/types/tool.d.ts +15 -15
package/types/agent.d.ts
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
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
|
-
/** 工具调用循环上限,默认 0(不限制);超过上限以 error reject */
|
|
24
|
-
maxSteps?: number;
|
|
25
|
-
/**
|
|
26
|
-
* 取消信号(0.2.0 起提供),会透传给每次模型请求;
|
|
27
|
-
* abort 后本轮以错误 reject,可配合 AuiPage.stop() 的 context.signal 使用。
|
|
28
|
-
*/
|
|
29
|
-
signal?: AbortSignal | null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export declare class Agent {
|
|
33
|
-
constructor(options: AgentOptions);
|
|
34
|
-
|
|
35
|
-
/** 底层模型实例 */
|
|
36
|
-
model: Model;
|
|
37
|
-
tools: AgentTool[];
|
|
38
|
-
systemPrompt: string;
|
|
39
|
-
stream: boolean;
|
|
40
|
-
/** 工具调用循环上限,0 表示不限制 */
|
|
41
|
-
maxSteps: number;
|
|
42
|
-
/** 取消信号,未设置时为 null */
|
|
43
|
-
signal: AbortSignal | null;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 执行对话循环:模型请求 → 工具调用 → 结果回传 → 继续请求,直至拿到最终文本。
|
|
47
|
-
*
|
|
48
|
-
* @param messages 本轮对话消息数组;配置了非空 systemPrompt 时会自动插到最前(原地修改)
|
|
49
|
-
* @param logback 流式正文增量回调
|
|
50
|
-
* @param thinkback 流式思维链增量回调
|
|
51
|
-
* @returns 模型最终回复;只产出工具调用而无文本时可能为 undefined
|
|
52
|
-
*/
|
|
53
|
-
generate(
|
|
54
|
-
messages: ChatMessage[],
|
|
55
|
-
logback?: Logback,
|
|
56
|
-
thinkback?: Thinkback
|
|
57
|
-
): Promise<string | undefined>;
|
|
58
|
-
}
|
|
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
|
+
/** 工具调用循环上限,默认 0(不限制);超过上限以 error reject */
|
|
24
|
+
maxSteps?: number;
|
|
25
|
+
/**
|
|
26
|
+
* 取消信号(0.2.0 起提供),会透传给每次模型请求;
|
|
27
|
+
* abort 后本轮以错误 reject,可配合 AuiPage.stop() 的 context.signal 使用。
|
|
28
|
+
*/
|
|
29
|
+
signal?: AbortSignal | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare class Agent {
|
|
33
|
+
constructor(options: AgentOptions);
|
|
34
|
+
|
|
35
|
+
/** 底层模型实例 */
|
|
36
|
+
model: Model;
|
|
37
|
+
tools: AgentTool[];
|
|
38
|
+
systemPrompt: string;
|
|
39
|
+
stream: boolean;
|
|
40
|
+
/** 工具调用循环上限,0 表示不限制 */
|
|
41
|
+
maxSteps: number;
|
|
42
|
+
/** 取消信号,未设置时为 null */
|
|
43
|
+
signal: AbortSignal | null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 执行对话循环:模型请求 → 工具调用 → 结果回传 → 继续请求,直至拿到最终文本。
|
|
47
|
+
*
|
|
48
|
+
* @param messages 本轮对话消息数组;配置了非空 systemPrompt 时会自动插到最前(原地修改)
|
|
49
|
+
* @param logback 流式正文增量回调
|
|
50
|
+
* @param thinkback 流式思维链增量回调
|
|
51
|
+
* @returns 模型最终回复;只产出工具调用而无文本时可能为 undefined
|
|
52
|
+
*/
|
|
53
|
+
generate(
|
|
54
|
+
messages: ChatMessage[],
|
|
55
|
+
logback?: Logback,
|
|
56
|
+
thinkback?: Thinkback
|
|
57
|
+
): Promise<string | undefined>;
|
|
58
|
+
}
|
package/types/create-tool.d.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
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
|
-
/** ct.create 的可选配置 */
|
|
27
|
-
export interface CreateToolOptions {
|
|
28
|
-
/** 前端工具等待页面回传的超时毫秒数,0 / 缺省表示不限制;超时以 error reject */
|
|
29
|
-
timeout?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export declare class CreateTool {
|
|
33
|
-
constructor(ms: MessageSender);
|
|
34
|
-
|
|
35
|
-
/** 构造时传入的消息流发送端 */
|
|
36
|
-
ms: MessageSender;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 包装一个工具为标准 AgentTool:
|
|
40
|
-
* - 有 execute:执行前后通过消息流推送 pending / success / error;失败时抛错由 callFuns 转成文本;
|
|
41
|
-
* - 无 execute:只推送 pending,随后挂起,等待 globalThis[id](result, status?) 唤醒。
|
|
42
|
-
*/
|
|
43
|
-
create(input: CreateToolInput, options?: CreateToolOptions): AgentTool;
|
|
44
|
-
}
|
|
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
|
+
/** ct.create 的可选配置 */
|
|
27
|
+
export interface CreateToolOptions {
|
|
28
|
+
/** 前端工具等待页面回传的超时毫秒数,0 / 缺省表示不限制;超时以 error reject */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare class CreateTool {
|
|
33
|
+
constructor(ms: MessageSender);
|
|
34
|
+
|
|
35
|
+
/** 构造时传入的消息流发送端 */
|
|
36
|
+
ms: MessageSender;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 包装一个工具为标准 AgentTool:
|
|
40
|
+
* - 有 execute:执行前后通过消息流推送 pending / success / error;失败时抛错由 callFuns 转成文本;
|
|
41
|
+
* - 无 execute:只推送 pending,随后挂起,等待 globalThis[id](result, status?) 唤醒。
|
|
42
|
+
*/
|
|
43
|
+
create(input: CreateToolInput, options?: CreateToolOptions): AgentTool;
|
|
44
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,20 +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";
|
|
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
CHANGED
|
@@ -1,15 +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
|
-
}
|
|
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
|
+
}
|