@agentionai/agents 0.12.0 → 0.14.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 +78 -7
- package/dist/agents/Agent.d.ts +9 -3
- package/dist/agents/Agent.js +4 -0
- package/dist/agents/AgentConfig.d.ts +29 -3
- package/dist/agents/anthropic/ClaudeAgent.d.ts +19 -1
- package/dist/agents/anthropic/ClaudeAgent.js +27 -8
- package/dist/agents/llamacpp/LlamaCppAgent.d.ts +37 -0
- package/dist/agents/llamacpp/LlamaCppAgent.js +44 -0
- package/dist/agents/model-types.d.ts +7 -0
- package/dist/agents/ollama/OllamaAgent.d.ts +23 -1
- package/dist/agents/ollama/OllamaAgent.js +13 -0
- package/dist/agents/openai-compatible/OpenAICompatibleAgent.d.ts +48 -0
- package/dist/agents/openai-compatible/OpenAICompatibleAgent.js +249 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/history/transformers.d.ts +64 -0
- package/dist/history/transformers.js +118 -1
- package/dist/history/types.d.ts +8 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +7 -1
- package/dist/llamacpp.d.ts +6 -0
- package/dist/llamacpp.js +26 -0
- package/dist/tools/BuiltInTool.d.ts +72 -0
- package/dist/tools/BuiltInTool.js +53 -0
- package/dist/viz/types.d.ts +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ Get an API key from your chosen provider:
|
|
|
27
27
|
- **OpenAI**: [platform.openai.com](https://platform.openai.com/api-keys)
|
|
28
28
|
- **Gemini**: [aistudio.google.com](https://aistudio.google.com/app/apikey)
|
|
29
29
|
- **Mistral**: [console.mistral.ai](https://console.mistral.ai/)
|
|
30
|
+
- **Ollama** / **llama.cpp**: no API key needed — run models locally (see [Agents guide](https://docs.agention.ai/guide/agents))
|
|
30
31
|
|
|
31
32
|
Set it as an environment variable:
|
|
32
33
|
|
|
@@ -56,10 +57,12 @@ console.log(response);
|
|
|
56
57
|
Import only the agents you need:
|
|
57
58
|
|
|
58
59
|
```typescript
|
|
59
|
-
import { ClaudeAgent } from '@agentionai/agents/claude';
|
|
60
|
-
import { OpenAiAgent } from '@agentionai/agents/openai';
|
|
61
|
-
import { GeminiAgent } from '@agentionai/agents/gemini';
|
|
62
|
-
import { MistralAgent } from '@agentionai/agents/mistral';
|
|
60
|
+
import { ClaudeAgent } from '@agentionai/agents/claude'; // Requires @anthropic-ai/sdk
|
|
61
|
+
import { OpenAiAgent } from '@agentionai/agents/openai'; // Requires openai
|
|
62
|
+
import { GeminiAgent } from '@agentionai/agents/gemini'; // Requires @google/generative-ai
|
|
63
|
+
import { MistralAgent } from '@agentionai/agents/mistral'; // Requires @mistralai/mistralai
|
|
64
|
+
import { OllamaAgent } from '@agentionai/agents/ollama'; // Requires ollama (local, no API key)
|
|
65
|
+
import { LlamaCppAgent } from '@agentionai/agents/llamacpp'; // Requires openai (local, no API key)
|
|
63
66
|
```
|
|
64
67
|
|
|
65
68
|
Or import everything (requires all SDKs):
|
|
@@ -71,7 +74,8 @@ import { ClaudeAgent, OpenAiAgent } from '@agentionai/agents';
|
|
|
71
74
|
|
|
72
75
|
## Features
|
|
73
76
|
|
|
74
|
-
- **Multi-Provider, No Lock-in** - Claude, OpenAI, Gemini, Mistral—same interface. Switch models with one line.
|
|
77
|
+
- **Multi-Provider, No Lock-in** - Claude, OpenAI, Gemini, Mistral, plus local models via Ollama and llama.cpp—same interface. Switch models with one line.
|
|
78
|
+
- **Built-In Tools** - Use provider-defined server-side tools (e.g. Anthropic's web search, bash, text editor) alongside your own.
|
|
75
79
|
- **Composable, Not Magical** - Agents are objects. Pipelines are arrays. No hidden state, no surprises.
|
|
76
80
|
- **Multimodal / Vision** - Send images alongside text with a unified `MessageContent[]` API across all providers.
|
|
77
81
|
- **Full Observability** - Per-call token counts, execution timing, pipeline structure visualization.
|
|
@@ -115,6 +119,73 @@ const agent = new GeminiAgent({
|
|
|
115
119
|
const response = await agent.execute("What's the weather in Paris?");
|
|
116
120
|
```
|
|
117
121
|
|
|
122
|
+
### Local Models (Ollama / llama.cpp / OpenAI-compatible servers)
|
|
123
|
+
|
|
124
|
+
Run models on your own machine — no API key required. Same agent interface as every other provider:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { OllamaAgent } from '@agentionai/agents/ollama';
|
|
128
|
+
import { LlamaCppAgent } from '@agentionai/agents/llamacpp';
|
|
129
|
+
|
|
130
|
+
// Ollama (https://ollama.com) — pull a model first: `ollama pull qwen2.5`
|
|
131
|
+
const ollama = new OllamaAgent({
|
|
132
|
+
id: 'local-ollama',
|
|
133
|
+
name: 'Local Assistant',
|
|
134
|
+
description: 'You are a helpful assistant.',
|
|
135
|
+
model: 'qwen2.5',
|
|
136
|
+
apiKey: '',
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// llama.cpp server (`llama-server -m model.gguf`) — OpenAI-compatible API
|
|
140
|
+
const llamaCpp = new LlamaCppAgent({
|
|
141
|
+
id: 'local-llamacpp',
|
|
142
|
+
name: 'Local Assistant',
|
|
143
|
+
description: 'You are a helpful assistant.',
|
|
144
|
+
apiKey: '',
|
|
145
|
+
baseURL: 'http://localhost:8080/v1',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const response = await ollama.execute('What can you run locally?');
|
|
149
|
+
|
|
150
|
+
// Discover which models are available on the server
|
|
151
|
+
const models = await ollama.listModels();
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Custom OpenAI-compatible server** (vLLM, LM Studio, Together AI, Groq, …): extend `OpenAICompatibleAgent` directly:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { OpenAICompatibleAgent, OpenAICompatibleConfig } from '@agentionai/agents/llamacpp';
|
|
158
|
+
|
|
159
|
+
class VLLMAgent extends OpenAICompatibleAgent {
|
|
160
|
+
constructor(config: Omit<OpenAICompatibleConfig, 'vendor'>) {
|
|
161
|
+
super({ ...config, vendor: 'llamacpp', baseURL: config.baseURL ?? 'http://localhost:8000/v1' });
|
|
162
|
+
}
|
|
163
|
+
protected getVendorName() { return 'vLLM'; }
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
[Full guide →](https://docs.agention.ai/guide/agents#custom-openai-compatible-agents)
|
|
168
|
+
|
|
169
|
+
### Built-In Tools
|
|
170
|
+
|
|
171
|
+
Use a provider's own server-side tools (executed by the provider, not locally) alongside your custom tools:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { ClaudeAgent } from '@agentionai/agents/claude';
|
|
175
|
+
import { webSearchTool } from '@agentionai/agents/claude';
|
|
176
|
+
|
|
177
|
+
const agent = new ClaudeAgent({
|
|
178
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
179
|
+
id: 'researcher',
|
|
180
|
+
name: 'Researcher',
|
|
181
|
+
description: 'You are a helpful research assistant with web access.',
|
|
182
|
+
model: 'claude-sonnet-4-6',
|
|
183
|
+
builtInTools: [webSearchTool({ maxUses: 5 })],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const response = await agent.execute('What happened in the news today?');
|
|
187
|
+
```
|
|
188
|
+
|
|
118
189
|
### Multi-Agent Pipeline
|
|
119
190
|
|
|
120
191
|
Chain agents together with different providers and models:
|
|
@@ -216,12 +287,12 @@ const response2 = await agent.execute([
|
|
|
216
287
|
## Core Concepts
|
|
217
288
|
|
|
218
289
|
### Agents
|
|
219
|
-
Unified interface across Claude, OpenAI, Gemini, and
|
|
290
|
+
Unified interface across Claude, OpenAI, Gemini, Mistral, and local models via Ollama and llama.cpp. Tools, history, and token tracking built-in.
|
|
220
291
|
|
|
221
292
|
[Learn more →](https://docs.agention.ai/guide/agents)
|
|
222
293
|
|
|
223
294
|
### Tools
|
|
224
|
-
JSON Schema + handler pattern. Unique capability: wrap any agent as a tool for delegation hierarchies.
|
|
295
|
+
JSON Schema + handler pattern. Unique capability: wrap any agent as a tool for delegation hierarchies. Also supports provider-defined built-in tools (e.g. Anthropic's web search, bash, text editor) that run server-side.
|
|
225
296
|
|
|
226
297
|
[Learn more →](https://docs.agention.ai/guide/tools)
|
|
227
298
|
|
package/dist/agents/Agent.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { OpenAiAgent } from "./openai/OpenAiAgent";
|
|
|
5
5
|
import { GeminiAgent } from "./google/GeminiAgent";
|
|
6
6
|
import { MistralAgent } from "./mistral/MistralAgent";
|
|
7
7
|
import { OllamaAgent } from "./ollama/OllamaAgent";
|
|
8
|
-
import {
|
|
8
|
+
import { LlamaCppAgent } from "./llamacpp/LlamaCppAgent";
|
|
9
|
+
import { ClaudeModel, OpenAIModel, GeminiModel, MistralModel, OllamaModel, LlamaCppModel } from "./model-types";
|
|
9
10
|
type ClaudeAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
10
11
|
vendor: "anthropic";
|
|
11
12
|
model?: ClaudeModel;
|
|
@@ -27,9 +28,14 @@ type OllamaAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
|
27
28
|
model?: OllamaModel;
|
|
28
29
|
host?: string;
|
|
29
30
|
};
|
|
30
|
-
type
|
|
31
|
+
type LlamaCppAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
32
|
+
vendor: "llamacpp";
|
|
33
|
+
model?: LlamaCppModel;
|
|
34
|
+
baseURL?: string;
|
|
35
|
+
};
|
|
36
|
+
type AgentConfig = ClaudeAgentConfig | OpenAIAgentConfig | GeminiAgentConfig | MistralAgentConfig | OllamaAgentConfig | LlamaCppAgentConfig;
|
|
31
37
|
export declare class Agent {
|
|
32
|
-
static create(config: AgentConfig, history?: History): ClaudeAgent | GeminiAgent | OpenAiAgent | MistralAgent | OllamaAgent;
|
|
38
|
+
static create(config: AgentConfig, history?: History): ClaudeAgent | GeminiAgent | OpenAiAgent | MistralAgent | OllamaAgent | LlamaCppAgent;
|
|
33
39
|
}
|
|
34
40
|
export {};
|
|
35
41
|
//# sourceMappingURL=Agent.d.ts.map
|
package/dist/agents/Agent.js
CHANGED
|
@@ -6,6 +6,7 @@ const OpenAiAgent_1 = require("./openai/OpenAiAgent");
|
|
|
6
6
|
const GeminiAgent_1 = require("./google/GeminiAgent");
|
|
7
7
|
const MistralAgent_1 = require("./mistral/MistralAgent");
|
|
8
8
|
const OllamaAgent_1 = require("./ollama/OllamaAgent");
|
|
9
|
+
const LlamaCppAgent_1 = require("./llamacpp/LlamaCppAgent");
|
|
9
10
|
class Agent {
|
|
10
11
|
static create(config, history) {
|
|
11
12
|
if (config.vendor === "anthropic") {
|
|
@@ -23,6 +24,9 @@ class Agent {
|
|
|
23
24
|
else if (config.vendor === "ollama") {
|
|
24
25
|
return new OllamaAgent_1.OllamaAgent(config, history);
|
|
25
26
|
}
|
|
27
|
+
else if (config.vendor === "llamacpp") {
|
|
28
|
+
return new LlamaCppAgent_1.LlamaCppAgent(config, history);
|
|
29
|
+
}
|
|
26
30
|
else {
|
|
27
31
|
throw new Error("No vendor defined");
|
|
28
32
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Tool } from "../tools/Tool";
|
|
2
|
+
import { BuiltInTool } from "../tools/BuiltInTool";
|
|
2
3
|
import { BaseAgent } from "./BaseAgent";
|
|
3
4
|
/** Supported LLM vendors */
|
|
4
|
-
export type AgentVendor = "openai" | "anthropic" | "mistral" | "gemini" | "ollama";
|
|
5
|
+
export type AgentVendor = "openai" | "anthropic" | "mistral" | "gemini" | "ollama" | "llamacpp";
|
|
5
6
|
/**
|
|
6
7
|
* Common configuration shared by all agents
|
|
7
8
|
*/
|
|
@@ -57,6 +58,21 @@ export interface CommonAgentConfig {
|
|
|
57
58
|
export interface ClaudeSpecificConfig {
|
|
58
59
|
disableParallelToolUse?: boolean;
|
|
59
60
|
metadata?: Record<string, string>;
|
|
61
|
+
/**
|
|
62
|
+
* Provider-defined / server-side tools (e.g. web search, bash, text editor).
|
|
63
|
+
* These are executed by Anthropic rather than locally — see `lib/tools/BuiltInTool.ts`.
|
|
64
|
+
*/
|
|
65
|
+
builtInTools?: BuiltInTool[];
|
|
66
|
+
/**
|
|
67
|
+
* How `apiKey` should be presented to the Anthropic SDK.
|
|
68
|
+
* - `"apiKey"` (default): sent as the `x-api-key` header — for standard Anthropic API keys.
|
|
69
|
+
* - `"oauth"`: sent as a bearer `authToken` — for OAuth access tokens (e.g. Claude Code /
|
|
70
|
+
* Claude.ai tokens, which look like `sk-ant-oat...`).
|
|
71
|
+
*
|
|
72
|
+
* Set this explicitly rather than relying on the token's prefix, since prefixes are an
|
|
73
|
+
* implementation detail that can change.
|
|
74
|
+
*/
|
|
75
|
+
authType?: "apiKey" | "oauth";
|
|
60
76
|
}
|
|
61
77
|
/**
|
|
62
78
|
* Vendor-specific configuration for OpenAI
|
|
@@ -90,9 +106,16 @@ export interface GeminiSpecificConfig {
|
|
|
90
106
|
* Vendor-specific configuration for Ollama (local)
|
|
91
107
|
*/
|
|
92
108
|
export interface OllamaSpecificConfig {
|
|
93
|
-
/** Ollama server URL (default: http://localhost:11434) */
|
|
109
|
+
/** Ollama server URL (default: `http://localhost:11434`) */
|
|
94
110
|
host?: string;
|
|
95
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Vendor-specific configuration for llama.cpp server (local)
|
|
114
|
+
*/
|
|
115
|
+
export interface LlamaCppSpecificConfig {
|
|
116
|
+
/** Base URL of the llama.cpp server's OpenAI-compatible API (default: `http://localhost:8080/v1`) */
|
|
117
|
+
baseURL?: string;
|
|
118
|
+
}
|
|
96
119
|
/**
|
|
97
120
|
* Generic vendor-specific configuration container
|
|
98
121
|
* This allows any vendor to add custom config without modifying base types
|
|
@@ -103,6 +126,7 @@ export interface VendorSpecificConfig {
|
|
|
103
126
|
mistral?: MistralSpecificConfig;
|
|
104
127
|
gemini?: GeminiSpecificConfig;
|
|
105
128
|
ollama?: OllamaSpecificConfig;
|
|
129
|
+
llamacpp?: LlamaCppSpecificConfig;
|
|
106
130
|
}
|
|
107
131
|
/**
|
|
108
132
|
* Complete agent configuration with vendor-specific extensions
|
|
@@ -144,10 +168,12 @@ export type TypedAgentConfig<V extends AgentVendor> = CommonAgentConfig & {
|
|
|
144
168
|
gemini?: GeminiSpecificConfig;
|
|
145
169
|
} : V extends "ollama" ? {
|
|
146
170
|
ollama?: OllamaSpecificConfig;
|
|
171
|
+
} : V extends "llamacpp" ? {
|
|
172
|
+
llamacpp?: LlamaCppSpecificConfig;
|
|
147
173
|
} : never;
|
|
148
174
|
};
|
|
149
175
|
/**
|
|
150
176
|
* Helper type to extract vendor-specific config for a given vendor
|
|
151
177
|
*/
|
|
152
|
-
export type VendorConfigFor<V extends AgentVendor> = V extends "anthropic" ? ClaudeSpecificConfig : V extends "openai" ? OpenAISpecificConfig : V extends "mistral" ? MistralSpecificConfig : V extends "gemini" ? GeminiSpecificConfig : V extends "ollama" ? OllamaSpecificConfig : never;
|
|
178
|
+
export type VendorConfigFor<V extends AgentVendor> = V extends "anthropic" ? ClaudeSpecificConfig : V extends "openai" ? OpenAISpecificConfig : V extends "mistral" ? MistralSpecificConfig : V extends "gemini" ? GeminiSpecificConfig : V extends "ollama" ? OllamaSpecificConfig : V extends "llamacpp" ? LlamaCppSpecificConfig : never;
|
|
153
179
|
//# sourceMappingURL=AgentConfig.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Message, Usage } from "@anthropic-ai/sdk/resources";
|
|
1
|
+
import { Message, ToolUnion, Usage } from "@anthropic-ai/sdk/resources";
|
|
2
2
|
import { type ToolDefinition } from "../../tools/Tool";
|
|
3
|
+
import { type BuiltInTool } from "../../tools/BuiltInTool";
|
|
3
4
|
import { BaseAgent, BaseAgentConfig, TokenUsage } from "../BaseAgent";
|
|
4
5
|
import { History, MessageContent } from "../../history/History";
|
|
5
6
|
import { ClaudeModel } from "../model-types";
|
|
@@ -9,6 +10,18 @@ type AgentConfig = BaseAgentConfig & {
|
|
|
9
10
|
maxTokens?: number;
|
|
10
11
|
disableParallelToolUse?: boolean;
|
|
11
12
|
metadata?: Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* How `apiKey` should be presented to the Anthropic SDK — `"apiKey"` (default, `x-api-key`
|
|
15
|
+
* header) or `"oauth"` (bearer `authToken`, for OAuth access tokens like Claude Code's
|
|
16
|
+
* `sk-ant-oat...` tokens). Set explicitly; do not infer it from the token's prefix.
|
|
17
|
+
*/
|
|
18
|
+
authType?: "apiKey" | "oauth";
|
|
19
|
+
/**
|
|
20
|
+
* Provider-defined / server-side tools (e.g. web search, bash, text editor).
|
|
21
|
+
* These run on Anthropic's infrastructure rather than locally.
|
|
22
|
+
* @see lib/tools/BuiltInTool.ts
|
|
23
|
+
*/
|
|
24
|
+
builtInTools?: BuiltInTool[];
|
|
12
25
|
};
|
|
13
26
|
/**
|
|
14
27
|
* Agent for Anthropic models.
|
|
@@ -36,6 +49,11 @@ export declare class ClaudeAgent extends BaseAgent {
|
|
|
36
49
|
private currentToolCallCount;
|
|
37
50
|
constructor(config: Omit<AgentConfig, "vendor">, history?: History);
|
|
38
51
|
protected getToolDefinitions(): ToolDefinition[];
|
|
52
|
+
/**
|
|
53
|
+
* Combine locally-executed tool definitions with provider-defined
|
|
54
|
+
* (server-side) built-in tools, in the shape Anthropic's API expects.
|
|
55
|
+
*/
|
|
56
|
+
protected getAllToolDefinitions(): ToolUnion[];
|
|
39
57
|
protected process(_input: string): Promise<string>;
|
|
40
58
|
execute(input: string | MessageContent[]): Promise<string>;
|
|
41
59
|
protected handleResponse(response: Message): Promise<string>;
|
|
@@ -29,9 +29,6 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
29
29
|
super({ ...config, vendor: "anthropic" }, history);
|
|
30
30
|
/** Count of tool calls in current execution */
|
|
31
31
|
this.currentToolCallCount = 0;
|
|
32
|
-
this.client = new sdk_1.Anthropic({
|
|
33
|
-
apiKey: config.apiKey,
|
|
34
|
-
});
|
|
35
32
|
// Merge flat config (deprecated) with nested vendorConfig
|
|
36
33
|
// Flat config takes precedence for backward compatibility
|
|
37
34
|
const vendorConfig = config.vendorConfig?.anthropic || {};
|
|
@@ -39,11 +36,18 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
39
36
|
vendorConfig.disableParallelToolUse ??
|
|
40
37
|
false;
|
|
41
38
|
const metadata = config.metadata ?? vendorConfig.metadata;
|
|
39
|
+
const builtInTools = config.builtInTools ?? vendorConfig.builtInTools;
|
|
40
|
+
const authType = config.authType ?? vendorConfig.authType ?? "apiKey";
|
|
41
|
+
this.client = new sdk_1.Anthropic(authType === "oauth"
|
|
42
|
+
? { authToken: config.apiKey }
|
|
43
|
+
: { apiKey: config.apiKey });
|
|
42
44
|
this.config = {
|
|
43
45
|
model: config.model || "claude-3-5-haiku-latest",
|
|
44
46
|
maxTokens: config.maxTokens || 1024,
|
|
45
47
|
disableParallelToolUse,
|
|
46
48
|
metadata,
|
|
49
|
+
builtInTools,
|
|
50
|
+
authType,
|
|
47
51
|
apiKey: config.apiKey,
|
|
48
52
|
temperature: config.temperature,
|
|
49
53
|
topP: config.topP,
|
|
@@ -56,6 +60,16 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
56
60
|
getToolDefinitions() {
|
|
57
61
|
return Array.from(this.tools.values()).map((tool) => tool.getPrompt());
|
|
58
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Combine locally-executed tool definitions with provider-defined
|
|
65
|
+
* (server-side) built-in tools, in the shape Anthropic's API expects.
|
|
66
|
+
*/
|
|
67
|
+
getAllToolDefinitions() {
|
|
68
|
+
return [
|
|
69
|
+
...this.getToolDefinitions(),
|
|
70
|
+
...(this.config.builtInTools ?? []),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
59
73
|
async process(_input) {
|
|
60
74
|
return "";
|
|
61
75
|
}
|
|
@@ -95,7 +109,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
95
109
|
system: systemMessage,
|
|
96
110
|
max_tokens: this.config.maxTokens,
|
|
97
111
|
messages,
|
|
98
|
-
tools: this.
|
|
112
|
+
tools: this.getAllToolDefinitions(),
|
|
99
113
|
temperature: this.config.temperature,
|
|
100
114
|
top_p: this.config.topP,
|
|
101
115
|
top_k: this.config.topK,
|
|
@@ -155,7 +169,12 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
155
169
|
throw error;
|
|
156
170
|
}
|
|
157
171
|
if (response.stop_reason !== "tool_use") {
|
|
158
|
-
|
|
172
|
+
// Server-side tools (web search, bash, etc.) add their own content blocks
|
|
173
|
+
// (server_tool_use / web_search_tool_result / ...) ahead of the final
|
|
174
|
+
// text — collect every text block rather than assuming content[0] is text.
|
|
175
|
+
const textBlocks = response.content?.filter((block) => block.type === "text");
|
|
176
|
+
if (response.content && textBlocks && textBlocks.length > 0) {
|
|
177
|
+
const textContent = textBlocks.map((block) => block.text).join("\n");
|
|
159
178
|
this.emit(AgentEvent_1.AgentEvent.DONE, response, usage);
|
|
160
179
|
// Convert response to normalized format and add to history
|
|
161
180
|
const entry = transformers_1.anthropicTransformer.fromProviderContent("assistant", response.content);
|
|
@@ -166,10 +185,10 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
166
185
|
input: this.lastTokenUsage?.input_tokens || 0,
|
|
167
186
|
output: this.lastTokenUsage?.output_tokens || 0,
|
|
168
187
|
total: this.lastTokenUsage?.total_tokens || 0,
|
|
169
|
-
}, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount,
|
|
188
|
+
}, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount, textContent);
|
|
170
189
|
this.vizEventId = undefined;
|
|
171
190
|
}
|
|
172
|
-
return
|
|
191
|
+
return textContent;
|
|
173
192
|
}
|
|
174
193
|
else {
|
|
175
194
|
const error = new AgentError_1.ExecutionError(`Unexpected response format: ${JSON.stringify(response.content)}`);
|
|
@@ -199,7 +218,7 @@ class ClaudeAgent extends BaseAgent_1.BaseAgent {
|
|
|
199
218
|
system: this.history.getSystemMessage(),
|
|
200
219
|
max_tokens: this.config.maxTokens,
|
|
201
220
|
messages,
|
|
202
|
-
tools: this.
|
|
221
|
+
tools: this.getAllToolDefinitions(),
|
|
203
222
|
temperature: this.config.temperature,
|
|
204
223
|
top_p: this.config.topP,
|
|
205
224
|
top_k: this.config.topK,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { History } from "../../history/History";
|
|
2
|
+
import { OpenAICompatibleAgent, OpenAICompatibleConfig } from "../openai-compatible/OpenAICompatibleAgent";
|
|
3
|
+
import { LlamaCppModel } from "../model-types";
|
|
4
|
+
type LlamaCppConfig = Omit<OpenAICompatibleConfig, "baseURL" | "model" | "vendor"> & {
|
|
5
|
+
/** Base URL of the llama.cpp server's OpenAI-compatible API (default: `http://localhost:8080/v1`) */
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
model?: LlamaCppModel;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Agent for locally-hosted models served by a llama.cpp server (`llama-server`),
|
|
11
|
+
* which exposes an OpenAI-compatible `/v1/chat/completions` API.
|
|
12
|
+
*
|
|
13
|
+
* Requires the `openai` package as a peer dependency and a running llama.cpp server.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const agent = new LlamaCppAgent({
|
|
18
|
+
* id: "1",
|
|
19
|
+
* name: "Assistant",
|
|
20
|
+
* description: "A helpful assistant",
|
|
21
|
+
* baseURL: "http://localhost:8080/v1",
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const response = await agent.execute("Hello!");
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example List available models
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const models = await agent.listModels();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class LlamaCppAgent extends OpenAICompatibleAgent {
|
|
33
|
+
constructor(config: LlamaCppConfig, history?: History);
|
|
34
|
+
protected getVendorName(): string;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=LlamaCppAgent.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LlamaCppAgent = void 0;
|
|
4
|
+
const OpenAICompatibleAgent_1 = require("../openai-compatible/OpenAICompatibleAgent");
|
|
5
|
+
/**
|
|
6
|
+
* Agent for locally-hosted models served by a llama.cpp server (`llama-server`),
|
|
7
|
+
* which exposes an OpenAI-compatible `/v1/chat/completions` API.
|
|
8
|
+
*
|
|
9
|
+
* Requires the `openai` package as a peer dependency and a running llama.cpp server.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const agent = new LlamaCppAgent({
|
|
14
|
+
* id: "1",
|
|
15
|
+
* name: "Assistant",
|
|
16
|
+
* description: "A helpful assistant",
|
|
17
|
+
* baseURL: "http://localhost:8080/v1",
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* const response = await agent.execute("Hello!");
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example List available models
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const models = await agent.listModels();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class LlamaCppAgent extends OpenAICompatibleAgent_1.OpenAICompatibleAgent {
|
|
29
|
+
constructor(config, history) {
|
|
30
|
+
const vendorConfig = config.vendorConfig?.llamacpp || {};
|
|
31
|
+
const baseURL = config.baseURL ?? vendorConfig.baseURL ?? "http://localhost:8080/v1";
|
|
32
|
+
super({
|
|
33
|
+
...config,
|
|
34
|
+
vendor: "llamacpp",
|
|
35
|
+
baseURL,
|
|
36
|
+
model: config.model ?? "default",
|
|
37
|
+
}, history);
|
|
38
|
+
}
|
|
39
|
+
getVendorName() {
|
|
40
|
+
return "llama.cpp";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.LlamaCppAgent = LlamaCppAgent;
|
|
44
|
+
//# sourceMappingURL=LlamaCppAgent.js.map
|
|
@@ -27,6 +27,13 @@ export type MistralModel = "mistral-large-latest" | "mistral-small-latest" | "mi
|
|
|
27
27
|
* @see https://ollama.com/library
|
|
28
28
|
*/
|
|
29
29
|
export type OllamaModel = "llama3.2" | "llama3.2:1b" | "llama3.1" | "llama3.1:70b" | "llama3" | "mistral" | "mistral-nemo" | "mixtral" | "qwen2.5" | "qwen2.5:7b" | "qwen2.5:72b" | "qwen2.5-coder" | "gemma2" | "gemma2:27b" | "phi3" | "phi4" | "deepseek-r1" | "deepseek-r1:7b" | "deepseek-r1:14b" | "deepseek-r1:70b" | "codellama" | (string & {});
|
|
30
|
+
/**
|
|
31
|
+
* Models served by a local llama.cpp server (`llama-server`).
|
|
32
|
+
* The model is identified by the GGUF file/alias loaded by the server, so any
|
|
33
|
+
* string is accepted — the values below are common conventions.
|
|
34
|
+
* @see https://github.com/ggml-org/llama.cpp/tree/master/tools/server
|
|
35
|
+
*/
|
|
36
|
+
export type LlamaCppModel = "default" | "gpt-oss-20b" | "gpt-oss-120b" | "llama-3.1-8b-instruct" | "llama-3.2-3b-instruct" | "qwen2.5-7b-instruct" | "qwen2.5-coder-7b-instruct" | "mistral-7b-instruct" | "phi-4" | "deepseek-r1-distill-qwen-7b" | (string & {});
|
|
30
37
|
/**
|
|
31
38
|
* Supported OpenAI models.
|
|
32
39
|
* You can also provide any custom string for newer models not yet listed.
|
|
@@ -2,7 +2,7 @@ import { BaseAgent, BaseAgentConfig, TokenUsage } from "../BaseAgent";
|
|
|
2
2
|
import { History, MessageContent } from "../../history/History";
|
|
3
3
|
import { OllamaModel } from "../model-types";
|
|
4
4
|
type AgentConfig = BaseAgentConfig & {
|
|
5
|
-
/** Ollama server URL (default: http://localhost:11434) */
|
|
5
|
+
/** Ollama server URL (default: `http://localhost:11434`) */
|
|
6
6
|
host?: string;
|
|
7
7
|
model?: OllamaModel;
|
|
8
8
|
maxTokens?: number;
|
|
@@ -56,6 +56,10 @@ export declare class OllamaAgent extends BaseAgent {
|
|
|
56
56
|
private _client;
|
|
57
57
|
constructor(config: Omit<AgentConfig, "vendor">, history?: History);
|
|
58
58
|
private getClient;
|
|
59
|
+
/**
|
|
60
|
+
* List the models currently available on the Ollama server.
|
|
61
|
+
*/
|
|
62
|
+
listModels(): Promise<OllamaModelInfo[]>;
|
|
59
63
|
protected getToolDefinitions(): OllamaToolDefinition[];
|
|
60
64
|
protected process(_input: string): Promise<string>;
|
|
61
65
|
execute(input: string | MessageContent[]): Promise<string>;
|
|
@@ -65,5 +69,23 @@ export declare class OllamaAgent extends BaseAgent {
|
|
|
65
69
|
private handleToolCalls;
|
|
66
70
|
protected parseUsage(input: unknown): TokenUsage;
|
|
67
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* A model available on the Ollama server, as returned by `client.list()`.
|
|
74
|
+
*/
|
|
75
|
+
export type OllamaModelInfo = {
|
|
76
|
+
name: string;
|
|
77
|
+
model: string;
|
|
78
|
+
modified_at: Date;
|
|
79
|
+
size: number;
|
|
80
|
+
digest: string;
|
|
81
|
+
details: {
|
|
82
|
+
parent_model: string;
|
|
83
|
+
format: string;
|
|
84
|
+
family: string;
|
|
85
|
+
families: string[];
|
|
86
|
+
parameter_size: string;
|
|
87
|
+
quantization_level: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
68
90
|
export {};
|
|
69
91
|
//# sourceMappingURL=OllamaAgent.d.ts.map
|
|
@@ -107,6 +107,19 @@ class OllamaAgent extends BaseAgent_1.BaseAgent {
|
|
|
107
107
|
}
|
|
108
108
|
return this._client;
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* List the models currently available on the Ollama server.
|
|
112
|
+
*/
|
|
113
|
+
async listModels() {
|
|
114
|
+
try {
|
|
115
|
+
const client = await this.getClient();
|
|
116
|
+
const response = await client.list();
|
|
117
|
+
return response.models;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new AgentError_1.ExecutionError(`Failed to list Ollama models: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
110
123
|
getToolDefinitions() {
|
|
111
124
|
return Array.from(this.tools.values()).map((tool) => ({
|
|
112
125
|
type: "function",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { ChatCompletion, ChatCompletionTool } from "openai/resources/chat/completions";
|
|
3
|
+
import { Model } from "openai/resources/models";
|
|
4
|
+
import { BaseAgent, BaseAgentConfig, TokenUsage } from "../BaseAgent";
|
|
5
|
+
import { AgentVendor } from "../AgentConfig";
|
|
6
|
+
import { History, MessageContent } from "../../history/History";
|
|
7
|
+
export type OpenAICompatibleConfig = BaseAgentConfig & {
|
|
8
|
+
/** Base URL of the OpenAI-compatible `/v1` endpoint (required) */
|
|
9
|
+
baseURL: string;
|
|
10
|
+
model?: string;
|
|
11
|
+
maxTokens?: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Abstract base class for agents that talk to any OpenAI-compatible
|
|
15
|
+
* `/v1/chat/completions` endpoint (llama.cpp, vLLM, LM Studio, etc.).
|
|
16
|
+
*
|
|
17
|
+
* Subclasses must implement:
|
|
18
|
+
* - `getVendorName()` — human-readable name used in error messages (e.g. `"llama.cpp"`)
|
|
19
|
+
*
|
|
20
|
+
* Subclasses may override:
|
|
21
|
+
* - `buildExtraRequestParams()` — extra fields merged into the completions request
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class OpenAICompatibleAgent extends BaseAgent {
|
|
24
|
+
protected client: OpenAI;
|
|
25
|
+
protected config: Partial<OpenAICompatibleConfig>;
|
|
26
|
+
lastTokenUsage?: TokenUsage;
|
|
27
|
+
private vizEventId?;
|
|
28
|
+
private currentToolCallCount;
|
|
29
|
+
constructor(config: OpenAICompatibleConfig & {
|
|
30
|
+
vendor: AgentVendor;
|
|
31
|
+
}, history?: History);
|
|
32
|
+
/** Human-readable vendor name used in error messages (e.g. `"llama.cpp"`). */
|
|
33
|
+
protected abstract getVendorName(): string;
|
|
34
|
+
/** Extra fields to merge into the chat completions request. Override for vendor-specific params. */
|
|
35
|
+
protected buildExtraRequestParams(): Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* List the models available on the server via the `/v1/models` endpoint.
|
|
38
|
+
*/
|
|
39
|
+
listModels(): Promise<Model[]>;
|
|
40
|
+
protected getToolDefinitions(): ChatCompletionTool[];
|
|
41
|
+
protected process(_input: string): Promise<string>;
|
|
42
|
+
execute(input: string | MessageContent[]): Promise<string>;
|
|
43
|
+
private callProvider;
|
|
44
|
+
protected handleResponse(response: ChatCompletion): Promise<string>;
|
|
45
|
+
private handleToolCalls;
|
|
46
|
+
protected parseUsage(response: ChatCompletion): TokenUsage;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=OpenAICompatibleAgent.d.ts.map
|