@arki-moe/agent-ts 4.0.0 → 5.0.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/README.md +5 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -4
- package/dist/types.d.ts +2 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ const getTimeTool: Tool = {
|
|
|
13
13
|
name: "get_time",
|
|
14
14
|
description: "Get the current time in ISO format",
|
|
15
15
|
parameters: { type: "object", properties: {} },
|
|
16
|
+
data: { category: "time" },
|
|
16
17
|
execute: (_args, _agent) => new Date().toISOString(),
|
|
17
18
|
};
|
|
18
19
|
|
|
@@ -54,7 +55,7 @@ When `apiKey` is not provided in config, adapters read from the corresponding en
|
|
|
54
55
|
- `Agent(adapterName, config)` - Create Agent
|
|
55
56
|
- `agent.context` - Public property, complete conversation history
|
|
56
57
|
- `agent.registerTool(tool)` - Register tool
|
|
57
|
-
- `agent.run(message
|
|
58
|
+
- `agent.run(message)` - Execute tool chain automatically, returns all new `Message[]`
|
|
58
59
|
|
|
59
60
|
### Config
|
|
60
61
|
|
|
@@ -68,10 +69,12 @@ When `apiKey` is not provided in config, adapters read from the corresponding en
|
|
|
68
69
|
| `onToolCall` | `(message, args, agent) => boolean \| void \| Promise<boolean \| void>` | Called before each tool execution; return `false` to skip tool execution and `onToolResult` |
|
|
69
70
|
| `onToolResult` | `(message, agent) => void \| Promise<void>` | Called after each tool execution (`message.role === Role.ToolResult`) |
|
|
70
71
|
|
|
71
|
-
`agent.run` always appends new messages to `agent.context`.
|
|
72
|
+
`agent.run` always appends new messages to `agent.context`. Multiple tool calls in a single model response are executed in parallel.
|
|
72
73
|
|
|
73
74
|
`onToolCall` receives parsed JSON args and can mutate them before execution. Returning `false` skips the tool call and does not emit a `ToolResult` message.
|
|
74
75
|
|
|
76
|
+
`tool.data` is a local JSON metadata bag for your own use and is not sent to adapters.
|
|
77
|
+
|
|
75
78
|
## Scripts
|
|
76
79
|
|
|
77
80
|
| Command | Description |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AgentConfig, AgentLike, Context, Message,
|
|
1
|
+
import type { AgentConfig, AgentLike, Context, Message, Tool } from "./types";
|
|
2
2
|
export { openaiAdapter } from "./adapter/openai";
|
|
3
3
|
export { openrouterAdapter } from "./adapter/openrouter";
|
|
4
|
-
export type { Adapter, AgentConfig, AgentLike, Context, Message,
|
|
4
|
+
export type { Adapter, AgentConfig, AgentLike, Context, Message, Tool } from "./types";
|
|
5
5
|
export { Role } from "./types";
|
|
6
6
|
export declare class Agent implements AgentLike {
|
|
7
7
|
context: Context;
|
|
@@ -14,5 +14,5 @@ export declare class Agent implements AgentLike {
|
|
|
14
14
|
private onToolResult?;
|
|
15
15
|
constructor(adapterName: string, config: AgentConfig);
|
|
16
16
|
registerTool(tool: Tool): void;
|
|
17
|
-
run(message: string
|
|
17
|
+
run(message: string): Promise<Message[]>;
|
|
18
18
|
}
|
package/dist/index.js
CHANGED
|
@@ -28,8 +28,7 @@ class Agent {
|
|
|
28
28
|
registerTool(tool) {
|
|
29
29
|
this.tools.push(tool);
|
|
30
30
|
}
|
|
31
|
-
async run(message
|
|
32
|
-
const once = options.once ?? false;
|
|
31
|
+
async run(message) {
|
|
33
32
|
const all = [];
|
|
34
33
|
const sessionContext = [...this.context];
|
|
35
34
|
const persistToContext = (msgs) => {
|
|
@@ -40,8 +39,7 @@ class Agent {
|
|
|
40
39
|
};
|
|
41
40
|
const userMessage = { role: types_1.Role.User, content: message };
|
|
42
41
|
pushToSession([userMessage]);
|
|
43
|
-
|
|
44
|
-
persistToContext([userMessage]);
|
|
42
|
+
persistToContext([userMessage]);
|
|
45
43
|
const runAdapter = async () => {
|
|
46
44
|
const msgs = await this.adapter(this.config, sessionContext, this.tools);
|
|
47
45
|
pushToSession(msgs);
|
package/dist/types.d.ts
CHANGED
|
@@ -29,12 +29,13 @@ export type Context = Message[];
|
|
|
29
29
|
export interface AgentLike {
|
|
30
30
|
context: Context;
|
|
31
31
|
registerTool: (tool: Tool) => void;
|
|
32
|
-
run: (message: string
|
|
32
|
+
run: (message: string) => Promise<Message[]>;
|
|
33
33
|
}
|
|
34
34
|
export type Tool = {
|
|
35
35
|
name: string;
|
|
36
36
|
description: string;
|
|
37
37
|
parameters: unknown;
|
|
38
|
+
data?: Record<string, unknown>;
|
|
38
39
|
execute: (args: unknown, agent: AgentLike) => Promise<unknown> | unknown;
|
|
39
40
|
};
|
|
40
41
|
export type AgentConfig = {
|
|
@@ -48,7 +49,4 @@ export type AgentConfig = {
|
|
|
48
49
|
}>, agent: AgentLike) => void | Promise<void>;
|
|
49
50
|
[key: string]: unknown;
|
|
50
51
|
};
|
|
51
|
-
export type RunOptions = {
|
|
52
|
-
once?: boolean;
|
|
53
|
-
};
|
|
54
52
|
export type Adapter = (config: Record<string, unknown>, context: Message[], tools: Tool[]) => Promise<Message[]>;
|