@agentionai/agents 0.12.0 → 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 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'; // Requires @anthropic-ai/sdk
60
- import { OpenAiAgent } from '@agentionai/agents/openai'; // Requires openai
61
- import { GeminiAgent } from '@agentionai/agents/gemini'; // Requires @google/generative-ai
62
- import { MistralAgent } from '@agentionai/agents/mistral'; // Requires @mistralai/mistralai
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 Mistral. Tools, history, and token tracking built-in.
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
 
@@ -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 { ClaudeModel, OpenAIModel, GeminiModel, MistralModel, OllamaModel } from "./model-types";
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 AgentConfig = ClaudeAgentConfig | OpenAIAgentConfig | GeminiAgentConfig | MistralAgentConfig | OllamaAgentConfig;
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
@@ -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.getToolDefinitions(),
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
- if (response.content && response.content[0]?.type === "text") {
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, response.content[0].text);
188
+ }, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount, textContent);
170
189
  this.vizEventId = undefined;
171
190
  }
172
- return response.content[0].text;
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.getToolDefinitions(),
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
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LlamaCppAgent = void 0;
7
+ const openai_1 = __importDefault(require("openai"));
8
+ const BaseAgent_1 = require("../BaseAgent");
9
+ const AgentEvent_1 = require("../AgentEvent");
10
+ const AgentError_1 = require("../errors/AgentError");
11
+ const transformers_1 = require("../../history/transformers");
12
+ const VizReporter_1 = require("../../viz/VizReporter");
13
+ const VizConfig_1 = require("../../viz/VizConfig");
14
+ /**
15
+ * Agent for locally-hosted models served by a llama.cpp server (`llama-server`),
16
+ * which exposes an OpenAI-compatible `/v1/chat/completions` API.
17
+ *
18
+ * Requires the `openai` package as a peer dependency and a running llama.cpp server.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const agent = new LlamaCppAgent({
23
+ * id: "1",
24
+ * name: "Assistant",
25
+ * description: "A helpful assistant",
26
+ * apiKey: "",
27
+ * baseURL: "http://localhost:8080/v1",
28
+ * });
29
+ *
30
+ * const response = await agent.execute("Hello!");
31
+ * ```
32
+ *
33
+ * @example List available models
34
+ * ```typescript
35
+ * const models = await agent.listModels();
36
+ * ```
37
+ */
38
+ class LlamaCppAgent extends BaseAgent_1.BaseAgent {
39
+ constructor(config, history) {
40
+ super({ ...config, vendor: "llamacpp" }, history);
41
+ /** Count of tool calls in current execution */
42
+ this.currentToolCallCount = 0;
43
+ const vendorConfig = config.vendorConfig?.llamacpp || {};
44
+ const baseURL = config.baseURL ?? vendorConfig.baseURL ?? "http://localhost:8080/v1";
45
+ this.client = new openai_1.default({
46
+ apiKey: config.apiKey || "not-needed",
47
+ baseURL,
48
+ });
49
+ this.config = {
50
+ model: config.model || "default",
51
+ baseURL,
52
+ maxTokens: config.maxTokens,
53
+ temperature: config.temperature,
54
+ topP: config.topP,
55
+ stopSequences: config.stopSequences,
56
+ seed: config.seed,
57
+ presencePenalty: config.presencePenalty,
58
+ frequencyPenalty: config.frequencyPenalty,
59
+ apiKey: config.apiKey,
60
+ };
61
+ this.addSystemMessage(this.getSystemMessage());
62
+ }
63
+ /**
64
+ * List the models currently available on the llama.cpp server (via its
65
+ * OpenAI-compatible `/v1/models` endpoint).
66
+ */
67
+ async listModels() {
68
+ try {
69
+ const page = await this.client.models.list();
70
+ return page.data;
71
+ }
72
+ catch (error) {
73
+ throw new AgentError_1.ExecutionError(`Failed to list llama.cpp models: ${error instanceof Error ? error.message : "Unknown error"}`);
74
+ }
75
+ }
76
+ getToolDefinitions() {
77
+ return Array.from(this.tools.values()).map((tool) => {
78
+ const prompt = tool.getPrompt();
79
+ return {
80
+ type: "function",
81
+ function: {
82
+ name: prompt.name,
83
+ description: prompt.description,
84
+ parameters: prompt.input_schema,
85
+ },
86
+ };
87
+ });
88
+ }
89
+ async process(_input) {
90
+ return "";
91
+ }
92
+ async execute(input) {
93
+ this.emit(AgentEvent_1.AgentEvent.BEFORE_EXECUTE, input);
94
+ this.lastTokenUsage = undefined;
95
+ this.currentToolCallCount = 0;
96
+ const inputPreview = typeof input === "string" ? input : JSON.stringify(input);
97
+ if (VizConfig_1.vizConfig.isEnabled()) {
98
+ this.vizEventId = VizReporter_1.vizReporter.agentStart(this.id, this.name, this.config.model, "llamacpp", inputPreview);
99
+ }
100
+ if (this.history.transient) {
101
+ this.history.clear();
102
+ this.addSystemMessage(this.getSystemMessage());
103
+ }
104
+ if (typeof input === "string") {
105
+ this.addTextToHistory("user", input);
106
+ }
107
+ else {
108
+ this.addMessageToHistory("user", input);
109
+ }
110
+ this.history.setSessionAnchor();
111
+ this.history.beginExecution();
112
+ try {
113
+ const response = await this.callLlamaCpp();
114
+ this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, response);
115
+ return await this.handleResponse(response);
116
+ }
117
+ catch (error) {
118
+ if (error instanceof openai_1.default.APIError) {
119
+ const apiError = new AgentError_1.ApiError(`llama.cpp API error: ${error.message}`, error.status, error);
120
+ this.emit(AgentEvent_1.AgentEvent.ERROR, apiError);
121
+ if (this.vizEventId) {
122
+ VizReporter_1.vizReporter.agentError(this.vizEventId, "ApiError", apiError.message, error.status === 429);
123
+ this.vizEventId = undefined;
124
+ }
125
+ throw apiError;
126
+ }
127
+ if (error instanceof AgentError_1.ExecutionError || error instanceof AgentError_1.ApiError) {
128
+ this.emit(AgentEvent_1.AgentEvent.ERROR, error);
129
+ if (this.vizEventId) {
130
+ VizReporter_1.vizReporter.agentError(this.vizEventId, error.constructor.name, error.message, false);
131
+ this.vizEventId = undefined;
132
+ }
133
+ throw error;
134
+ }
135
+ const executionError = new AgentError_1.ExecutionError(`llama.cpp error: ${error instanceof Error ? error.message : "Unknown error"}`);
136
+ this.emit(AgentEvent_1.AgentEvent.ERROR, executionError);
137
+ if (this.vizEventId) {
138
+ VizReporter_1.vizReporter.agentError(this.vizEventId, "ExecutionError", executionError.message, false);
139
+ this.vizEventId = undefined;
140
+ }
141
+ throw executionError;
142
+ }
143
+ finally {
144
+ this.history.endExecution();
145
+ }
146
+ }
147
+ async callLlamaCpp() {
148
+ const messages = transformers_1.chatCompletionsTransformer.toProvider(this.history.getEntries());
149
+ const tools = this.tools.size > 0 ? this.getToolDefinitions() : undefined;
150
+ return this.client.chat.completions.create({
151
+ model: this.config.model,
152
+ messages,
153
+ tools,
154
+ stream: false,
155
+ max_tokens: this.config.maxTokens,
156
+ temperature: this.config.temperature,
157
+ top_p: this.config.topP,
158
+ stop: this.config.stopSequences,
159
+ seed: this.config.seed,
160
+ presence_penalty: this.config.presencePenalty,
161
+ frequency_penalty: this.config.frequencyPenalty,
162
+ });
163
+ }
164
+ async handleResponse(response) {
165
+ const usage = this.parseUsage(response);
166
+ if (this.lastTokenUsage) {
167
+ this.lastTokenUsage.input_tokens += usage.input_tokens;
168
+ this.lastTokenUsage.output_tokens += usage.output_tokens;
169
+ this.lastTokenUsage.total_tokens += usage.total_tokens;
170
+ }
171
+ else {
172
+ this.lastTokenUsage = { ...usage };
173
+ }
174
+ const choice = response.choices[0];
175
+ const message = choice.message;
176
+ if (choice.finish_reason === "length") {
177
+ const error = new AgentError_1.MaxTokensExceededError("Response exceeded maximum token limit", this.config.maxTokens || 1024);
178
+ this.emit(AgentEvent_1.AgentEvent.MAX_TOKENS_EXCEEDED, error);
179
+ this.emit(AgentEvent_1.AgentEvent.ERROR, error);
180
+ if (this.vizEventId) {
181
+ VizReporter_1.vizReporter.agentError(this.vizEventId, "MaxTokensExceededError", error.message, false);
182
+ this.vizEventId = undefined;
183
+ }
184
+ throw error;
185
+ }
186
+ const hasToolCalls = message.tool_calls && message.tool_calls.length > 0;
187
+ if (!hasToolCalls) {
188
+ const textContent = message.content || "";
189
+ const entry = transformers_1.chatCompletionsTransformer.fromProviderMessage(message);
190
+ this.addToHistory(entry);
191
+ this.emit(AgentEvent_1.AgentEvent.DONE, message, usage);
192
+ if (this.vizEventId) {
193
+ VizReporter_1.vizReporter.agentComplete(this.vizEventId, {
194
+ input: this.lastTokenUsage?.input_tokens || 0,
195
+ output: this.lastTokenUsage?.output_tokens || 0,
196
+ total: this.lastTokenUsage?.total_tokens || 0,
197
+ }, "end_turn", this.currentToolCallCount > 0, this.currentToolCallCount, textContent);
198
+ this.vizEventId = undefined;
199
+ }
200
+ return textContent;
201
+ }
202
+ // Tool calls detected
203
+ const toolCalls = message.tool_calls;
204
+ this.emit(AgentEvent_1.AgentEvent.TOOL_USE, toolCalls);
205
+ this.currentToolCallCount += toolCalls.length;
206
+ const assistantEntry = transformers_1.chatCompletionsTransformer.fromProviderMessage(message);
207
+ this.addToHistory(assistantEntry);
208
+ const toolResults = await this.handleToolCalls(toolCalls);
209
+ for (const result of toolResults) {
210
+ const resultEntry = transformers_1.chatCompletionsTransformer.toolResultEntry(result.toolCallId, result.content);
211
+ this.addToHistory(resultEntry);
212
+ }
213
+ // Continue conversation with tool results
214
+ try {
215
+ const newResponse = await this.callLlamaCpp();
216
+ this.emit(AgentEvent_1.AgentEvent.AFTER_EXECUTE, newResponse);
217
+ return this.handleResponse(newResponse);
218
+ }
219
+ catch (error) {
220
+ const executionError = new AgentError_1.ExecutionError(`llama.cpp error during tool response: ${error instanceof Error ? error.message : "Unknown error"}`);
221
+ this.emit(AgentEvent_1.AgentEvent.ERROR, executionError);
222
+ throw executionError;
223
+ }
224
+ }
225
+ async handleToolCalls(toolCalls) {
226
+ return Promise.all(toolCalls.map(async (toolCall) => {
227
+ const toolName = toolCall.type === "function" ? toolCall.function.name : "";
228
+ const tool = this.tools.get(toolName);
229
+ const toolCallId = toolCall.id;
230
+ if (toolCall.type !== "function" || !tool) {
231
+ const errorMessage = `Tool '${toolName}' not found`;
232
+ const error = new AgentError_1.ToolExecutionError(errorMessage, toolName, toolCall.type === "function" ? toolCall.function.arguments : undefined);
233
+ this.emit(AgentEvent_1.AgentEvent.TOOL_ERROR, error);
234
+ return { toolCallId, content: errorMessage };
235
+ }
236
+ try {
237
+ const args = JSON.parse(toolCall.function.arguments || "{}");
238
+ const result = await tool.execute(this.getId(), this.getName(), args, toolCallId, this.config.model, "llamacpp");
239
+ return { toolCallId, content: JSON.stringify(result) };
240
+ }
241
+ catch (error) {
242
+ const errorMessage = `Error executing tool '${toolName}': ${error instanceof Error ? error.message : "Unknown error"}`;
243
+ if (this.debug) {
244
+ console.error(errorMessage);
245
+ }
246
+ const toolError = new AgentError_1.ToolExecutionError(errorMessage, toolName, toolCall.function.arguments);
247
+ this.emit(AgentEvent_1.AgentEvent.TOOL_ERROR, toolError);
248
+ return { toolCallId, content: errorMessage };
249
+ }
250
+ }));
251
+ }
252
+ parseUsage(response) {
253
+ const usage = response.usage;
254
+ return {
255
+ input_tokens: usage?.prompt_tokens ?? 0,
256
+ output_tokens: usage?.completion_tokens ?? 0,
257
+ total_tokens: usage?.total_tokens ?? 0,
258
+ };
259
+ }
260
+ }
261
+ exports.LlamaCppAgent = LlamaCppAgent;
262
+ //# 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",
package/dist/core.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./history/History";
7
7
  export * from "./history/types";
8
8
  export * from "./graph/AgentGraph";
9
9
  export * from "./tools/Tool";
10
+ export * from "./tools/BuiltInTool";
10
11
  export * from "./mcp";
11
12
  export * from "./viz";
12
13
  export * from "./embeddings";
package/dist/core.js CHANGED
@@ -29,6 +29,7 @@ __exportStar(require("./history/types"), exports);
29
29
  __exportStar(require("./graph/AgentGraph"), exports);
30
30
  // Tools
31
31
  __exportStar(require("./tools/Tool"), exports);
32
+ __exportStar(require("./tools/BuiltInTool"), exports);
32
33
  // MCP (Model Context Protocol)
33
34
  __exportStar(require("./mcp"), exports);
34
35
  // Visualization
@@ -134,5 +134,69 @@ export declare const ollamaTransformer: {
134
134
  */
135
135
  toolResultEntry(tool_call_id: string, output: string): HistoryEntry;
136
136
  };
137
+ /**
138
+ * Convert normalized entries to/from the OpenAI Chat Completions message format
139
+ * (`/v1/chat/completions`). Used by `LlamaCppAgent` and any other agent that
140
+ * targets an OpenAI-compatible chat-completions endpoint.
141
+ */
142
+ export declare const chatCompletionsTransformer: {
143
+ /**
144
+ * Convert normalized entries to Chat Completions message format.
145
+ * Tool results become role:"tool" messages; tool calls are embedded in assistant messages.
146
+ */
147
+ toProvider(entries: HistoryEntry[]): ChatCompletionMessage[];
148
+ /**
149
+ * Convert a Chat Completions response message to a normalized HistoryEntry.
150
+ */
151
+ fromProviderMessage(message: ChatCompletionResponseMessage): HistoryEntry;
152
+ /**
153
+ * Create a normalized tool result entry for a Chat Completions tool call
154
+ */
155
+ toolResultEntry(tool_call_id: string, output: string): HistoryEntry;
156
+ };
157
+ type ChatCompletionToolCallParam = {
158
+ id: string;
159
+ type: "function";
160
+ function: {
161
+ name: string;
162
+ arguments: string;
163
+ };
164
+ };
165
+ type ChatCompletionContentPart = {
166
+ type: "text";
167
+ text: string;
168
+ } | {
169
+ type: "image_url";
170
+ image_url: {
171
+ url: string;
172
+ detail?: "auto" | "low" | "high";
173
+ };
174
+ };
175
+ type ChatCompletionMessage = {
176
+ role: "system";
177
+ content: string;
178
+ } | {
179
+ role: "user";
180
+ content: string | ChatCompletionContentPart[];
181
+ } | {
182
+ role: "assistant";
183
+ content: string | null;
184
+ tool_calls?: ChatCompletionToolCallParam[];
185
+ } | {
186
+ role: "tool";
187
+ tool_call_id: string;
188
+ content: string;
189
+ };
190
+ type ChatCompletionResponseMessage = {
191
+ role: string;
192
+ content: string | null;
193
+ tool_calls?: Array<{
194
+ id: string;
195
+ function?: {
196
+ name: string;
197
+ arguments: string;
198
+ };
199
+ }>;
200
+ };
137
201
  export {};
138
202
  //# sourceMappingURL=transformers.d.ts.map
@@ -5,7 +5,7 @@
5
5
  * Transform between normalized HistoryEntry format and provider-specific formats.
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.ollamaTransformer = exports.geminiTransformer = exports.mistralTransformer = exports.openAiTransformer = exports.anthropicTransformer = void 0;
8
+ exports.chatCompletionsTransformer = exports.ollamaTransformer = exports.geminiTransformer = exports.mistralTransformer = exports.openAiTransformer = exports.anthropicTransformer = void 0;
9
9
  const types_1 = require("./types");
10
10
  // =============================================================================
11
11
  // Anthropic Transformer
@@ -576,4 +576,121 @@ exports.ollamaTransformer = {
576
576
  };
577
577
  },
578
578
  };
579
+ // =============================================================================
580
+ // Chat Completions Transformer (OpenAI-compatible servers, e.g. llama.cpp)
581
+ // =============================================================================
582
+ /**
583
+ * Convert normalized entries to/from the OpenAI Chat Completions message format
584
+ * (`/v1/chat/completions`). Used by `LlamaCppAgent` and any other agent that
585
+ * targets an OpenAI-compatible chat-completions endpoint.
586
+ */
587
+ exports.chatCompletionsTransformer = {
588
+ /**
589
+ * Convert normalized entries to Chat Completions message format.
590
+ * Tool results become role:"tool" messages; tool calls are embedded in assistant messages.
591
+ */
592
+ toProvider(entries) {
593
+ const messages = [];
594
+ for (const entry of entries) {
595
+ const textBlocks = entry.content.filter(types_1.isTextContent);
596
+ const toolUseBlocks = entry.content.filter(types_1.isToolUseContent);
597
+ const toolResultBlocks = entry.content.filter(types_1.isToolResultContent);
598
+ const imageUrlBlocks = entry.content.filter(types_1.isImageUrlContent);
599
+ const imageBase64Blocks = entry.content.filter(types_1.isImageBase64Content);
600
+ const hasImages = imageUrlBlocks.length > 0 || imageBase64Blocks.length > 0;
601
+ if (entry.role === "system") {
602
+ messages.push({ role: "system", content: textBlocks.map((c) => c.text).join("\n") });
603
+ continue;
604
+ }
605
+ if (entry.role === "assistant") {
606
+ const msg = {
607
+ role: "assistant",
608
+ content: textBlocks.map((c) => c.text).join("\n") || null,
609
+ };
610
+ if (toolUseBlocks.length > 0) {
611
+ msg.tool_calls = toolUseBlocks.map((block) => ({
612
+ id: block.id,
613
+ type: "function",
614
+ function: {
615
+ name: block.name,
616
+ arguments: JSON.stringify(block.input),
617
+ },
618
+ }));
619
+ }
620
+ messages.push(msg);
621
+ continue;
622
+ }
623
+ // User role — could be text, images, or tool results
624
+ if (toolResultBlocks.length > 0) {
625
+ for (const result of toolResultBlocks) {
626
+ messages.push({
627
+ role: "tool",
628
+ tool_call_id: result.tool_use_id,
629
+ content: result.content,
630
+ });
631
+ }
632
+ }
633
+ else if (hasImages) {
634
+ const parts = [];
635
+ for (const block of entry.content) {
636
+ if ((0, types_1.isTextContent)(block)) {
637
+ parts.push({ type: "text", text: block.text });
638
+ }
639
+ else if ((0, types_1.isImageUrlContent)(block)) {
640
+ parts.push({
641
+ type: "image_url",
642
+ image_url: {
643
+ url: block.url,
644
+ ...(block.detail ? { detail: block.detail } : {}),
645
+ },
646
+ });
647
+ }
648
+ else if ((0, types_1.isImageBase64Content)(block)) {
649
+ parts.push({
650
+ type: "image_url",
651
+ image_url: { url: `data:${block.mimeType};base64,${block.data}` },
652
+ });
653
+ }
654
+ }
655
+ messages.push({ role: "user", content: parts });
656
+ }
657
+ else if (textBlocks.length > 0) {
658
+ messages.push({ role: "user", content: textBlocks.map((c) => c.text).join("\n") });
659
+ }
660
+ }
661
+ return messages;
662
+ },
663
+ /**
664
+ * Convert a Chat Completions response message to a normalized HistoryEntry.
665
+ */
666
+ fromProviderMessage(message) {
667
+ const content = [];
668
+ if (typeof message.content === "string" && message.content) {
669
+ content.push((0, types_1.text)(message.content));
670
+ }
671
+ if (message.tool_calls) {
672
+ message.tool_calls.forEach((call) => {
673
+ if (!call.function)
674
+ return;
675
+ const args = JSON.parse(call.function.arguments || "{}");
676
+ content.push((0, types_1.toolUse)(call.id, call.function.name, args));
677
+ });
678
+ }
679
+ return {
680
+ role: "assistant",
681
+ content,
682
+ meta: { provider: "llamacpp" },
683
+ };
684
+ },
685
+ /**
686
+ * Create a normalized tool result entry for a Chat Completions tool call
687
+ */
688
+ toolResultEntry(tool_call_id, output) {
689
+ return {
690
+ role: "user",
691
+ content: [(0, types_1.toolResult)(tool_call_id, output)],
692
+ meta: { provider: "llamacpp", tool_call_id },
693
+ };
694
+ },
695
+ };
579
696
  //# sourceMappingURL=transformers.js.map
@@ -94,10 +94,17 @@ export type OllamaMeta = {
94
94
  provider: "ollama";
95
95
  tool_call_id?: string;
96
96
  };
97
+ /**
98
+ * llama.cpp-specific metadata
99
+ */
100
+ export type LlamaCppMeta = {
101
+ provider: "llamacpp";
102
+ tool_call_id?: string;
103
+ };
97
104
  /**
98
105
  * Union of all provider metadata types
99
106
  */
100
- export type ProviderMeta = AnthropicMeta | OpenAiMeta | MistralMeta | GeminiMeta | OllamaMeta;
107
+ export type ProviderMeta = AnthropicMeta | OpenAiMeta | MistralMeta | GeminiMeta | OllamaMeta | LlamaCppMeta;
101
108
  /**
102
109
  * Valid roles for history entries
103
110
  */
package/dist/index.d.ts CHANGED
@@ -4,15 +4,17 @@ export { OpenAiAgent } from "./agents/openai/OpenAiAgent";
4
4
  export { MistralAgent } from "./agents/mistral/MistralAgent";
5
5
  export { GeminiAgent } from "./agents/google/GeminiAgent";
6
6
  export { OllamaAgent } from "./agents/ollama/OllamaAgent";
7
+ export { LlamaCppAgent } from "./agents/llamacpp/LlamaCppAgent";
7
8
  export * from "./agents/model-types";
8
9
  export * from "./agents/AgentConfig";
9
10
  export * from "./agents/AgentEvent";
10
11
  export * from "./agents/errors/AgentError";
11
12
  export * from "./history/History";
12
13
  export * from "./history/types";
13
- export { anthropicTransformer, openAiTransformer, mistralTransformer, geminiTransformer, ollamaTransformer, } from "./history/transformers";
14
+ export { anthropicTransformer, openAiTransformer, mistralTransformer, geminiTransformer, ollamaTransformer, chatCompletionsTransformer, } from "./history/transformers";
14
15
  export * from "./graph/AgentGraph";
15
16
  export * from "./tools/Tool";
17
+ export * from "./tools/BuiltInTool";
16
18
  export * from "./mcp";
17
19
  export * from "./viz";
18
20
  export * from "./vectorstore";
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
22
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ollamaTransformer = exports.geminiTransformer = exports.mistralTransformer = exports.openAiTransformer = exports.anthropicTransformer = exports.OllamaAgent = exports.GeminiAgent = exports.MistralAgent = exports.OpenAiAgent = void 0;
25
+ exports.chatCompletionsTransformer = exports.ollamaTransformer = exports.geminiTransformer = exports.mistralTransformer = exports.openAiTransformer = exports.anthropicTransformer = exports.LlamaCppAgent = exports.OllamaAgent = exports.GeminiAgent = exports.MistralAgent = exports.OpenAiAgent = void 0;
26
26
  // Agents
27
27
  __exportStar(require("./agents/BaseAgent"), exports);
28
28
  __exportStar(require("./agents/anthropic/ClaudeAgent"), exports);
@@ -34,6 +34,8 @@ var GeminiAgent_1 = require("./agents/google/GeminiAgent");
34
34
  Object.defineProperty(exports, "GeminiAgent", { enumerable: true, get: function () { return GeminiAgent_1.GeminiAgent; } });
35
35
  var OllamaAgent_1 = require("./agents/ollama/OllamaAgent");
36
36
  Object.defineProperty(exports, "OllamaAgent", { enumerable: true, get: function () { return OllamaAgent_1.OllamaAgent; } });
37
+ var LlamaCppAgent_1 = require("./agents/llamacpp/LlamaCppAgent");
38
+ Object.defineProperty(exports, "LlamaCppAgent", { enumerable: true, get: function () { return LlamaCppAgent_1.LlamaCppAgent; } });
37
39
  __exportStar(require("./agents/model-types"), exports);
38
40
  __exportStar(require("./agents/AgentConfig"), exports);
39
41
  __exportStar(require("./agents/AgentEvent"), exports);
@@ -47,10 +49,12 @@ Object.defineProperty(exports, "openAiTransformer", { enumerable: true, get: fun
47
49
  Object.defineProperty(exports, "mistralTransformer", { enumerable: true, get: function () { return transformers_1.mistralTransformer; } });
48
50
  Object.defineProperty(exports, "geminiTransformer", { enumerable: true, get: function () { return transformers_1.geminiTransformer; } });
49
51
  Object.defineProperty(exports, "ollamaTransformer", { enumerable: true, get: function () { return transformers_1.ollamaTransformer; } });
52
+ Object.defineProperty(exports, "chatCompletionsTransformer", { enumerable: true, get: function () { return transformers_1.chatCompletionsTransformer; } });
50
53
  // Graph
51
54
  __exportStar(require("./graph/AgentGraph"), exports);
52
55
  // Tools
53
56
  __exportStar(require("./tools/Tool"), exports);
57
+ __exportStar(require("./tools/BuiltInTool"), exports);
54
58
  // MCP (Model Context Protocol)
55
59
  __exportStar(require("./mcp"), exports);
56
60
  // Visualization
@@ -0,0 +1,4 @@
1
+ export * from "./core";
2
+ export { LlamaCppAgent } from "./agents/llamacpp/LlamaCppAgent";
3
+ export { chatCompletionsTransformer } from "./history/transformers";
4
+ //# sourceMappingURL=llamacpp.d.ts.map
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.chatCompletionsTransformer = exports.LlamaCppAgent = void 0;
18
+ // llama.cpp Agent Entry Point
19
+ __exportStar(require("./core"), exports);
20
+ var LlamaCppAgent_1 = require("./agents/llamacpp/LlamaCppAgent");
21
+ Object.defineProperty(exports, "LlamaCppAgent", { enumerable: true, get: function () { return LlamaCppAgent_1.LlamaCppAgent; } });
22
+ var transformers_1 = require("./history/transformers");
23
+ Object.defineProperty(exports, "chatCompletionsTransformer", { enumerable: true, get: function () { return transformers_1.chatCompletionsTransformer; } });
24
+ //# sourceMappingURL=llamacpp.js.map
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Provider-defined ("built-in" / server-side) tools.
3
+ *
4
+ * Unlike `Tool`, these are not executed locally — the provider runs them as
5
+ * part of generating its response (e.g. Anthropic's web search, bash, and
6
+ * text editor tools). They carry no `execute` function or input schema; the
7
+ * agent simply forwards their definition to the provider's API.
8
+ *
9
+ * Pass arbitrary built-in tool definitions straight through — only `type`
10
+ * and `name` are required, any other provider-specific fields are allowed:
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const agent = new ClaudeAgent({
15
+ * ...,
16
+ * builtInTools: [
17
+ * { type: "web_search_20250305", name: "web_search", max_uses: 5 },
18
+ * ],
19
+ * });
20
+ * ```
21
+ *
22
+ * Or use one of the helpers below for the well-known Anthropic tools.
23
+ */
24
+ export interface BuiltInTool {
25
+ /** Provider-specific tool type identifier, e.g. `"web_search_20250305"` */
26
+ type: string;
27
+ /** Name the model will use to refer to the tool, e.g. `"web_search"` */
28
+ name: string;
29
+ /** Any additional provider-specific configuration for this tool */
30
+ [key: string]: unknown;
31
+ }
32
+ /**
33
+ * Options for Anthropic's web search tool (`web_search_20250305`).
34
+ * @see https://docs.anthropic.com/en/docs/build-with-claude/tool-use/web-search-tool
35
+ */
36
+ export interface WebSearchToolOptions {
37
+ /** Maximum number of searches Claude can perform during the request */
38
+ maxUses?: number;
39
+ /** Only include results from these domains (mutually exclusive with `blockedDomains`) */
40
+ allowedDomains?: string[];
41
+ /** Never include results from these domains (mutually exclusive with `allowedDomains`) */
42
+ blockedDomains?: string[];
43
+ /** Approximate user location, used to localize search results */
44
+ userLocation?: {
45
+ type?: "approximate";
46
+ city?: string;
47
+ region?: string;
48
+ country?: string;
49
+ timezone?: string;
50
+ };
51
+ }
52
+ /**
53
+ * Anthropic's server-side web search tool.
54
+ * Claude decides when to search and the results are fetched and processed by Anthropic.
55
+ */
56
+ export declare function webSearchTool(options?: WebSearchToolOptions): BuiltInTool;
57
+ /**
58
+ * Anthropic's server-side bash tool — gives Claude a persistent shell session.
59
+ * Requires a compatible model (e.g. Claude 4 / 3.7 Sonnet) and beta header support.
60
+ */
61
+ export declare function bashTool(): BuiltInTool;
62
+ /**
63
+ * Anthropic's server-side text editor tool — lets Claude view and edit text files.
64
+ */
65
+ export declare function textEditorTool(version?: "20250124" | "20250429" | "20250728"): BuiltInTool;
66
+ /**
67
+ * Define an arbitrary provider-defined / built-in tool by its raw definition.
68
+ * Use this to pass through tools not covered by the helpers above (or for
69
+ * other providers that support server-side tools).
70
+ */
71
+ export declare function builtInTool(definition: BuiltInTool): BuiltInTool;
72
+ //# sourceMappingURL=BuiltInTool.d.ts.map
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webSearchTool = webSearchTool;
4
+ exports.bashTool = bashTool;
5
+ exports.textEditorTool = textEditorTool;
6
+ exports.builtInTool = builtInTool;
7
+ /**
8
+ * Anthropic's server-side web search tool.
9
+ * Claude decides when to search and the results are fetched and processed by Anthropic.
10
+ */
11
+ function webSearchTool(options = {}) {
12
+ const tool = {
13
+ type: "web_search_20250305",
14
+ name: "web_search",
15
+ };
16
+ if (options.maxUses !== undefined)
17
+ tool.max_uses = options.maxUses;
18
+ if (options.allowedDomains)
19
+ tool.allowed_domains = options.allowedDomains;
20
+ if (options.blockedDomains)
21
+ tool.blocked_domains = options.blockedDomains;
22
+ if (options.userLocation) {
23
+ tool.user_location = { type: "approximate", ...options.userLocation };
24
+ }
25
+ return tool;
26
+ }
27
+ /**
28
+ * Anthropic's server-side bash tool — gives Claude a persistent shell session.
29
+ * Requires a compatible model (e.g. Claude 4 / 3.7 Sonnet) and beta header support.
30
+ */
31
+ function bashTool() {
32
+ return { type: "bash_20250124", name: "bash" };
33
+ }
34
+ /**
35
+ * Anthropic's server-side text editor tool — lets Claude view and edit text files.
36
+ */
37
+ function textEditorTool(version = "20250728") {
38
+ const names = {
39
+ "20250124": "str_replace_editor",
40
+ "20250429": "str_replace_based_edit_tool",
41
+ "20250728": "str_replace_based_edit_tool",
42
+ };
43
+ return { type: `text_editor_${version}`, name: names[version] };
44
+ }
45
+ /**
46
+ * Define an arbitrary provider-defined / built-in tool by its raw definition.
47
+ * Use this to pass through tools not covered by the helpers above (or for
48
+ * other providers that support server-side tools).
49
+ */
50
+ function builtInTool(definition) {
51
+ return definition;
52
+ }
53
+ //# sourceMappingURL=BuiltInTool.js.map
@@ -2,7 +2,7 @@
2
2
  * Visualization event types and interfaces for agent monitoring.
3
3
  * These types define the contract between agention-lib and @agention/viz.
4
4
  */
5
- export type VizVendor = "anthropic" | "openai" | "mistral" | "gemini" | "ollama";
5
+ export type VizVendor = "anthropic" | "openai" | "mistral" | "gemini" | "ollama" | "llamacpp";
6
6
  export type VizEventType = "session.start" | "session.end" | "pipeline.start" | "pipeline.end" | "executor.start" | "executor.end" | "agent.start" | "agent.complete" | "agent.error" | "tool.start" | "tool.complete" | "tool.error" | "message.user" | "message.assistant";
7
7
  export type VizExecutorType = "sequential" | "parallel" | "map" | "voting" | "router";
8
8
  export type VizStopReason = "end_turn" | "tool_use" | "max_tokens" | "stop_sequence" | "error";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agentionai/agents",
3
3
  "author": "Laurent Zuijdwijk",
4
- "version": "0.12.0",
4
+ "version": "0.13.0",
5
5
  "description": "Agent Library",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -34,6 +34,10 @@
34
34
  "types": "./dist/ollama.d.ts",
35
35
  "default": "./dist/ollama.js"
36
36
  },
37
+ "./llamacpp": {
38
+ "types": "./dist/llamacpp.d.ts",
39
+ "default": "./dist/llamacpp.js"
40
+ },
37
41
  "./embeddings": {
38
42
  "types": "./dist/embeddings/index.d.ts",
39
43
  "default": "./dist/embeddings/index.js"