@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.
Files changed (91) hide show
  1. package/README.md +517 -0
  2. package/dist/agents/Agent.d.ts +29 -0
  3. package/dist/agents/Agent.js +28 -0
  4. package/dist/agents/AgentConfig.d.ts +118 -0
  5. package/dist/agents/AgentConfig.js +3 -0
  6. package/dist/agents/AgentEvent.d.ts +18 -0
  7. package/dist/agents/AgentEvent.js +26 -0
  8. package/dist/agents/BaseAgent.d.ts +82 -0
  9. package/dist/agents/BaseAgent.js +121 -0
  10. package/dist/agents/anthropic/ClaudeAgent.d.ts +46 -0
  11. package/dist/agents/anthropic/ClaudeAgent.js +262 -0
  12. package/dist/agents/errors/AgentError.d.ts +47 -0
  13. package/dist/agents/errors/AgentError.js +74 -0
  14. package/dist/agents/google/GeminiAgent.d.ts +63 -0
  15. package/dist/agents/google/GeminiAgent.js +395 -0
  16. package/dist/agents/mistral/MistralAgent.d.ts +47 -0
  17. package/dist/agents/mistral/MistralAgent.js +313 -0
  18. package/dist/agents/model-types.d.ts +30 -0
  19. package/dist/agents/model-types.js +8 -0
  20. package/dist/agents/openai/OpenAiAgent.d.ts +48 -0
  21. package/dist/agents/openai/OpenAiAgent.js +338 -0
  22. package/dist/chunkers/Chunker.d.ts +53 -0
  23. package/dist/chunkers/Chunker.js +174 -0
  24. package/dist/chunkers/RecursiveChunker.d.ts +52 -0
  25. package/dist/chunkers/RecursiveChunker.js +166 -0
  26. package/dist/chunkers/TextChunker.d.ts +27 -0
  27. package/dist/chunkers/TextChunker.js +50 -0
  28. package/dist/chunkers/TokenChunker.d.ts +60 -0
  29. package/dist/chunkers/TokenChunker.js +176 -0
  30. package/dist/chunkers/index.d.ts +6 -0
  31. package/dist/chunkers/index.js +14 -0
  32. package/dist/chunkers/types.d.ts +95 -0
  33. package/dist/chunkers/types.js +3 -0
  34. package/dist/graph/AgentGraph.d.ts +99 -0
  35. package/dist/graph/AgentGraph.js +115 -0
  36. package/dist/graph/BaseExecutor.d.ts +86 -0
  37. package/dist/graph/BaseExecutor.js +61 -0
  38. package/dist/graph/GraphMetrics.d.ts +143 -0
  39. package/dist/graph/GraphMetrics.js +264 -0
  40. package/dist/graph/MapExecutor.d.ts +39 -0
  41. package/dist/graph/MapExecutor.js +123 -0
  42. package/dist/graph/ParallelExecutor.d.ts +51 -0
  43. package/dist/graph/ParallelExecutor.js +103 -0
  44. package/dist/graph/Pipeline.d.ts +44 -0
  45. package/dist/graph/Pipeline.js +109 -0
  46. package/dist/graph/RouterExecutor.d.ts +89 -0
  47. package/dist/graph/RouterExecutor.js +209 -0
  48. package/dist/graph/SequentialExecutor.d.ts +44 -0
  49. package/dist/graph/SequentialExecutor.js +115 -0
  50. package/dist/graph/VotingSystem.d.ts +54 -0
  51. package/dist/graph/VotingSystem.js +106 -0
  52. package/dist/history/History.d.ts +107 -0
  53. package/dist/history/History.js +166 -0
  54. package/dist/history/RedisHistory.d.ts +27 -0
  55. package/dist/history/RedisHistory.js +55 -0
  56. package/dist/history/transformers.d.ts +102 -0
  57. package/dist/history/transformers.js +415 -0
  58. package/dist/history/types.d.ts +130 -0
  59. package/dist/history/types.js +55 -0
  60. package/dist/index.d.ts +16 -0
  61. package/dist/index.js +48 -0
  62. package/dist/ingestion/IngestionPipeline.d.ts +86 -0
  63. package/dist/ingestion/IngestionPipeline.js +266 -0
  64. package/dist/ingestion/index.d.ts +3 -0
  65. package/dist/ingestion/index.js +7 -0
  66. package/dist/ingestion/types.d.ts +74 -0
  67. package/dist/ingestion/types.js +3 -0
  68. package/dist/team/Team.d.ts +46 -0
  69. package/dist/team/Team.js +104 -0
  70. package/dist/tools/Tool.d.ts +75 -0
  71. package/dist/tools/Tool.js +137 -0
  72. package/dist/vectorstore/Embeddings.d.ts +67 -0
  73. package/dist/vectorstore/Embeddings.js +54 -0
  74. package/dist/vectorstore/LanceDBVectorStore.d.ts +149 -0
  75. package/dist/vectorstore/LanceDBVectorStore.js +338 -0
  76. package/dist/vectorstore/OpenAIEmbeddings.d.ts +45 -0
  77. package/dist/vectorstore/OpenAIEmbeddings.js +109 -0
  78. package/dist/vectorstore/VectorStore.d.ts +255 -0
  79. package/dist/vectorstore/VectorStore.js +216 -0
  80. package/dist/vectorstore/index.d.ts +28 -0
  81. package/dist/vectorstore/index.js +35 -0
  82. package/dist/viz/VizConfig.d.ts +54 -0
  83. package/dist/viz/VizConfig.js +100 -0
  84. package/dist/viz/VizReporter.d.ts +127 -0
  85. package/dist/viz/VizReporter.js +595 -0
  86. package/dist/viz/index.d.ts +31 -0
  87. package/dist/viz/index.js +51 -0
  88. package/dist/viz/types.d.ts +105 -0
  89. package/dist/viz/types.js +7 -0
  90. package/package.json +109 -0
  91. package/readme.md +1 -0
@@ -0,0 +1,137 @@
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.Tool = exports.ToolResultEvent = exports.ToolEvent = void 0;
7
+ const events_1 = __importDefault(require("events"));
8
+ const VizReporter_1 = require("../viz/VizReporter");
9
+ const VizConfig_1 = require("../viz/VizConfig");
10
+ class ToolEvent {
11
+ constructor(target, input, id, agentId, agentName) {
12
+ this.target = target;
13
+ this.input = input;
14
+ this.id = id;
15
+ this.agentId = agentId;
16
+ this.agentName = agentName;
17
+ this.defaultPrevented = false;
18
+ }
19
+ preventDefault() {
20
+ this.defaultPrevented = true;
21
+ }
22
+ get isDefaultPrevented() {
23
+ return this.defaultPrevented;
24
+ }
25
+ }
26
+ exports.ToolEvent = ToolEvent;
27
+ ToolEvent.EXECUTE = "execute";
28
+ class ToolResultEvent extends ToolEvent {
29
+ constructor(target, input, id, result, agentId, agentName) {
30
+ super(target, input, id, agentId, agentName);
31
+ this.target = target;
32
+ this.input = input;
33
+ this.id = id;
34
+ this.result = result;
35
+ this.agentId = agentId;
36
+ this.agentName = agentName;
37
+ this.eventName = "ToolResult";
38
+ }
39
+ }
40
+ exports.ToolResultEvent = ToolResultEvent;
41
+ ToolResultEvent.RESULT = "toolResult";
42
+ /**
43
+ * Tools are used to retrieve additional information for LLMs, so they can provide better results. Examples could be
44
+ * Retrieving weather information, stock prices or specific price information.
45
+ *
46
+ * @param T Generic. Format of the tool result
47
+
48
+ */
49
+ class Tool extends events_1.default {
50
+ /**
51
+ * Agents can act as assistants to other agents. This static method creates a tool
52
+ * @param agent The agent that will act as an assistant
53
+ * @param description Th
54
+ * @returns Tool
55
+ */
56
+ static fromAgent(agent, description) {
57
+ return new Tool({
58
+ name: agent.getName().replace(/ /g, "_"),
59
+ description: description ? description : agent.getDescription(),
60
+ inputSchema: {
61
+ type: "object",
62
+ properties: {
63
+ instructions: {
64
+ type: "string",
65
+ description: "Detailed instructions for the agent.",
66
+ },
67
+ },
68
+ required: ["instructions"],
69
+ },
70
+ execute: async (input) => {
71
+ try {
72
+ return (await agent.execute(input.instructions));
73
+ }
74
+ catch (error) {
75
+ return JSON.stringify({
76
+ error: "Failed to execute instructions: " + error.message,
77
+ });
78
+ }
79
+ },
80
+ });
81
+ }
82
+ constructor(config) {
83
+ super();
84
+ this.executeFn = config.execute;
85
+ this.context = config.context || null;
86
+ this.name = config.name;
87
+ this.description = config.description;
88
+ this.schema = config.inputSchema;
89
+ }
90
+ async execute(agentId, agentName, input, id, agentModel, agentVendor) {
91
+ const event = new ToolEvent(this, input, id, agentId, agentName);
92
+ this.emit(ToolEvent.EXECUTE, event);
93
+ if (event.isDefaultPrevented) {
94
+ throw new Error("Tool execution prevented, do not try this tool again with this input");
95
+ }
96
+ // Visualization reporting
97
+ let vizEventId;
98
+ if (VizConfig_1.vizConfig.isEnabled()) {
99
+ const vizSource = {
100
+ agentId,
101
+ agentName,
102
+ model: agentModel || "unknown",
103
+ vendor: agentVendor || "anthropic",
104
+ };
105
+ vizEventId = VizReporter_1.vizReporter.toolStart(this.name, id, input, vizSource);
106
+ }
107
+ try {
108
+ const result = await this.executeFn(input, this.context);
109
+ const resultEvent = new ToolResultEvent(this, input, id, result, agentId, agentName);
110
+ this.emit(ToolResultEvent.RESULT, resultEvent);
111
+ if (resultEvent.isDefaultPrevented) {
112
+ throw new Error("Tool result prevented, do not try this tool again with this input");
113
+ }
114
+ // Report tool completion to viz
115
+ if (vizEventId) {
116
+ VizReporter_1.vizReporter.toolComplete(vizEventId, this.name, id, true, result);
117
+ }
118
+ return result;
119
+ }
120
+ catch (error) {
121
+ // Report tool error to viz
122
+ if (vizEventId) {
123
+ VizReporter_1.vizReporter.toolError(vizEventId, this.name, id, error?.message || "Unknown error");
124
+ }
125
+ throw error;
126
+ }
127
+ }
128
+ getPrompt(_vendor) {
129
+ return {
130
+ name: this.name,
131
+ description: this.description,
132
+ input_schema: this.schema,
133
+ };
134
+ }
135
+ }
136
+ exports.Tool = Tool;
137
+ //# sourceMappingURL=Tool.js.map
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Embeddings interface for generating vector representations of text.
3
+ *
4
+ * This module provides an abstract interface for embedding providers,
5
+ * allowing vector stores to work with any embedding service.
6
+ */
7
+ /**
8
+ * Configuration for embedding operations.
9
+ */
10
+ export interface EmbeddingOptions {
11
+ /** Model identifier (provider-specific) */
12
+ model?: string;
13
+ /** Number of dimensions for the embedding (if configurable) */
14
+ dimensions?: number;
15
+ }
16
+ /**
17
+ * Abstract interface for embedding providers.
18
+ *
19
+ * Implementations generate vector representations of text that can be
20
+ * used for semantic similarity search in vector stores.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * class OpenAIEmbeddings extends Embeddings {
25
+ * async embed(texts: string[]): Promise<number[][]> {
26
+ * const response = await openai.embeddings.create({
27
+ * model: this.model,
28
+ * input: texts,
29
+ * });
30
+ * return response.data.map(d => d.embedding);
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ export declare abstract class Embeddings {
36
+ /** Name identifier for this embeddings provider */
37
+ abstract readonly name: string;
38
+ /** The model being used for embeddings */
39
+ abstract readonly model: string;
40
+ /** Number of dimensions in the output vectors */
41
+ abstract readonly dimensions: number;
42
+ /**
43
+ * Generate embeddings for multiple texts.
44
+ *
45
+ * @param texts - Array of text strings to embed
46
+ * @returns Array of embedding vectors (one per input text)
47
+ */
48
+ abstract embed(texts: string[]): Promise<number[][]>;
49
+ /**
50
+ * Generate embedding for a single text.
51
+ * Default implementation calls embed() with a single-item array.
52
+ *
53
+ * @param text - Text string to embed
54
+ * @returns Embedding vector
55
+ */
56
+ embedOne(text: string): Promise<number[]>;
57
+ /**
58
+ * Generate embedding for a search query.
59
+ * Some providers use different models/settings for queries vs documents.
60
+ * Default implementation calls embedOne().
61
+ *
62
+ * @param query - Query text to embed
63
+ * @returns Embedding vector optimized for query
64
+ */
65
+ embedQuery(query: string): Promise<number[]>;
66
+ }
67
+ //# sourceMappingURL=Embeddings.d.ts.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * Embeddings interface for generating vector representations of text.
4
+ *
5
+ * This module provides an abstract interface for embedding providers,
6
+ * allowing vector stores to work with any embedding service.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Embeddings = void 0;
10
+ /**
11
+ * Abstract interface for embedding providers.
12
+ *
13
+ * Implementations generate vector representations of text that can be
14
+ * used for semantic similarity search in vector stores.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * class OpenAIEmbeddings extends Embeddings {
19
+ * async embed(texts: string[]): Promise<number[][]> {
20
+ * const response = await openai.embeddings.create({
21
+ * model: this.model,
22
+ * input: texts,
23
+ * });
24
+ * return response.data.map(d => d.embedding);
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ class Embeddings {
30
+ /**
31
+ * Generate embedding for a single text.
32
+ * Default implementation calls embed() with a single-item array.
33
+ *
34
+ * @param text - Text string to embed
35
+ * @returns Embedding vector
36
+ */
37
+ async embedOne(text) {
38
+ const results = await this.embed([text]);
39
+ return results[0];
40
+ }
41
+ /**
42
+ * Generate embedding for a search query.
43
+ * Some providers use different models/settings for queries vs documents.
44
+ * Default implementation calls embedOne().
45
+ *
46
+ * @param query - Query text to embed
47
+ * @returns Embedding vector optimized for query
48
+ */
49
+ async embedQuery(query) {
50
+ return this.embedOne(query);
51
+ }
52
+ }
53
+ exports.Embeddings = Embeddings;
54
+ //# sourceMappingURL=Embeddings.js.map
@@ -0,0 +1,149 @@
1
+ /**
2
+ * LanceDB implementation of the VectorStore interface.
3
+ *
4
+ * LanceDB is an embedded vector database that runs locally or can connect
5
+ * to cloud storage. It provides fast vector search with automatic indexing.
6
+ *
7
+ * @requires @lancedb/lancedb - Install with: npm install @lancedb/lancedb
8
+ * @requires apache-arrow - Install with: npm install apache-arrow
9
+ */
10
+ import type { Connection, Table, ConnectionOptions } from "@lancedb/lancedb";
11
+ import { VectorStore, Document, EmbeddedDocument, SearchResult, AddDocumentsOptions, SearchOptions, DeleteOptions } from "./VectorStore";
12
+ import { Embeddings } from "./Embeddings";
13
+ /**
14
+ * Configuration for LanceDBVectorStore.
15
+ */
16
+ export interface LanceDBVectorStoreConfig {
17
+ /** Name identifier for this store instance */
18
+ name: string;
19
+ /** URI for the LanceDB database (local path or cloud URI) */
20
+ uri: string;
21
+ /** Name of the table to use */
22
+ tableName: string;
23
+ /** Embeddings provider for automatic embedding generation */
24
+ embeddings?: Embeddings;
25
+ /** Vector dimensions (required if no embeddings provider, defaults to embeddings.dimensions) */
26
+ dimensions?: number;
27
+ /** Additional connection options */
28
+ connectionOptions?: Partial<ConnectionOptions>;
29
+ }
30
+ /**
31
+ * LanceDB implementation of the VectorStore interface.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { LanceDBVectorStore, OpenAIEmbeddings } from "@agentionai/agents";
36
+ *
37
+ * // Create with OpenAI embeddings
38
+ * const embeddings = new OpenAIEmbeddings({
39
+ * model: "text-embedding-3-small",
40
+ * });
41
+ *
42
+ * const store = await LanceDBVectorStore.create({
43
+ * name: "knowledge_base",
44
+ * uri: "./my-database",
45
+ * tableName: "documents",
46
+ * embeddings,
47
+ * });
48
+ *
49
+ * // Add documents (embeddings generated automatically)
50
+ * await store.addDocuments([
51
+ * { id: "1", content: "LanceDB is a vector database" },
52
+ * { id: "2", content: "Vector search enables semantic queries" },
53
+ * ]);
54
+ *
55
+ * // Search
56
+ * const results = await store.search("What is LanceDB?", { limit: 5 });
57
+ *
58
+ * // Create a tool for agents
59
+ * const searchTool = store.toRetrievalTool("Search the knowledge base");
60
+ * ```
61
+ */
62
+ export declare class LanceDBVectorStore extends VectorStore {
63
+ readonly name: string;
64
+ private connection;
65
+ private table;
66
+ private embeddings?;
67
+ private tableName;
68
+ private dimensions;
69
+ private constructor();
70
+ /**
71
+ * Create a new LanceDBVectorStore instance.
72
+ *
73
+ * This is an async factory method since LanceDB connection is asynchronous.
74
+ *
75
+ * @param config - Configuration for the store
76
+ * @returns A configured LanceDBVectorStore instance
77
+ *
78
+ * @throws Error if @lancedb/lancedb is not installed
79
+ */
80
+ static create(config: LanceDBVectorStoreConfig): Promise<LanceDBVectorStore>;
81
+ /**
82
+ * Add documents to the vector store.
83
+ * If an embeddings provider is configured, embeddings are generated automatically.
84
+ */
85
+ addDocuments(documents: Document[], _options?: AddDocumentsOptions): Promise<string[]>;
86
+ /**
87
+ * Add documents with pre-computed embeddings.
88
+ */
89
+ addEmbeddedDocuments(documents: EmbeddedDocument[], _options?: AddDocumentsOptions): Promise<string[]>;
90
+ /**
91
+ * Search for documents similar to the query.
92
+ */
93
+ search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
94
+ /**
95
+ * Search using a pre-computed embedding vector.
96
+ */
97
+ searchByVector(embedding: number[], options?: SearchOptions): Promise<SearchResult[]>;
98
+ /**
99
+ * Delete documents by their IDs.
100
+ */
101
+ delete(ids: string[], _options?: DeleteOptions): Promise<number>;
102
+ /**
103
+ * Delete all documents.
104
+ */
105
+ clear(_options?: DeleteOptions): Promise<void>;
106
+ /**
107
+ * Get a document by its ID.
108
+ */
109
+ getById(id: string, _options?: DeleteOptions): Promise<Document | null>;
110
+ /**
111
+ * Get existing documents by their content hashes.
112
+ * Used for deduplication during ingestion.
113
+ */
114
+ getByHashes(hashes: string[], _options?: DeleteOptions): Promise<Map<string, string>>;
115
+ /**
116
+ * Get the underlying LanceDB connection.
117
+ */
118
+ getConnection(): Connection;
119
+ /**
120
+ * Get the underlying LanceDB table.
121
+ */
122
+ getTable(): Table;
123
+ /**
124
+ * Get the configured embeddings provider.
125
+ */
126
+ getEmbeddings(): Embeddings | undefined;
127
+ /**
128
+ * Get the vector dimensions.
129
+ */
130
+ getDimensions(): number;
131
+ /**
132
+ * Create an index on the vector column for faster searches.
133
+ * Recommended for tables with more than 10,000 rows.
134
+ */
135
+ createIndex(): Promise<void>;
136
+ /**
137
+ * Optimize the table for better performance.
138
+ */
139
+ optimize(): Promise<void>;
140
+ /**
141
+ * Build a SQL filter string from a filter object.
142
+ */
143
+ private buildFilterString;
144
+ /**
145
+ * Process raw LanceDB results into SearchResult format.
146
+ */
147
+ private processResults;
148
+ }
149
+ //# sourceMappingURL=LanceDBVectorStore.d.ts.map