@agent-smith/agent 0.0.2 → 0.0.4

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
@@ -6,7 +6,7 @@ declare class Agent {
6
6
  tools: Record<string, ToolSpec>;
7
7
  history: Array<HistoryTurn>;
8
8
  constructor(lm: Lm);
9
- run(prompt: string, params: InferenceParams, options?: InferenceOptions, template?: PromptTemplate): Promise<InferenceResult>;
9
+ run(prompt: string, params: InferenceParams, options?: InferenceOptions, template?: PromptTemplate | string): Promise<InferenceResult>;
10
10
  runAgentNoTemplate(it: number, prompt: string, params: InferenceParams, options?: InferenceOptions): Promise<InferenceResult>;
11
11
  runAgentWithTemplate(it: number, prompt: string, params: InferenceParams, options: InferenceOptions | undefined, tpl: PromptTemplate): Promise<{
12
12
  inferenceResult: InferenceResult;
package/dist/agent.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { PromptTemplate } from 'modprompt';
1
2
  class Agent {
2
3
  lm;
3
4
  tools = {};
@@ -6,23 +7,41 @@ class Agent {
6
7
  this.lm = lm;
7
8
  }
8
9
  async run(prompt, params, options = {}, template) {
9
- this.tools = {};
10
- if (options?.tools) {
11
- options.tools.forEach(t => {
12
- this.tools[t.name] = t;
13
- if (template) {
14
- template = template.addTool(t);
15
- }
16
- });
10
+ let tpl;
11
+ if (options?.debug) {
12
+ console.log("Agent inference params:", params);
13
+ console.log("Agent options:", options);
14
+ console.log("Agent template:", template);
15
+ console.log("Prompt:", prompt);
17
16
  }
18
17
  if (this.lm.providerType == "openai") {
19
18
  return await this.runAgentNoTemplate(1, prompt, params, options);
20
19
  }
21
20
  else {
22
21
  if (!template) {
23
- throw new Error(`A template is required for provider ${this.lm.provider.name}`);
22
+ if (params?.template) {
23
+ tpl = new PromptTemplate(params.template);
24
+ }
25
+ else {
26
+ throw new Error(`A template is required for provider ${this.lm.provider.name}`);
27
+ }
28
+ }
29
+ else {
30
+ if (typeof template == "string") {
31
+ tpl = new PromptTemplate(template);
32
+ }
33
+ else {
34
+ tpl = template;
35
+ }
24
36
  }
25
- return (await this.runAgentWithTemplate(1, prompt, params, options, template)).inferenceResult;
37
+ this.tools = {};
38
+ if (options?.tools) {
39
+ options.tools.forEach(t => {
40
+ this.tools[t.name] = t;
41
+ tpl = tpl.addTool(t);
42
+ });
43
+ }
44
+ return (await this.runAgentWithTemplate(1, prompt, params, options, tpl)).inferenceResult;
26
45
  }
27
46
  }
28
47
  async runAgentNoTemplate(it, prompt, params, options = {}) {
@@ -72,6 +91,12 @@ class Agent {
72
91
  return _res;
73
92
  }
74
93
  async runAgentWithTemplate(it, prompt, params, options = {}, tpl) {
94
+ if (this.lm.providerType == "ollama") {
95
+ if (!params?.model) {
96
+ throw new Error("A model inference parameters is required for provider Ollama");
97
+ }
98
+ await this.lm.loadModel(params.model.name, params.model.ctx);
99
+ }
75
100
  let res = await this.lm.infer(tpl.prompt(prompt), params, options);
76
101
  const { isToolCall, toolsCall, error } = tpl.processAnswer(res.text);
77
102
  if (error) {
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@agent-smith/agent",
3
3
  "description": "Agent Smith: agent runtime",
4
- "repository": "https://github.com/synw/agent-smith",
5
- "version": "0.0.2",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/synw/agent-smith.git"
7
+ },
8
+ "version": "0.0.4",
6
9
  "scripts": {
7
10
  "buildrl": "rm -rf dist/* && rollup -c",
8
11
  "build": "rm -rf dist/* && tsc"