@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
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector Store interface for document storage and semantic retrieval.
|
|
3
|
+
*
|
|
4
|
+
* This module provides an abstract interface for vector databases,
|
|
5
|
+
* enabling document storage with embeddings and semantic search capabilities.
|
|
6
|
+
*/
|
|
7
|
+
import { Tool } from "../tools/Tool";
|
|
8
|
+
/**
|
|
9
|
+
* Represents a document with its content and optional metadata.
|
|
10
|
+
*/
|
|
11
|
+
export interface Document {
|
|
12
|
+
/** Unique identifier for the document */
|
|
13
|
+
id: string;
|
|
14
|
+
/** The text content of the document */
|
|
15
|
+
content: string;
|
|
16
|
+
/** Optional metadata associated with the document */
|
|
17
|
+
metadata?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A document with its computed embedding vector.
|
|
21
|
+
*/
|
|
22
|
+
export interface EmbeddedDocument extends Document {
|
|
23
|
+
/** The embedding vector for the document */
|
|
24
|
+
embedding: number[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result from a similarity search operation.
|
|
28
|
+
*/
|
|
29
|
+
export interface SearchResult {
|
|
30
|
+
/** The matching document */
|
|
31
|
+
document: Document;
|
|
32
|
+
/** Similarity score (higher is more similar, typically 0-1) */
|
|
33
|
+
score: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for adding documents to the vector store.
|
|
37
|
+
*/
|
|
38
|
+
export interface AddDocumentsOptions {
|
|
39
|
+
/** Namespace or collection to add documents to */
|
|
40
|
+
namespace?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for searching the vector store.
|
|
44
|
+
*/
|
|
45
|
+
export interface SearchOptions {
|
|
46
|
+
/** Maximum number of results to return */
|
|
47
|
+
limit?: number;
|
|
48
|
+
/** Minimum similarity score threshold (0-1) */
|
|
49
|
+
scoreThreshold?: number;
|
|
50
|
+
/** Namespace or collection to search in */
|
|
51
|
+
namespace?: string;
|
|
52
|
+
/** Metadata filters to apply */
|
|
53
|
+
filter?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Options for deleting documents from the vector store.
|
|
57
|
+
*/
|
|
58
|
+
export interface DeleteOptions {
|
|
59
|
+
/** Namespace or collection to delete from */
|
|
60
|
+
namespace?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Options for creating a retrieval tool from a vector store.
|
|
64
|
+
*/
|
|
65
|
+
export interface RetrievalToolOptions {
|
|
66
|
+
/** Custom name for the tool (defaults to `${storeName}_search`) */
|
|
67
|
+
toolName?: string;
|
|
68
|
+
/** Default number of results to return */
|
|
69
|
+
defaultLimit?: number;
|
|
70
|
+
/** Default score threshold */
|
|
71
|
+
defaultScoreThreshold?: number;
|
|
72
|
+
/** Namespace to search in */
|
|
73
|
+
namespace?: string;
|
|
74
|
+
/** Whether to include document metadata in results */
|
|
75
|
+
includeMetadata?: boolean;
|
|
76
|
+
/** Default filters to apply (e.g., { projectId: "123", tenantId: "acme" }) */
|
|
77
|
+
defaultFilter?: Record<string, unknown>;
|
|
78
|
+
/** Whether to allow the agent to override filters via tool parameters */
|
|
79
|
+
allowFilterOverride?: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Options for creating an add documents tool from a vector store.
|
|
83
|
+
*/
|
|
84
|
+
export interface AddDocumentsToolOptions {
|
|
85
|
+
/** Custom name for the tool (defaults to `${storeName}_add`) */
|
|
86
|
+
toolName?: string;
|
|
87
|
+
/** Namespace to add documents to */
|
|
88
|
+
namespace?: string;
|
|
89
|
+
/** Default metadata to add to all documents (e.g., { projectId: "123", tenantId: "acme" }) */
|
|
90
|
+
defaultMetadata?: Record<string, unknown>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Options for creating a get chunk by ID tool from a vector store.
|
|
94
|
+
*/
|
|
95
|
+
export interface GetChunkByIdToolOptions {
|
|
96
|
+
/** Custom name for the tool (defaults to `${storeName}_get_chunk`) */
|
|
97
|
+
toolName?: string;
|
|
98
|
+
/** Namespace to search in */
|
|
99
|
+
namespace?: string;
|
|
100
|
+
/** Whether to include document metadata in results */
|
|
101
|
+
includeMetadata?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Abstract interface for vector database implementations.
|
|
105
|
+
*
|
|
106
|
+
* Implementations should handle:
|
|
107
|
+
* - Embedding generation (or accept pre-computed embeddings)
|
|
108
|
+
* - Vector storage and indexing
|
|
109
|
+
* - Similarity search
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* class PineconeVectorStore extends VectorStore {
|
|
114
|
+
* async addDocuments(docs: Document[]): Promise<string[]> {
|
|
115
|
+
* // Generate embeddings and upsert to Pinecone
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
* async search(query: string, options?: SearchOptions): Promise<SearchResult[]> {
|
|
119
|
+
* // Embed query and search Pinecone
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* // Create a retrieval tool for an agent
|
|
124
|
+
* const store = new PineconeVectorStore({ ... });
|
|
125
|
+
* const searchTool = store.toRetrievalTool("Search product documentation");
|
|
126
|
+
* const agent = new ClaudeAgent({ tools: [searchTool] });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare abstract class VectorStore {
|
|
130
|
+
/** Name identifier for this vector store instance */
|
|
131
|
+
abstract readonly name: string;
|
|
132
|
+
/**
|
|
133
|
+
* Add documents to the vector store.
|
|
134
|
+
* The implementation should handle embedding generation.
|
|
135
|
+
*
|
|
136
|
+
* @param documents - Documents to add
|
|
137
|
+
* @param options - Optional configuration for the add operation
|
|
138
|
+
* @returns Array of document IDs that were added
|
|
139
|
+
*/
|
|
140
|
+
abstract addDocuments(documents: Document[], options?: AddDocumentsOptions): Promise<string[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Add documents with pre-computed embeddings.
|
|
143
|
+
* Use this when you want to control the embedding process.
|
|
144
|
+
*
|
|
145
|
+
* @param documents - Documents with embeddings to add
|
|
146
|
+
* @param options - Optional configuration for the add operation
|
|
147
|
+
* @returns Array of document IDs that were added
|
|
148
|
+
*/
|
|
149
|
+
abstract addEmbeddedDocuments(documents: EmbeddedDocument[], options?: AddDocumentsOptions): Promise<string[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Search for documents similar to the query.
|
|
152
|
+
* The implementation should handle query embedding.
|
|
153
|
+
*
|
|
154
|
+
* @param query - The search query text
|
|
155
|
+
* @param options - Search configuration options
|
|
156
|
+
* @returns Array of search results with documents and scores
|
|
157
|
+
*/
|
|
158
|
+
abstract search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Search using a pre-computed embedding vector.
|
|
161
|
+
*
|
|
162
|
+
* @param embedding - The query embedding vector
|
|
163
|
+
* @param options - Search configuration options
|
|
164
|
+
* @returns Array of search results with documents and scores
|
|
165
|
+
*/
|
|
166
|
+
abstract searchByVector(embedding: number[], options?: SearchOptions): Promise<SearchResult[]>;
|
|
167
|
+
/**
|
|
168
|
+
* Delete documents by their IDs.
|
|
169
|
+
*
|
|
170
|
+
* @param ids - Array of document IDs to delete
|
|
171
|
+
* @param options - Optional configuration for the delete operation
|
|
172
|
+
* @returns Number of documents deleted
|
|
173
|
+
*/
|
|
174
|
+
abstract delete(ids: string[], options?: DeleteOptions): Promise<number>;
|
|
175
|
+
/**
|
|
176
|
+
* Delete all documents, optionally within a namespace.
|
|
177
|
+
*
|
|
178
|
+
* @param options - Optional configuration including namespace
|
|
179
|
+
*/
|
|
180
|
+
abstract clear(options?: DeleteOptions): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Get a document by its ID.
|
|
183
|
+
*
|
|
184
|
+
* @param id - The document ID
|
|
185
|
+
* @param options - Optional configuration including namespace
|
|
186
|
+
* @returns The document if found, null otherwise
|
|
187
|
+
*/
|
|
188
|
+
abstract getById(id: string, options?: DeleteOptions): Promise<Document | null>;
|
|
189
|
+
/**
|
|
190
|
+
* Get existing documents by their content hashes.
|
|
191
|
+
* Used for deduplication during ingestion.
|
|
192
|
+
*
|
|
193
|
+
* @param hashes - Array of content hashes to check
|
|
194
|
+
* @param options - Optional configuration including namespace
|
|
195
|
+
* @returns Map of hash to document ID
|
|
196
|
+
*/
|
|
197
|
+
abstract getByHashes(hashes: string[], options?: DeleteOptions): Promise<Map<string, string>>;
|
|
198
|
+
/**
|
|
199
|
+
* Create a retrieval tool that agents can use to search this vector store.
|
|
200
|
+
*
|
|
201
|
+
* @param description - Description of what data the store contains (e.g., "Search product documentation for technical specifications")
|
|
202
|
+
* @param options - Configuration options for the tool
|
|
203
|
+
* @returns A Tool instance that can be added to an agent
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const store = new LanceDBVectorStore({ ... });
|
|
208
|
+
* const tool = store.toRetrievalTool(
|
|
209
|
+
* "Search company knowledge base for HR policies and procedures",
|
|
210
|
+
* { defaultLimit: 5 }
|
|
211
|
+
* );
|
|
212
|
+
* agent.addTools([tool]);
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
toRetrievalTool(description: string, options?: RetrievalToolOptions): Tool<SearchResult[]>;
|
|
216
|
+
/**
|
|
217
|
+
* Create a tool that agents can use to add documents to this vector store.
|
|
218
|
+
*
|
|
219
|
+
* @param description - Description of what the tool does (e.g., "Store new knowledge articles in the database")
|
|
220
|
+
* @param options - Configuration options for the tool
|
|
221
|
+
* @returns A Tool instance that can be added to an agent
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const store = new LanceDBVectorStore({ ... });
|
|
226
|
+
* const tool = store.toAddDocumentsTool(
|
|
227
|
+
* "Save new information to the knowledge base for future reference"
|
|
228
|
+
* );
|
|
229
|
+
* agent.addTools([tool]);
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
toAddDocumentsTool(description: string, options?: AddDocumentsToolOptions): Tool<{
|
|
233
|
+
added: string[];
|
|
234
|
+
count: number;
|
|
235
|
+
}>;
|
|
236
|
+
/**
|
|
237
|
+
* Create a tool that agents can use to retrieve a chunk by its ID.
|
|
238
|
+
* Useful for navigating chunk chains using previousChunkId/nextChunkId metadata.
|
|
239
|
+
*
|
|
240
|
+
* @param description - Description of what the tool does (e.g., "Get a specific chunk by ID to read adjacent context")
|
|
241
|
+
* @param options - Configuration options for the tool
|
|
242
|
+
* @returns A Tool instance that can be added to an agent
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* const store = new LanceDBVectorStore({ ... });
|
|
247
|
+
* const tool = store.toGetChunkByIdTool(
|
|
248
|
+
* "Retrieve a specific chunk by ID. Use previousChunkId or nextChunkId from search results to get surrounding context."
|
|
249
|
+
* );
|
|
250
|
+
* agent.addTools([tool]);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
toGetChunkByIdTool(description: string, options?: GetChunkByIdToolOptions): Tool<Document | null>;
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=VectorStore.d.ts.map
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vector Store interface for document storage and semantic retrieval.
|
|
4
|
+
*
|
|
5
|
+
* This module provides an abstract interface for vector databases,
|
|
6
|
+
* enabling document storage with embeddings and semantic search capabilities.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VectorStore = void 0;
|
|
10
|
+
const Tool_1 = require("../tools/Tool");
|
|
11
|
+
/**
|
|
12
|
+
* Abstract interface for vector database implementations.
|
|
13
|
+
*
|
|
14
|
+
* Implementations should handle:
|
|
15
|
+
* - Embedding generation (or accept pre-computed embeddings)
|
|
16
|
+
* - Vector storage and indexing
|
|
17
|
+
* - Similarity search
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* class PineconeVectorStore extends VectorStore {
|
|
22
|
+
* async addDocuments(docs: Document[]): Promise<string[]> {
|
|
23
|
+
* // Generate embeddings and upsert to Pinecone
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* async search(query: string, options?: SearchOptions): Promise<SearchResult[]> {
|
|
27
|
+
* // Embed query and search Pinecone
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* // Create a retrieval tool for an agent
|
|
32
|
+
* const store = new PineconeVectorStore({ ... });
|
|
33
|
+
* const searchTool = store.toRetrievalTool("Search product documentation");
|
|
34
|
+
* const agent = new ClaudeAgent({ tools: [searchTool] });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
class VectorStore {
|
|
38
|
+
/**
|
|
39
|
+
* Create a retrieval tool that agents can use to search this vector store.
|
|
40
|
+
*
|
|
41
|
+
* @param description - Description of what data the store contains (e.g., "Search product documentation for technical specifications")
|
|
42
|
+
* @param options - Configuration options for the tool
|
|
43
|
+
* @returns A Tool instance that can be added to an agent
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const store = new LanceDBVectorStore({ ... });
|
|
48
|
+
* const tool = store.toRetrievalTool(
|
|
49
|
+
* "Search company knowledge base for HR policies and procedures",
|
|
50
|
+
* { defaultLimit: 5 }
|
|
51
|
+
* );
|
|
52
|
+
* agent.addTools([tool]);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
toRetrievalTool(description, options = {}) {
|
|
56
|
+
const { toolName = `${this.name}_search`, defaultLimit = 3, defaultScoreThreshold, namespace, includeMetadata = true, defaultFilter, allowFilterOverride = false, } = options;
|
|
57
|
+
const inputSchema = {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
query: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "The search query to find relevant documents",
|
|
63
|
+
},
|
|
64
|
+
limit: {
|
|
65
|
+
type: "number",
|
|
66
|
+
description: `Maximum number of results to return (default: ${defaultLimit})`,
|
|
67
|
+
},
|
|
68
|
+
...(allowFilterOverride && {
|
|
69
|
+
filter: {
|
|
70
|
+
type: "object",
|
|
71
|
+
description: "Optional metadata filters to apply to the search",
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
required: ["query", "limit"],
|
|
76
|
+
};
|
|
77
|
+
return new Tool_1.Tool({
|
|
78
|
+
name: toolName,
|
|
79
|
+
description,
|
|
80
|
+
inputSchema,
|
|
81
|
+
execute: async (input) => {
|
|
82
|
+
// Merge default filters with input filters
|
|
83
|
+
let finalFilter = defaultFilter;
|
|
84
|
+
if (allowFilterOverride && input.filter) {
|
|
85
|
+
finalFilter = { ...defaultFilter, ...input.filter };
|
|
86
|
+
}
|
|
87
|
+
const results = await this.search(input.query, {
|
|
88
|
+
limit: input.limit ?? defaultLimit,
|
|
89
|
+
scoreThreshold: defaultScoreThreshold,
|
|
90
|
+
namespace,
|
|
91
|
+
filter: finalFilter,
|
|
92
|
+
});
|
|
93
|
+
if (!includeMetadata) {
|
|
94
|
+
return results.map((r) => ({
|
|
95
|
+
document: { id: r.document.id, content: r.document.content },
|
|
96
|
+
score: r.score,
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
return results;
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a tool that agents can use to add documents to this vector store.
|
|
105
|
+
*
|
|
106
|
+
* @param description - Description of what the tool does (e.g., "Store new knowledge articles in the database")
|
|
107
|
+
* @param options - Configuration options for the tool
|
|
108
|
+
* @returns A Tool instance that can be added to an agent
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const store = new LanceDBVectorStore({ ... });
|
|
113
|
+
* const tool = store.toAddDocumentsTool(
|
|
114
|
+
* "Save new information to the knowledge base for future reference"
|
|
115
|
+
* );
|
|
116
|
+
* agent.addTools([tool]);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
toAddDocumentsTool(description, options = {}) {
|
|
120
|
+
const { toolName = `${this.name}_add`, namespace, defaultMetadata, } = options;
|
|
121
|
+
const inputSchema = {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
documents: {
|
|
125
|
+
type: "array",
|
|
126
|
+
description: "Array of documents to add",
|
|
127
|
+
items: {
|
|
128
|
+
type: "object",
|
|
129
|
+
properties: {
|
|
130
|
+
id: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Unique identifier for the document",
|
|
133
|
+
},
|
|
134
|
+
content: {
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "The text content of the document",
|
|
137
|
+
},
|
|
138
|
+
metadata: {
|
|
139
|
+
type: "object",
|
|
140
|
+
description: "Optional metadata for the document",
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
required: ["id", "content", "metadata"],
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
required: ["documents"],
|
|
148
|
+
};
|
|
149
|
+
return new Tool_1.Tool({
|
|
150
|
+
name: toolName,
|
|
151
|
+
description,
|
|
152
|
+
inputSchema,
|
|
153
|
+
execute: async (input) => {
|
|
154
|
+
// Merge default metadata into each document
|
|
155
|
+
const documentsWithMetadata = input.documents.map((doc) => ({
|
|
156
|
+
...doc,
|
|
157
|
+
metadata: { ...defaultMetadata, ...doc.metadata },
|
|
158
|
+
}));
|
|
159
|
+
const ids = await this.addDocuments(documentsWithMetadata, {
|
|
160
|
+
namespace,
|
|
161
|
+
});
|
|
162
|
+
return { added: ids, count: ids.length };
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create a tool that agents can use to retrieve a chunk by its ID.
|
|
168
|
+
* Useful for navigating chunk chains using previousChunkId/nextChunkId metadata.
|
|
169
|
+
*
|
|
170
|
+
* @param description - Description of what the tool does (e.g., "Get a specific chunk by ID to read adjacent context")
|
|
171
|
+
* @param options - Configuration options for the tool
|
|
172
|
+
* @returns A Tool instance that can be added to an agent
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const store = new LanceDBVectorStore({ ... });
|
|
177
|
+
* const tool = store.toGetChunkByIdTool(
|
|
178
|
+
* "Retrieve a specific chunk by ID. Use previousChunkId or nextChunkId from search results to get surrounding context."
|
|
179
|
+
* );
|
|
180
|
+
* agent.addTools([tool]);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
toGetChunkByIdTool(description, options = {}) {
|
|
184
|
+
const { toolName = `${this.name}_get_chunk`, namespace, includeMetadata = true, } = options;
|
|
185
|
+
const inputSchema = {
|
|
186
|
+
type: "object",
|
|
187
|
+
properties: {
|
|
188
|
+
id: {
|
|
189
|
+
type: "string",
|
|
190
|
+
description: "The chunk ID to retrieve (e.g., from previousChunkId or nextChunkId metadata)",
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
required: ["id"],
|
|
194
|
+
};
|
|
195
|
+
return new Tool_1.Tool({
|
|
196
|
+
name: toolName,
|
|
197
|
+
description,
|
|
198
|
+
inputSchema,
|
|
199
|
+
execute: async (input) => {
|
|
200
|
+
const document = await this.getById(input.id, { namespace });
|
|
201
|
+
if (!document) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
if (!includeMetadata) {
|
|
205
|
+
return {
|
|
206
|
+
id: document.id,
|
|
207
|
+
content: document.content,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
return document;
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.VectorStore = VectorStore;
|
|
216
|
+
//# sourceMappingURL=VectorStore.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector Store module for document storage and semantic retrieval.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { LanceDBVectorStore, OpenAIEmbeddings } from "@agentionai/agents";
|
|
7
|
+
*
|
|
8
|
+
* const embeddings = new OpenAIEmbeddings({
|
|
9
|
+
* model: "text-embedding-3-small",
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* const store = await LanceDBVectorStore.create({
|
|
13
|
+
* name: "docs",
|
|
14
|
+
* uri: "./data",
|
|
15
|
+
* tableName: "documents",
|
|
16
|
+
* embeddings,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* // Create tools for agents
|
|
20
|
+
* const searchTool = store.toRetrievalTool("Search documentation");
|
|
21
|
+
* const addTool = store.toAddDocumentsTool("Save new documents");
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { VectorStore, Document, EmbeddedDocument, SearchResult, AddDocumentsOptions, SearchOptions, DeleteOptions, RetrievalToolOptions, AddDocumentsToolOptions, } from "./VectorStore";
|
|
25
|
+
export { Embeddings, EmbeddingOptions } from "./Embeddings";
|
|
26
|
+
export { OpenAIEmbeddings, OpenAIEmbeddingsConfig } from "./OpenAIEmbeddings";
|
|
27
|
+
export { LanceDBVectorStore, LanceDBVectorStoreConfig, } from "./LanceDBVectorStore";
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vector Store module for document storage and semantic retrieval.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { LanceDBVectorStore, OpenAIEmbeddings } from "@agentionai/agents";
|
|
8
|
+
*
|
|
9
|
+
* const embeddings = new OpenAIEmbeddings({
|
|
10
|
+
* model: "text-embedding-3-small",
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const store = await LanceDBVectorStore.create({
|
|
14
|
+
* name: "docs",
|
|
15
|
+
* uri: "./data",
|
|
16
|
+
* tableName: "documents",
|
|
17
|
+
* embeddings,
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Create tools for agents
|
|
21
|
+
* const searchTool = store.toRetrievalTool("Search documentation");
|
|
22
|
+
* const addTool = store.toAddDocumentsTool("Save new documents");
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.LanceDBVectorStore = exports.OpenAIEmbeddings = exports.Embeddings = exports.VectorStore = void 0;
|
|
27
|
+
var VectorStore_1 = require("./VectorStore");
|
|
28
|
+
Object.defineProperty(exports, "VectorStore", { enumerable: true, get: function () { return VectorStore_1.VectorStore; } });
|
|
29
|
+
var Embeddings_1 = require("./Embeddings");
|
|
30
|
+
Object.defineProperty(exports, "Embeddings", { enumerable: true, get: function () { return Embeddings_1.Embeddings; } });
|
|
31
|
+
var OpenAIEmbeddings_1 = require("./OpenAIEmbeddings");
|
|
32
|
+
Object.defineProperty(exports, "OpenAIEmbeddings", { enumerable: true, get: function () { return OpenAIEmbeddings_1.OpenAIEmbeddings; } });
|
|
33
|
+
var LanceDBVectorStore_1 = require("./LanceDBVectorStore");
|
|
34
|
+
Object.defineProperty(exports, "LanceDBVectorStore", { enumerable: true, get: function () { return LanceDBVectorStore_1.LanceDBVectorStore; } });
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for visualization reporting.
|
|
3
|
+
* Reads from environment variables and allows programmatic overrides.
|
|
4
|
+
*/
|
|
5
|
+
export interface VizConfigOptions {
|
|
6
|
+
/** Enable/disable visualization reporting */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
/** WebSocket URL for the visualization server */
|
|
9
|
+
url?: string;
|
|
10
|
+
/** Session name for labeling */
|
|
11
|
+
sessionName?: string;
|
|
12
|
+
/** Auto-reconnect on disconnect */
|
|
13
|
+
reconnect?: boolean;
|
|
14
|
+
/** Reconnect interval in milliseconds */
|
|
15
|
+
reconnectInterval?: number;
|
|
16
|
+
/** Maximum events to queue when disconnected */
|
|
17
|
+
maxQueueSize?: number;
|
|
18
|
+
}
|
|
19
|
+
declare class VizConfigManager {
|
|
20
|
+
private config;
|
|
21
|
+
constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Load configuration from environment variables
|
|
24
|
+
*/
|
|
25
|
+
private loadFromEnvironment;
|
|
26
|
+
/**
|
|
27
|
+
* Set configuration options programmatically
|
|
28
|
+
*/
|
|
29
|
+
set(options: VizConfigOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get current configuration
|
|
32
|
+
*/
|
|
33
|
+
get(): Readonly<Required<VizConfigOptions>>;
|
|
34
|
+
/**
|
|
35
|
+
* Check if visualization is enabled
|
|
36
|
+
*/
|
|
37
|
+
isEnabled(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Get the WebSocket URL
|
|
40
|
+
*/
|
|
41
|
+
getUrl(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get session name
|
|
44
|
+
*/
|
|
45
|
+
getSessionName(): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reset to default configuration
|
|
48
|
+
*/
|
|
49
|
+
reset(): void;
|
|
50
|
+
}
|
|
51
|
+
/** Global configuration instance */
|
|
52
|
+
export declare const vizConfig: VizConfigManager;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=VizConfig.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration management for visualization reporting.
|
|
4
|
+
* Reads from environment variables and allows programmatic overrides.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.vizConfig = void 0;
|
|
8
|
+
const DEFAULT_CONFIG = {
|
|
9
|
+
enabled: false,
|
|
10
|
+
url: "ws://localhost:4242/ws/agent",
|
|
11
|
+
sessionName: "",
|
|
12
|
+
reconnect: true,
|
|
13
|
+
reconnectInterval: 5000,
|
|
14
|
+
maxQueueSize: 1000,
|
|
15
|
+
};
|
|
16
|
+
class VizConfigManager {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.config = { ...DEFAULT_CONFIG };
|
|
19
|
+
this.loadFromEnvironment();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Load configuration from environment variables
|
|
23
|
+
*/
|
|
24
|
+
loadFromEnvironment() {
|
|
25
|
+
if (typeof process !== "undefined" && process.env) {
|
|
26
|
+
if (process.env.AGENTION_VIZ_ENABLED === "true") {
|
|
27
|
+
this.config.enabled = true;
|
|
28
|
+
}
|
|
29
|
+
if (process.env.AGENTION_VIZ_URL) {
|
|
30
|
+
this.config.url = process.env.AGENTION_VIZ_URL;
|
|
31
|
+
}
|
|
32
|
+
if (process.env.AGENTION_VIZ_SESSION_NAME) {
|
|
33
|
+
this.config.sessionName = process.env.AGENTION_VIZ_SESSION_NAME;
|
|
34
|
+
}
|
|
35
|
+
if (process.env.AGENTION_VIZ_RECONNECT_INTERVAL) {
|
|
36
|
+
const interval = parseInt(process.env.AGENTION_VIZ_RECONNECT_INTERVAL, 10);
|
|
37
|
+
if (!isNaN(interval)) {
|
|
38
|
+
this.config.reconnectInterval = interval;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Set configuration options programmatically
|
|
45
|
+
*/
|
|
46
|
+
set(options) {
|
|
47
|
+
if (options.enabled !== undefined) {
|
|
48
|
+
this.config.enabled = options.enabled;
|
|
49
|
+
}
|
|
50
|
+
if (options.url !== undefined) {
|
|
51
|
+
this.config.url = options.url;
|
|
52
|
+
}
|
|
53
|
+
if (options.sessionName !== undefined) {
|
|
54
|
+
this.config.sessionName = options.sessionName;
|
|
55
|
+
}
|
|
56
|
+
if (options.reconnect !== undefined) {
|
|
57
|
+
this.config.reconnect = options.reconnect;
|
|
58
|
+
}
|
|
59
|
+
if (options.reconnectInterval !== undefined) {
|
|
60
|
+
this.config.reconnectInterval = options.reconnectInterval;
|
|
61
|
+
}
|
|
62
|
+
if (options.maxQueueSize !== undefined) {
|
|
63
|
+
this.config.maxQueueSize = options.maxQueueSize;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get current configuration
|
|
68
|
+
*/
|
|
69
|
+
get() {
|
|
70
|
+
return { ...this.config };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if visualization is enabled
|
|
74
|
+
*/
|
|
75
|
+
isEnabled() {
|
|
76
|
+
return this.config.enabled;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the WebSocket URL
|
|
80
|
+
*/
|
|
81
|
+
getUrl() {
|
|
82
|
+
return this.config.url;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get session name
|
|
86
|
+
*/
|
|
87
|
+
getSessionName() {
|
|
88
|
+
return this.config.sessionName;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reset to default configuration
|
|
92
|
+
*/
|
|
93
|
+
reset() {
|
|
94
|
+
this.config = { ...DEFAULT_CONFIG };
|
|
95
|
+
this.loadFromEnvironment();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Global configuration instance */
|
|
99
|
+
exports.vizConfig = new VizConfigManager();
|
|
100
|
+
//# sourceMappingURL=VizConfig.js.map
|