@agentionai/agents 0.3.0-beta
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 +517 -0
- package/dist/agents/Agent.d.ts +29 -0
- package/dist/agents/Agent.js +28 -0
- package/dist/agents/AgentConfig.d.ts +118 -0
- package/dist/agents/AgentConfig.js +3 -0
- package/dist/agents/AgentEvent.d.ts +18 -0
- package/dist/agents/AgentEvent.js +26 -0
- package/dist/agents/BaseAgent.d.ts +82 -0
- package/dist/agents/BaseAgent.js +121 -0
- package/dist/agents/anthropic/ClaudeAgent.d.ts +46 -0
- package/dist/agents/anthropic/ClaudeAgent.js +262 -0
- package/dist/agents/errors/AgentError.d.ts +47 -0
- package/dist/agents/errors/AgentError.js +74 -0
- package/dist/agents/google/GeminiAgent.d.ts +63 -0
- package/dist/agents/google/GeminiAgent.js +395 -0
- package/dist/agents/mistral/MistralAgent.d.ts +47 -0
- package/dist/agents/mistral/MistralAgent.js +313 -0
- package/dist/agents/model-types.d.ts +30 -0
- package/dist/agents/model-types.js +8 -0
- package/dist/agents/openai/OpenAiAgent.d.ts +48 -0
- package/dist/agents/openai/OpenAiAgent.js +338 -0
- package/dist/chunkers/Chunker.d.ts +53 -0
- package/dist/chunkers/Chunker.js +174 -0
- package/dist/chunkers/RecursiveChunker.d.ts +52 -0
- package/dist/chunkers/RecursiveChunker.js +166 -0
- package/dist/chunkers/TextChunker.d.ts +27 -0
- package/dist/chunkers/TextChunker.js +50 -0
- package/dist/chunkers/TokenChunker.d.ts +60 -0
- package/dist/chunkers/TokenChunker.js +176 -0
- package/dist/chunkers/index.d.ts +6 -0
- package/dist/chunkers/index.js +14 -0
- package/dist/chunkers/types.d.ts +95 -0
- package/dist/chunkers/types.js +3 -0
- package/dist/graph/AgentGraph.d.ts +99 -0
- package/dist/graph/AgentGraph.js +115 -0
- package/dist/graph/BaseExecutor.d.ts +86 -0
- package/dist/graph/BaseExecutor.js +61 -0
- package/dist/graph/GraphMetrics.d.ts +143 -0
- package/dist/graph/GraphMetrics.js +264 -0
- package/dist/graph/MapExecutor.d.ts +39 -0
- package/dist/graph/MapExecutor.js +123 -0
- package/dist/graph/ParallelExecutor.d.ts +51 -0
- package/dist/graph/ParallelExecutor.js +103 -0
- package/dist/graph/Pipeline.d.ts +44 -0
- package/dist/graph/Pipeline.js +109 -0
- package/dist/graph/RouterExecutor.d.ts +89 -0
- package/dist/graph/RouterExecutor.js +209 -0
- package/dist/graph/SequentialExecutor.d.ts +44 -0
- package/dist/graph/SequentialExecutor.js +115 -0
- package/dist/graph/VotingSystem.d.ts +54 -0
- package/dist/graph/VotingSystem.js +106 -0
- package/dist/history/History.d.ts +107 -0
- package/dist/history/History.js +166 -0
- package/dist/history/RedisHistory.d.ts +27 -0
- package/dist/history/RedisHistory.js +55 -0
- package/dist/history/transformers.d.ts +102 -0
- package/dist/history/transformers.js +415 -0
- package/dist/history/types.d.ts +130 -0
- package/dist/history/types.js +55 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +48 -0
- package/dist/ingestion/IngestionPipeline.d.ts +86 -0
- package/dist/ingestion/IngestionPipeline.js +266 -0
- package/dist/ingestion/index.d.ts +3 -0
- package/dist/ingestion/index.js +7 -0
- package/dist/ingestion/types.d.ts +74 -0
- package/dist/ingestion/types.js +3 -0
- package/dist/team/Team.d.ts +46 -0
- package/dist/team/Team.js +104 -0
- package/dist/tools/Tool.d.ts +75 -0
- package/dist/tools/Tool.js +137 -0
- package/dist/vectorstore/Embeddings.d.ts +67 -0
- package/dist/vectorstore/Embeddings.js +54 -0
- package/dist/vectorstore/LanceDBVectorStore.d.ts +149 -0
- package/dist/vectorstore/LanceDBVectorStore.js +338 -0
- package/dist/vectorstore/OpenAIEmbeddings.d.ts +45 -0
- package/dist/vectorstore/OpenAIEmbeddings.js +109 -0
- package/dist/vectorstore/VectorStore.d.ts +255 -0
- package/dist/vectorstore/VectorStore.js +216 -0
- package/dist/vectorstore/index.d.ts +28 -0
- package/dist/vectorstore/index.js +35 -0
- package/dist/viz/VizConfig.d.ts +54 -0
- package/dist/viz/VizConfig.js +100 -0
- package/dist/viz/VizReporter.d.ts +127 -0
- package/dist/viz/VizReporter.js +595 -0
- package/dist/viz/index.d.ts +31 -0
- package/dist/viz/index.js +51 -0
- package/dist/viz/types.d.ts +105 -0
- package/dist/viz/types.js +7 -0
- package/package.json +109 -0
- package/readme.md +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
# Agention
|
|
2
|
+
|
|
3
|
+
> A TypeScript library for building AI-powered agents, tools, and complex workflows
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@agentionai/agents)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
Agention provides a clean, modular architecture for working with LLMs from multiple providers. Build single-purpose agents or orchestrate complex multi-agent workflows with built-in tools, vector search, and document processing capabilities.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **🤖 Multi-Provider Support** - Works with Claude, OpenAI, Mistral, and Google Gemini out of the box
|
|
13
|
+
- **🔧 Powerful Tool System** - Define tools with JSON Schema validation, agents use them automatically
|
|
14
|
+
- **🔀 Graph Pipelines** - Chain agents together with sequential, parallel, map, voting, and router patterns
|
|
15
|
+
- **💾 Vector Search** - Built-in LanceDB integration for semantic search and RAG applications
|
|
16
|
+
- **📄 Document Processing** - Intelligent chunking with token-aware splitting and metadata tracking
|
|
17
|
+
- **📊 Metrics & Observability** - Track tokens, timing, and pipeline execution
|
|
18
|
+
- **🔒 Type-Safe** - Full TypeScript support with strict typing throughout
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @agentionai/agents
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Install the SDK for your chosen LLM provider:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# For Claude
|
|
30
|
+
npm install @anthropic-ai/sdk
|
|
31
|
+
|
|
32
|
+
# For OpenAI
|
|
33
|
+
npm install openai
|
|
34
|
+
|
|
35
|
+
# For vector search (optional)
|
|
36
|
+
npm install @lancedb/lancedb apache-arrow
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
### Basic Agent
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { ClaudeAgent } from '@agentionai/agents';
|
|
45
|
+
|
|
46
|
+
const agent = new ClaudeAgent({
|
|
47
|
+
model: 'claude-sonnet-4-20250514',
|
|
48
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const response = await agent.execute('What is the capital of France?');
|
|
52
|
+
console.log(response);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Agent with Tools
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { ClaudeAgent, Tool } from '@agentionai/agents';
|
|
59
|
+
|
|
60
|
+
const calculator = new Tool({
|
|
61
|
+
name: 'calculate',
|
|
62
|
+
description: 'Perform mathematical calculations',
|
|
63
|
+
input_schema: {
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
expression: { type: 'string', description: 'Math expression to evaluate' },
|
|
67
|
+
},
|
|
68
|
+
required: ['expression'],
|
|
69
|
+
},
|
|
70
|
+
handler: async ({ expression }) => {
|
|
71
|
+
return String(eval(expression));
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const agent = new ClaudeAgent({
|
|
76
|
+
model: 'claude-sonnet-4-20250514',
|
|
77
|
+
systemPrompt: 'You are a helpful math assistant.',
|
|
78
|
+
tools: [calculator],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const response = await agent.execute('What is 15% of 230?');
|
|
82
|
+
// Agent automatically uses the calculator tool
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Multi-Agent Pipeline
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { Pipeline, ClaudeAgent, OpenAiAgent } from '@agentionai/agents';
|
|
89
|
+
|
|
90
|
+
// Research agent with search capabilities
|
|
91
|
+
const researcher = new OpenAiAgent({
|
|
92
|
+
name: 'researcher',
|
|
93
|
+
model: 'gpt-4o',
|
|
94
|
+
systemPrompt: 'Research the topic thoroughly.',
|
|
95
|
+
tools: [webSearchTool],
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Writing agent
|
|
99
|
+
const writer = new ClaudeAgent({
|
|
100
|
+
name: 'writer',
|
|
101
|
+
model: 'claude-sonnet-4-20250514',
|
|
102
|
+
systemPrompt: 'Write a compelling blog post from the research.',
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Chain them together
|
|
106
|
+
const pipeline = new Pipeline([researcher, writer]);
|
|
107
|
+
const result = await pipeline.execute('AI in Healthcare');
|
|
108
|
+
// researcher output → writer input → final blog post
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### RAG with Vector Search
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { ClaudeAgent, LanceDBVectorStore, OpenAIEmbeddings } from '@agentionai/agents';
|
|
115
|
+
|
|
116
|
+
// Setup vector store
|
|
117
|
+
const embeddings = new OpenAIEmbeddings({ model: 'text-embedding-3-small' });
|
|
118
|
+
const store = await LanceDBVectorStore.create({
|
|
119
|
+
name: 'docs',
|
|
120
|
+
uri: './data/vectors',
|
|
121
|
+
tableName: 'knowledge',
|
|
122
|
+
embeddings,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Add documents
|
|
126
|
+
await store.addDocuments([
|
|
127
|
+
{ id: '1', content: 'Company policy on refunds...' },
|
|
128
|
+
{ id: '2', content: 'Technical documentation...' },
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
// Create search tool
|
|
132
|
+
const searchTool = store.toRetrievalTool(
|
|
133
|
+
'Search company knowledge base',
|
|
134
|
+
{ defaultLimit: 5 }
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Agent can search and answer
|
|
138
|
+
const agent = new ClaudeAgent({
|
|
139
|
+
model: 'claude-sonnet-4-20250514',
|
|
140
|
+
systemPrompt: 'Answer questions using the knowledge base.',
|
|
141
|
+
tools: [searchTool],
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const answer = await agent.execute('What is our refund policy?');
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Core Concepts
|
|
148
|
+
|
|
149
|
+
### Agents
|
|
150
|
+
|
|
151
|
+
Agents wrap LLM providers with a consistent interface. All agents support:
|
|
152
|
+
|
|
153
|
+
- Conversation history management
|
|
154
|
+
- Tool use
|
|
155
|
+
- Token tracking
|
|
156
|
+
- Pipeline integration
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { ClaudeAgent, OpenAiAgent, MistralAgent, GeminiAgent } from '@agentionai/agents';
|
|
160
|
+
|
|
161
|
+
// Same interface, different providers
|
|
162
|
+
const claude = new ClaudeAgent({ model: 'claude-sonnet-4-20250514' });
|
|
163
|
+
const openai = new OpenAiAgent({ model: 'gpt-4o' });
|
|
164
|
+
const mistral = new MistralAgent({ model: 'mistral-large-latest' });
|
|
165
|
+
const gemini = new GeminiAgent({ model: 'gemini-2.0-flash' });
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Tools
|
|
169
|
+
|
|
170
|
+
Tools give agents abilities beyond text generation. Define them with JSON Schema:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const weatherTool = new Tool({
|
|
174
|
+
name: 'get_weather',
|
|
175
|
+
description: 'Get current weather for a city',
|
|
176
|
+
input_schema: {
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
city: { type: 'string' },
|
|
180
|
+
units: { type: 'string', enum: ['celsius', 'fahrenheit'] },
|
|
181
|
+
},
|
|
182
|
+
required: ['city'],
|
|
183
|
+
},
|
|
184
|
+
handler: async ({ city, units }) => {
|
|
185
|
+
const weather = await fetchWeather(city, units);
|
|
186
|
+
return JSON.stringify(weather);
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Advanced: Agents as Tools**
|
|
192
|
+
|
|
193
|
+
Use agents as tools for hierarchical workflows:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// Specialized sub-agent
|
|
197
|
+
const researchAssistant = new OpenAiAgent({
|
|
198
|
+
name: 'research-assistant',
|
|
199
|
+
description: 'Expert at finding research papers',
|
|
200
|
+
tools: [pubmedSearchTool],
|
|
201
|
+
model: 'gpt-4o-mini',
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Main agent delegates to sub-agent
|
|
205
|
+
const mainAgent = new ClaudeAgent({
|
|
206
|
+
name: 'coordinator',
|
|
207
|
+
agents: [researchAssistant], // Sub-agents available as tools
|
|
208
|
+
model: 'claude-sonnet-4-20250514',
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Graph Pipelines
|
|
213
|
+
|
|
214
|
+
Build complex workflows by combining agents and executors:
|
|
215
|
+
|
|
216
|
+
#### Sequential Processing
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { SequentialExecutor } from '@agentionai/agents';
|
|
220
|
+
|
|
221
|
+
const chain = new SequentialExecutor({
|
|
222
|
+
name: 'content-pipeline',
|
|
223
|
+
agents: [researcher, writer, editor],
|
|
224
|
+
});
|
|
225
|
+
// researcher → writer → editor
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Parallel Execution
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { ParallelExecutor } from '@agentionai/agents';
|
|
232
|
+
|
|
233
|
+
const parallel = new ParallelExecutor({
|
|
234
|
+
name: 'multi-perspective',
|
|
235
|
+
agents: [optimist, pessimist, realist],
|
|
236
|
+
});
|
|
237
|
+
// All run simultaneously on same input
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### Map Operations
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
import { MapExecutor } from '@agentionai/agents';
|
|
244
|
+
|
|
245
|
+
const mapper = new MapExecutor({
|
|
246
|
+
name: 'batch-process',
|
|
247
|
+
processor: summarizer,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
await mapper.execute(['doc1', 'doc2', 'doc3']);
|
|
251
|
+
// Applies summarizer to each document
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### Voting Systems
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
import { VotingSystem } from '@agentionai/agents';
|
|
258
|
+
|
|
259
|
+
const voting = new VotingSystem({
|
|
260
|
+
name: 'code-review',
|
|
261
|
+
candidates: [juniorDev, seniorDev, architect],
|
|
262
|
+
judge: techLead,
|
|
263
|
+
});
|
|
264
|
+
// Multiple solutions proposed, judge picks best
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### Router Patterns
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { RouterExecutor } from '@agentionai/agents';
|
|
271
|
+
|
|
272
|
+
const router = new RouterExecutor({
|
|
273
|
+
name: 'support-router',
|
|
274
|
+
routes: [
|
|
275
|
+
{ name: 'billing', agent: billingAgent, description: 'Billing questions' },
|
|
276
|
+
{ name: 'technical', agent: techAgent, description: 'Technical issues' },
|
|
277
|
+
],
|
|
278
|
+
routerAgent: classifierAgent,
|
|
279
|
+
});
|
|
280
|
+
// Routes input to appropriate agent
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Document Processing
|
|
284
|
+
|
|
285
|
+
#### Chunking Strategies
|
|
286
|
+
|
|
287
|
+
Split documents intelligently for RAG applications:
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import { RecursiveChunker, TokenChunker, TextChunker } from '@agentionai/agents';
|
|
291
|
+
|
|
292
|
+
// Semantic chunking (best for structured docs)
|
|
293
|
+
const recursiveChunker = new RecursiveChunker({
|
|
294
|
+
chunkSize: 1000,
|
|
295
|
+
chunkOverlap: 100,
|
|
296
|
+
separators: ['\n\n', '\n', '. ', ' '],
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// Token-aware chunking (best for LLM context limits)
|
|
300
|
+
const tokenChunker = new TokenChunker({
|
|
301
|
+
chunkSize: 500, // tokens, not characters
|
|
302
|
+
chunkOverlap: 50,
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// Simple character-based chunking
|
|
306
|
+
const textChunker = new TextChunker({
|
|
307
|
+
chunkSize: 1000,
|
|
308
|
+
chunkOverlap: 200,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const chunks = await recursiveChunker.chunk(documentText, {
|
|
312
|
+
sourceId: 'doc-123',
|
|
313
|
+
metadata: { author: 'Alice' },
|
|
314
|
+
});
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### Ingestion Pipeline
|
|
318
|
+
|
|
319
|
+
Orchestrate chunking, embedding, and storage:
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import { IngestionPipeline, RecursiveChunker } from '@agentionai/agents';
|
|
323
|
+
|
|
324
|
+
const chunker = new RecursiveChunker({ chunkSize: 1000 });
|
|
325
|
+
const embeddings = new OpenAIEmbeddings({ model: 'text-embedding-3-small' });
|
|
326
|
+
const store = await LanceDBVectorStore.create({
|
|
327
|
+
name: 'docs',
|
|
328
|
+
uri: './data',
|
|
329
|
+
tableName: 'chunks',
|
|
330
|
+
embeddings,
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const pipeline = new IngestionPipeline(chunker, embeddings, store);
|
|
334
|
+
|
|
335
|
+
const result = await pipeline.ingest(documentText, {
|
|
336
|
+
sourceId: 'doc-001',
|
|
337
|
+
batchSize: 50,
|
|
338
|
+
onProgress: ({ phase, processed, total }) => {
|
|
339
|
+
console.log(`${phase}: ${processed}/${total}`);
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Metrics & Observability
|
|
345
|
+
|
|
346
|
+
Track performance across your pipelines:
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
import { MetricsCollector } from '@agentionai/agents';
|
|
350
|
+
|
|
351
|
+
const metrics = new MetricsCollector();
|
|
352
|
+
const result = await pipeline.execute('Input', { metrics });
|
|
353
|
+
|
|
354
|
+
const stats = metrics.getMetrics();
|
|
355
|
+
console.log({
|
|
356
|
+
totalDuration: stats.totalDuration,
|
|
357
|
+
totalTokens: stats.totalInputTokens + stats.totalOutputTokens,
|
|
358
|
+
nodeCount: stats.nodes.length,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// Per-node metrics
|
|
362
|
+
stats.nodes.forEach(node => {
|
|
363
|
+
console.log(`${node.name}: ${node.duration}ms, ${node.tokens?.total} tokens`);
|
|
364
|
+
});
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Architecture
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
371
|
+
│ Agention │
|
|
372
|
+
│ │
|
|
373
|
+
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
|
|
374
|
+
│ │ Claude │ │ OpenAI │ │ Mistral │ │ Gemini │ │
|
|
375
|
+
│ │ Agent │ │ Agent │ │ Agent │ │ Agent │ │
|
|
376
|
+
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
|
|
377
|
+
│ │ │ │ │ │
|
|
378
|
+
│ └─────────────┴───────────────┴─────────────┘ │
|
|
379
|
+
│ │ │
|
|
380
|
+
│ ┌─────▼─────┐ │
|
|
381
|
+
│ │ BaseAgent │ │
|
|
382
|
+
│ │ Interface │ │
|
|
383
|
+
│ └─────┬─────┘ │
|
|
384
|
+
│ │ │
|
|
385
|
+
│ ┌──────────────────┼──────────────────┐ │
|
|
386
|
+
│ │ │ │ │
|
|
387
|
+
│ ┌────▼────┐ ┌─────▼─────┐ ┌─────▼─────┐ │
|
|
388
|
+
│ │ Tools │ │ Pipelines │ │ History │ │
|
|
389
|
+
│ └─────────┘ └───────────┘ └───────────┘ │
|
|
390
|
+
│ │ │ │
|
|
391
|
+
│ ┌────▼────────────┐ │ │
|
|
392
|
+
│ │ Vector Stores │ │ │
|
|
393
|
+
│ │ - LanceDB │ │ │
|
|
394
|
+
│ │ - Embeddings │ │ │
|
|
395
|
+
│ └─────────────────┘ │ │
|
|
396
|
+
│ │ │
|
|
397
|
+
│ ┌──────────────────┼──────────────────┐ │
|
|
398
|
+
│ │ │ │ │
|
|
399
|
+
│ ┌────▼────┐ ┌─────▼─────┐ ┌─────▼─────┐ │
|
|
400
|
+
│ │Sequential│ │ Parallel │ │ Router │ │
|
|
401
|
+
│ │Executor │ │ Executor │ │ Executor │ │
|
|
402
|
+
│ └──────────┘ └───────────┘ └───────────┘ │
|
|
403
|
+
│ │
|
|
404
|
+
└─────────────────────────────────────────────────────────────┘
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## Documentation
|
|
408
|
+
|
|
409
|
+
- **[Getting Started](docs/guide/getting-started.md)** - Installation and first steps
|
|
410
|
+
- **[Agents](docs/guide/agents.md)** - Agent configuration and providers
|
|
411
|
+
- **[Tools](docs/guide/tools.md)** - Creating and using tools
|
|
412
|
+
- **[Graph Pipelines](docs/guide/graph-pipelines.md)** - Building multi-agent workflows
|
|
413
|
+
- **[Vector Stores](docs/guide/vector-stores.md)** - Semantic search and RAG
|
|
414
|
+
- **[Chunking & Ingestion](docs/guide/chunking-and-ingestion.md)** - Document processing
|
|
415
|
+
- **[Examples](docs/guide/examples.md)** - Complete example applications
|
|
416
|
+
- **[API Reference](docs/api)** - Full API documentation
|
|
417
|
+
|
|
418
|
+
## Examples
|
|
419
|
+
|
|
420
|
+
See the [examples](examples) directory for complete working examples:
|
|
421
|
+
|
|
422
|
+
- **Basic Agents** - Simple agent usage with different providers
|
|
423
|
+
- **Tool Usage** - Agents with custom tools
|
|
424
|
+
- **Multi-Agent Pipelines** - Sequential, parallel, and voting patterns
|
|
425
|
+
- **RAG Applications** - Vector search and document retrieval
|
|
426
|
+
- **Document Ingestion** - Chunking and embedding pipelines
|
|
427
|
+
- **Graph-based RAG** - Advanced knowledge graph integration
|
|
428
|
+
|
|
429
|
+
## Development
|
|
430
|
+
|
|
431
|
+
### Commands
|
|
432
|
+
|
|
433
|
+
```bash
|
|
434
|
+
# Build
|
|
435
|
+
npm run build
|
|
436
|
+
|
|
437
|
+
# Test
|
|
438
|
+
npm test
|
|
439
|
+
npm run test:watch
|
|
440
|
+
|
|
441
|
+
# Linting
|
|
442
|
+
npm run lint
|
|
443
|
+
npm run lint:fix
|
|
444
|
+
|
|
445
|
+
# Documentation
|
|
446
|
+
npm run docs:dev # Start docs dev server
|
|
447
|
+
npm run docs:build # Build documentation
|
|
448
|
+
npm run docs:api # Generate API docs
|
|
449
|
+
|
|
450
|
+
# Examples
|
|
451
|
+
npm run example # Run example code
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Project Structure
|
|
455
|
+
|
|
456
|
+
```
|
|
457
|
+
agention-lib/
|
|
458
|
+
├── lib/
|
|
459
|
+
│ ├── agents/ # Agent implementations
|
|
460
|
+
│ │ ├── anthropic/ # Claude agent
|
|
461
|
+
│ │ ├── openai/ # OpenAI agent
|
|
462
|
+
│ │ ├── mistral/ # Mistral agent
|
|
463
|
+
│ │ ├── google/ # Gemini agent
|
|
464
|
+
│ │ └── BaseAgent.ts # Abstract base class
|
|
465
|
+
│ ├── tools/ # Tool system
|
|
466
|
+
│ ├── history/ # Conversation management
|
|
467
|
+
│ ├── graph/ # Pipeline executors
|
|
468
|
+
│ │ ├── executors/ # Sequential, Parallel, Map, Voting, Router
|
|
469
|
+
│ │ ├── MetricsCollector.ts
|
|
470
|
+
│ │ └── Pipeline.ts
|
|
471
|
+
│ ├── chunking/ # Document chunking
|
|
472
|
+
│ │ ├── TextChunker.ts
|
|
473
|
+
│ │ ├── RecursiveChunker.ts
|
|
474
|
+
│ │ └── TokenChunker.ts
|
|
475
|
+
│ ├── ingestion/ # Ingestion pipeline
|
|
476
|
+
│ └── vectorstore/ # Vector store implementations
|
|
477
|
+
│ ├── LanceDBVectorStore.ts
|
|
478
|
+
│ └── embeddings/
|
|
479
|
+
├── examples/ # Example applications
|
|
480
|
+
├── docs/ # Documentation
|
|
481
|
+
└── dist/ # Build output
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
## Environment Variables
|
|
485
|
+
|
|
486
|
+
Set API keys as environment variables:
|
|
487
|
+
|
|
488
|
+
```bash
|
|
489
|
+
# LLM Providers
|
|
490
|
+
export ANTHROPIC_API_KEY=your-key-here
|
|
491
|
+
export OPENAI_API_KEY=your-key-here
|
|
492
|
+
export MISTRAL_API_KEY=your-key-here
|
|
493
|
+
export GOOGLE_API_KEY=your-key-here
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
## Contributing
|
|
497
|
+
|
|
498
|
+
Contributions are welcome! Please see our development guidelines in [CLAUDE.md](CLAUDE.md).
|
|
499
|
+
|
|
500
|
+
## License
|
|
501
|
+
|
|
502
|
+
MIT
|
|
503
|
+
|
|
504
|
+
## Roadmap
|
|
505
|
+
|
|
506
|
+
- [ ] Streaming response support
|
|
507
|
+
- [ ] Additional vector store integrations (Pinecone, Weaviate)
|
|
508
|
+
- [ ] Conditional and loop executors
|
|
509
|
+
- [ ] Graph visualization tools
|
|
510
|
+
- [ ] Enhanced retry mechanisms
|
|
511
|
+
- [ ] Middleware system for request/response processing
|
|
512
|
+
|
|
513
|
+
## Support
|
|
514
|
+
|
|
515
|
+
- **Issues**: [GitHub Issues](https://github.com/laurentzuijdwijk/agention-lib/issues)
|
|
516
|
+
- **Documentation**: [docs](docs/guide/getting-started.md)
|
|
517
|
+
- **Examples**: [examples](examples)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { History } from "../history/History";
|
|
2
|
+
import { ClaudeAgent } from "./anthropic/ClaudeAgent";
|
|
3
|
+
import { BaseAgentConfig } from "./BaseAgent";
|
|
4
|
+
import { OpenAiAgent } from "./openai/OpenAiAgent";
|
|
5
|
+
import { GeminiAgent } from "./google/GeminiAgent";
|
|
6
|
+
import { MistralAgent } from "./mistral/MistralAgent";
|
|
7
|
+
import { ClaudeModel, OpenAIModel, GeminiModel, MistralModel } from "./model-types";
|
|
8
|
+
type ClaudeAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
9
|
+
vendor: "anthropic";
|
|
10
|
+
model?: ClaudeModel;
|
|
11
|
+
};
|
|
12
|
+
type OpenAIAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
13
|
+
vendor: "openai";
|
|
14
|
+
model?: OpenAIModel;
|
|
15
|
+
};
|
|
16
|
+
type GeminiAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
17
|
+
vendor: "gemini";
|
|
18
|
+
model?: GeminiModel;
|
|
19
|
+
};
|
|
20
|
+
type MistralAgentConfig = Omit<BaseAgentConfig, "vendor" | "model"> & {
|
|
21
|
+
vendor: "mistral";
|
|
22
|
+
model?: MistralModel;
|
|
23
|
+
};
|
|
24
|
+
type AgentConfig = ClaudeAgentConfig | OpenAIAgentConfig | GeminiAgentConfig | MistralAgentConfig;
|
|
25
|
+
export declare class Agent {
|
|
26
|
+
static create(config: AgentConfig, history?: History): ClaudeAgent | OpenAiAgent | MistralAgent | GeminiAgent;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=Agent.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Agent = void 0;
|
|
4
|
+
const ClaudeAgent_1 = require("./anthropic/ClaudeAgent");
|
|
5
|
+
const OpenAiAgent_1 = require("./openai/OpenAiAgent");
|
|
6
|
+
const GeminiAgent_1 = require("./google/GeminiAgent");
|
|
7
|
+
const MistralAgent_1 = require("./mistral/MistralAgent");
|
|
8
|
+
class Agent {
|
|
9
|
+
static create(config, history) {
|
|
10
|
+
if (config.vendor === "anthropic") {
|
|
11
|
+
return new ClaudeAgent_1.ClaudeAgent(config, history);
|
|
12
|
+
}
|
|
13
|
+
else if (config.vendor === "openai") {
|
|
14
|
+
return new OpenAiAgent_1.OpenAiAgent(config, history);
|
|
15
|
+
}
|
|
16
|
+
else if (config.vendor === "gemini") {
|
|
17
|
+
return new GeminiAgent_1.GeminiAgent(config, history);
|
|
18
|
+
}
|
|
19
|
+
else if (config.vendor === "mistral") {
|
|
20
|
+
return new MistralAgent_1.MistralAgent(config, history);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error("No vendor defined");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.Agent = Agent;
|
|
28
|
+
//# sourceMappingURL=Agent.js.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Tool } from "../tools/Tool";
|
|
2
|
+
import { BaseAgent } from "./BaseAgent";
|
|
3
|
+
/** Supported LLM vendors */
|
|
4
|
+
export type AgentVendor = "openai" | "anthropic" | "mistral" | "gemini";
|
|
5
|
+
/**
|
|
6
|
+
* Common configuration shared by all agents
|
|
7
|
+
*/
|
|
8
|
+
export interface CommonAgentConfig {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
description: string;
|
|
12
|
+
apiKey: string;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
maxHistoryLength?: number;
|
|
15
|
+
model?: string;
|
|
16
|
+
tools?: Tool<unknown>[];
|
|
17
|
+
agents?: BaseAgent[];
|
|
18
|
+
maxTokens?: number;
|
|
19
|
+
temperature?: number;
|
|
20
|
+
topP?: number;
|
|
21
|
+
topK?: number;
|
|
22
|
+
stopSequences?: string[];
|
|
23
|
+
timeout?: number;
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
seed?: number;
|
|
26
|
+
presencePenalty?: number;
|
|
27
|
+
frequencyPenalty?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Vendor-specific configuration for Anthropic Claude
|
|
31
|
+
*/
|
|
32
|
+
export interface ClaudeSpecificConfig {
|
|
33
|
+
disableParallelToolUse?: boolean;
|
|
34
|
+
metadata?: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Vendor-specific configuration for OpenAI
|
|
38
|
+
*/
|
|
39
|
+
export interface OpenAISpecificConfig {
|
|
40
|
+
disableParallelToolUse?: boolean;
|
|
41
|
+
disableReasoning?: boolean;
|
|
42
|
+
reasoningEffort?: "low" | "medium" | "high";
|
|
43
|
+
seed?: number;
|
|
44
|
+
user?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Vendor-specific configuration for Mistral
|
|
48
|
+
*/
|
|
49
|
+
export interface MistralSpecificConfig {
|
|
50
|
+
disableParallelToolUse?: boolean;
|
|
51
|
+
safePrompt?: boolean;
|
|
52
|
+
randomSeed?: number;
|
|
53
|
+
rateLimitDelay?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Vendor-specific configuration for Google Gemini
|
|
57
|
+
*/
|
|
58
|
+
export interface GeminiSpecificConfig {
|
|
59
|
+
candidateCount?: number;
|
|
60
|
+
stopSequences?: string[];
|
|
61
|
+
responseMimeType?: string;
|
|
62
|
+
responseSchema?: any;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Generic vendor-specific configuration container
|
|
66
|
+
* This allows any vendor to add custom config without modifying base types
|
|
67
|
+
*/
|
|
68
|
+
export interface VendorSpecificConfig {
|
|
69
|
+
anthropic?: ClaudeSpecificConfig;
|
|
70
|
+
openai?: OpenAISpecificConfig;
|
|
71
|
+
mistral?: MistralSpecificConfig;
|
|
72
|
+
gemini?: GeminiSpecificConfig;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Complete agent configuration with vendor-specific extensions
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const config: AgentConfig = {
|
|
80
|
+
* id: "1",
|
|
81
|
+
* name: "Assistant",
|
|
82
|
+
* description: "A helpful assistant",
|
|
83
|
+
* apiKey: process.env.API_KEY,
|
|
84
|
+
* temperature: 0.7,
|
|
85
|
+
* vendorConfig: {
|
|
86
|
+
* openai: {
|
|
87
|
+
* disableReasoning: true,
|
|
88
|
+
* reasoningEffort: "high"
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
* };
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export interface AgentConfig extends CommonAgentConfig {
|
|
95
|
+
vendor: AgentVendor;
|
|
96
|
+
vendorConfig?: VendorSpecificConfig;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Type-safe agent configuration for specific vendors
|
|
100
|
+
* Use this to get type hints for vendor-specific config
|
|
101
|
+
*/
|
|
102
|
+
export type TypedAgentConfig<V extends AgentVendor> = CommonAgentConfig & {
|
|
103
|
+
vendor: V;
|
|
104
|
+
vendorConfig?: V extends "anthropic" ? {
|
|
105
|
+
anthropic?: ClaudeSpecificConfig;
|
|
106
|
+
} : V extends "openai" ? {
|
|
107
|
+
openai?: OpenAISpecificConfig;
|
|
108
|
+
} : V extends "mistral" ? {
|
|
109
|
+
mistral?: MistralSpecificConfig;
|
|
110
|
+
} : V extends "gemini" ? {
|
|
111
|
+
gemini?: GeminiSpecificConfig;
|
|
112
|
+
} : never;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Helper type to extract vendor-specific config for a given vendor
|
|
116
|
+
*/
|
|
117
|
+
export type VendorConfigFor<V extends AgentVendor> = V extends "anthropic" ? ClaudeSpecificConfig : V extends "openai" ? OpenAISpecificConfig : V extends "mistral" ? MistralSpecificConfig : V extends "gemini" ? GeminiSpecificConfig : never;
|
|
118
|
+
//# sourceMappingURL=AgentConfig.d.ts.map
|