@agentionai/agents 0.12.0-beta → 0.13.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 +63 -7
- package/dist/agents/Agent.d.ts +15 -3
- package/dist/agents/Agent.js +8 -0
- package/dist/agents/AgentConfig.d.ts +38 -2
- package/dist/agents/anthropic/ClaudeAgent.d.ts +19 -1
- package/dist/agents/anthropic/ClaudeAgent.js +27 -8
- package/dist/agents/llamacpp/LlamaCppAgent.d.ts +60 -0
- package/dist/agents/llamacpp/LlamaCppAgent.js +262 -0
- package/dist/agents/model-types.d.ts +14 -1
- package/dist/agents/ollama/OllamaAgent.d.ts +91 -0
- package/dist/agents/ollama/OllamaAgent.js +317 -0
- package/dist/chunkers/index.d.ts +0 -1
- package/dist/chunkers/index.js +1 -3
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/history/transformers.d.ts +100 -0
- package/dist/history/transformers.js +195 -1
- package/dist/history/types.d.ts +15 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +8 -1
- package/dist/ingestion/IngestionPipeline.d.ts +1 -73
- package/dist/ingestion/IngestionPipeline.js +1 -110
- package/dist/llamacpp.d.ts +4 -0
- package/dist/llamacpp.js +24 -0
- package/dist/ollama.d.ts +4 -0
- package/dist/ollama.js +24 -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 +10 -42
- package/dist/chunkers/ElementChunker.d.ts +0 -100
- package/dist/chunkers/ElementChunker.js +0 -242
- package/dist/parsers/DocumentParser.d.ts +0 -36
- package/dist/parsers/DocumentParser.js +0 -35
- package/dist/parsers/LlamaIndexParser.d.ts +0 -58
- package/dist/parsers/LlamaIndexParser.js +0 -71
- package/dist/parsers/OllamaOCRParser.d.ts +0 -98
- package/dist/parsers/OllamaOCRParser.js +0 -203
- package/dist/parsers/UnstructuredAPIParser.d.ts +0 -57
- package/dist/parsers/UnstructuredAPIParser.js +0 -131
- package/dist/parsers/UnstructuredLocalParser.d.ts +0 -42
- package/dist/parsers/UnstructuredLocalParser.js +0 -118
- package/dist/parsers/index.d.ts +0 -3
- package/dist/parsers/index.js +0 -6
- package/dist/parsers/types.d.ts +0 -50
- package/dist/parsers/types.js +0 -3
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,58 @@ 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)
|
|
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
|
+
### Built-In Tools
|
|
155
|
+
|
|
156
|
+
Use a provider's own server-side tools (executed by the provider, not locally) alongside your custom tools:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { ClaudeAgent } from '@agentionai/agents/claude';
|
|
160
|
+
import { webSearchTool } from '@agentionai/agents/claude';
|
|
161
|
+
|
|
162
|
+
const agent = new ClaudeAgent({
|
|
163
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
164
|
+
id: 'researcher',
|
|
165
|
+
name: 'Researcher',
|
|
166
|
+
description: 'You are a helpful research assistant with web access.',
|
|
167
|
+
model: 'claude-sonnet-4-6',
|
|
168
|
+
builtInTools: [webSearchTool({ maxUses: 5 })],
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const response = await agent.execute('What happened in the news today?');
|
|
172
|
+
```
|
|
173
|
+
|
|
118
174
|
### Multi-Agent Pipeline
|
|
119
175
|
|
|
120
176
|
Chain agents together with different providers and models:
|
|
@@ -216,12 +272,12 @@ const response2 = await agent.execute([
|
|
|
216
272
|
## Core Concepts
|
|
217
273
|
|
|
218
274
|
### Agents
|
|
219
|
-
Unified interface across Claude, OpenAI, Gemini, and
|
|
275
|
+
Unified interface across Claude, OpenAI, Gemini, Mistral, and local models via Ollama and llama.cpp. Tools, history, and token tracking built-in.
|
|
220
276
|
|
|
221
277
|
[Learn more →](https://docs.agention.ai/guide/agents)
|
|
222
278
|
|
|
223
279
|
### Tools
|
|
224
|
-
JSON Schema + handler pattern. Unique capability: wrap any agent as a tool for delegation hierarchies.
|
|
280
|
+
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
281
|
|
|
226
282
|
[Learn more →](https://docs.agention.ai/guide/tools)
|
|
227
283
|
|
package/dist/agents/Agent.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import { BaseAgentConfig } from "./BaseAgent";
|
|
|
4
4
|
import { OpenAiAgent } from "./openai/OpenAiAgent";
|
|
5
5
|
import { GeminiAgent } from "./google/GeminiAgent";
|
|
6
6
|
import { MistralAgent } from "./mistral/MistralAgent";
|
|
7
|
-
import {
|
|
7
|
+
import { OllamaAgent } from "./ollama/OllamaAgent";
|
|
8
|
+
import { LlamaCppAgent } from "./llamacpp/LlamaCppAgent";
|
|
9
|
+
import { ClaudeModel, OpenAIModel, GeminiModel, MistralModel, OllamaModel, LlamaCppModel } from "./model-types";
|
|
8
10
|
type ClaudeAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
9
11
|
vendor: "anthropic";
|
|
10
12
|
model?: ClaudeModel;
|
|
@@ -21,9 +23,19 @@ type MistralAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
|
21
23
|
vendor: "mistral";
|
|
22
24
|
model?: MistralModel;
|
|
23
25
|
};
|
|
24
|
-
type
|
|
26
|
+
type OllamaAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
27
|
+
vendor: "ollama";
|
|
28
|
+
model?: OllamaModel;
|
|
29
|
+
host?: string;
|
|
30
|
+
};
|
|
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;
|
|
25
37
|
export declare class Agent {
|
|
26
|
-
static create(config: AgentConfig, history?: History): ClaudeAgent | GeminiAgent | OpenAiAgent | MistralAgent;
|
|
38
|
+
static create(config: AgentConfig, history?: History): ClaudeAgent | GeminiAgent | OpenAiAgent | MistralAgent | OllamaAgent | LlamaCppAgent;
|
|
27
39
|
}
|
|
28
40
|
export {};
|
|
29
41
|
//# sourceMappingURL=Agent.d.ts.map
|
package/dist/agents/Agent.js
CHANGED
|
@@ -5,6 +5,8 @@ const ClaudeAgent_1 = require("./anthropic/ClaudeAgent");
|
|
|
5
5
|
const OpenAiAgent_1 = require("./openai/OpenAiAgent");
|
|
6
6
|
const GeminiAgent_1 = require("./google/GeminiAgent");
|
|
7
7
|
const MistralAgent_1 = require("./mistral/MistralAgent");
|
|
8
|
+
const OllamaAgent_1 = require("./ollama/OllamaAgent");
|
|
9
|
+
const LlamaCppAgent_1 = require("./llamacpp/LlamaCppAgent");
|
|
8
10
|
class Agent {
|
|
9
11
|
static create(config, history) {
|
|
10
12
|
if (config.vendor === "anthropic") {
|
|
@@ -19,6 +21,12 @@ class Agent {
|
|
|
19
21
|
else if (config.vendor === "mistral") {
|
|
20
22
|
return new MistralAgent_1.MistralAgent(config, history);
|
|
21
23
|
}
|
|
24
|
+
else if (config.vendor === "ollama") {
|
|
25
|
+
return new OllamaAgent_1.OllamaAgent(config, history);
|
|
26
|
+
}
|
|
27
|
+
else if (config.vendor === "llamacpp") {
|
|
28
|
+
return new LlamaCppAgent_1.LlamaCppAgent(config, history);
|
|
29
|
+
}
|
|
22
30
|
else {
|
|
23
31
|
throw new Error("No vendor defined");
|
|
24
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";
|
|
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
|
|
@@ -86,6 +102,20 @@ export interface GeminiSpecificConfig {
|
|
|
86
102
|
responseMimeType?: string;
|
|
87
103
|
responseSchema?: any;
|
|
88
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Vendor-specific configuration for Ollama (local)
|
|
107
|
+
*/
|
|
108
|
+
export interface OllamaSpecificConfig {
|
|
109
|
+
/** Ollama server URL (default: `http://localhost:11434`) */
|
|
110
|
+
host?: string;
|
|
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
|
+
}
|
|
89
119
|
/**
|
|
90
120
|
* Generic vendor-specific configuration container
|
|
91
121
|
* This allows any vendor to add custom config without modifying base types
|
|
@@ -95,6 +125,8 @@ export interface VendorSpecificConfig {
|
|
|
95
125
|
openai?: OpenAISpecificConfig;
|
|
96
126
|
mistral?: MistralSpecificConfig;
|
|
97
127
|
gemini?: GeminiSpecificConfig;
|
|
128
|
+
ollama?: OllamaSpecificConfig;
|
|
129
|
+
llamacpp?: LlamaCppSpecificConfig;
|
|
98
130
|
}
|
|
99
131
|
/**
|
|
100
132
|
* Complete agent configuration with vendor-specific extensions
|
|
@@ -134,10 +166,14 @@ export type TypedAgentConfig<V extends AgentVendor> = CommonAgentConfig & {
|
|
|
134
166
|
mistral?: MistralSpecificConfig;
|
|
135
167
|
} : V extends "gemini" ? {
|
|
136
168
|
gemini?: GeminiSpecificConfig;
|
|
169
|
+
} : V extends "ollama" ? {
|
|
170
|
+
ollama?: OllamaSpecificConfig;
|
|
171
|
+
} : V extends "llamacpp" ? {
|
|
172
|
+
llamacpp?: LlamaCppSpecificConfig;
|
|
137
173
|
} : never;
|
|
138
174
|
};
|
|
139
175
|
/**
|
|
140
176
|
* Helper type to extract vendor-specific config for a given vendor
|
|
141
177
|
*/
|
|
142
|
-
export type VendorConfigFor<V extends AgentVendor> = V extends "anthropic" ? ClaudeSpecificConfig : V extends "openai" ? OpenAISpecificConfig : V extends "mistral" ? MistralSpecificConfig : V extends "gemini" ? GeminiSpecificConfig : 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;
|
|
143
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,60 @@
|
|
|
1
|
+
import { ChatCompletion, ChatCompletionTool } from "openai/resources/chat/completions";
|
|
2
|
+
import { Model } from "openai/resources/models";
|
|
3
|
+
import { BaseAgent, BaseAgentConfig, TokenUsage } from "../BaseAgent";
|
|
4
|
+
import { History, MessageContent } from "../../history/History";
|
|
5
|
+
import { LlamaCppModel } from "../model-types";
|
|
6
|
+
type AgentConfig = BaseAgentConfig & {
|
|
7
|
+
/** Base URL of the llama.cpp server's OpenAI-compatible API (default: `http://localhost:8080/v1`) */
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
model?: LlamaCppModel;
|
|
10
|
+
maxTokens?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Agent for locally-hosted models served by a llama.cpp server (`llama-server`),
|
|
14
|
+
* which exposes an OpenAI-compatible `/v1/chat/completions` API.
|
|
15
|
+
*
|
|
16
|
+
* Requires the `openai` package as a peer dependency and a running llama.cpp server.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const agent = new LlamaCppAgent({
|
|
21
|
+
* id: "1",
|
|
22
|
+
* name: "Assistant",
|
|
23
|
+
* description: "A helpful assistant",
|
|
24
|
+
* apiKey: "",
|
|
25
|
+
* baseURL: "http://localhost:8080/v1",
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const response = await agent.execute("Hello!");
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example List available models
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const models = await agent.listModels();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class LlamaCppAgent extends BaseAgent {
|
|
37
|
+
private client;
|
|
38
|
+
protected config: Partial<AgentConfig>;
|
|
39
|
+
/** Token usage from the last execution (for metrics tracking) */
|
|
40
|
+
lastTokenUsage?: TokenUsage;
|
|
41
|
+
/** Current visualization event ID */
|
|
42
|
+
private vizEventId?;
|
|
43
|
+
/** Count of tool calls in current execution */
|
|
44
|
+
private currentToolCallCount;
|
|
45
|
+
constructor(config: Omit<AgentConfig, "vendor">, history?: History);
|
|
46
|
+
/**
|
|
47
|
+
* List the models currently available on the llama.cpp server (via its
|
|
48
|
+
* OpenAI-compatible `/v1/models` endpoint).
|
|
49
|
+
*/
|
|
50
|
+
listModels(): Promise<Model[]>;
|
|
51
|
+
protected getToolDefinitions(): ChatCompletionTool[];
|
|
52
|
+
protected process(_input: string): Promise<string>;
|
|
53
|
+
execute(input: string | MessageContent[]): Promise<string>;
|
|
54
|
+
private callLlamaCpp;
|
|
55
|
+
protected handleResponse(response: ChatCompletion): Promise<string>;
|
|
56
|
+
private handleToolCalls;
|
|
57
|
+
protected parseUsage(response: ChatCompletion): TokenUsage;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=LlamaCppAgent.d.ts.map
|