@agent-smith/agent 0.1.8 → 0.2.1

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/dist/agent.d.ts CHANGED
@@ -2,10 +2,11 @@ import { Lm } from "@locallm/api";
2
2
  import { InferenceParams, ToolSpec, HistoryTurn, InferenceOptions, InferenceResult } from "@locallm/types";
3
3
  import { PromptTemplate } from 'modprompt';
4
4
  declare class Agent {
5
+ name: string;
5
6
  lm: Lm;
6
7
  tools: Record<string, ToolSpec>;
7
8
  history: Array<HistoryTurn>;
8
- constructor(lm: Lm);
9
+ constructor(lm: Lm, name?: string);
9
10
  run(prompt: string, params: InferenceParams, options?: InferenceOptions, template?: PromptTemplate | string): Promise<InferenceResult>;
10
11
  runAgentNoTemplate(it: number, prompt: string, params: InferenceParams, options?: InferenceOptions): Promise<InferenceResult>;
11
12
  runAgentWithTemplate(it: number, prompt: string, params: InferenceParams, options: InferenceOptions | undefined, tpl: PromptTemplate): Promise<InferenceResult>;
package/dist/agent.js CHANGED
@@ -1,17 +1,21 @@
1
1
  import { PromptTemplate } from 'modprompt';
2
2
  import { splitThinking } from "./utils.js";
3
3
  class Agent {
4
+ name = "unamed";
4
5
  lm;
5
6
  tools = {};
6
7
  history = [];
7
- constructor(lm) {
8
+ constructor(lm, name) {
8
9
  this.lm = lm;
10
+ if (name) {
11
+ this.name = name;
12
+ }
9
13
  }
10
14
  async run(prompt, params, options = {}, template) {
11
15
  let tpl;
12
16
  if (options?.debug) {
13
- console.log("Agent inference params:", params);
14
- console.log("Agent options:", options);
17
+ console.log("Agent", this.name, "inference params:", params);
18
+ console.log("Agent", this.name, "options:", options);
15
19
  }
16
20
  if (options?.history) {
17
21
  this.history = options.history;
@@ -72,7 +76,7 @@ class Agent {
72
76
  const tool = this.tools[tc.name];
73
77
  let canRun = true;
74
78
  if (tool?.canRun) {
75
- canRun = await tool.canRun(tool);
79
+ canRun = await tool.canRun(tc);
76
80
  }
77
81
  if (canRun) {
78
82
  if (options?.onToolCall) {
@@ -94,10 +98,19 @@ class Agent {
94
98
  }
95
99
  }
96
100
  this.history.push({ tools: toolsResults });
101
+ if (options?.isToolsRouter) {
102
+ const fres = {
103
+ text: JSON.stringify(toolsResults.map(tr => tr.response)),
104
+ stats: res.stats,
105
+ serverStats: res.serverStats,
106
+ toolCalls: res.toolCalls,
107
+ };
108
+ return fres;
109
+ }
110
+ const nit = it + 1;
97
111
  if (options?.tools) {
98
112
  options.tools = Object.values(this.tools);
99
113
  }
100
- const nit = it + 1;
101
114
  _res = await this.runAgentNoTemplate(nit, "", params, options);
102
115
  }
103
116
  else {
@@ -138,7 +151,7 @@ class Agent {
138
151
  }
139
152
  let canRun = true;
140
153
  if (tool?.canRun) {
141
- canRun = await tool.canRun(tool);
154
+ canRun = await tool.canRun(toolCall);
142
155
  }
143
156
  if (!canRun) {
144
157
  if (options?.debug || options?.verbose) {
@@ -182,6 +195,15 @@ class Agent {
182
195
  tools: toolResults,
183
196
  });
184
197
  }
198
+ if (options?.isToolsRouter && isToolCall) {
199
+ const fres = {
200
+ text: JSON.stringify(toolResults.map(tr => tr.response)),
201
+ stats: res.stats,
202
+ serverStats: res.serverStats,
203
+ toolCalls: res.toolCalls,
204
+ };
205
+ return fres;
206
+ }
185
207
  return await this.runAgentWithTemplate(it + 1, prompt, params, options, tpl);
186
208
  }
187
209
  else {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/synw/agent-smith.git"
7
7
  },
8
- "version": "0.1.8",
8
+ "version": "0.2.1",
9
9
  "scripts": {
10
10
  "buildrl": "rm -rf dist/* && rollup -c",
11
11
  "build": "rm -rf dist/* && tsc"
@@ -16,12 +16,12 @@
16
16
  "restmix": "^0.6.1"
17
17
  },
18
18
  "devDependencies": {
19
- "@locallm/types": "^0.6.5",
19
+ "@locallm/types": "^0.6.7",
20
20
  "@rollup/plugin-node-resolve": "^16.0.3",
21
21
  "@rollup/plugin-typescript": "^12.3.0",
22
- "@types/node": "^25.0.3",
23
- "openai": "^6.15.0",
24
- "rollup": "^4.54.0",
22
+ "@types/node": "^25.0.8",
23
+ "openai": "^6.16.0",
24
+ "rollup": "^4.55.1",
25
25
  "ts-node": "^10.9.2",
26
26
  "tslib": "2.8.1",
27
27
  "typescript": "^5.9.3"