@voltagent/core 0.1.2 → 0.1.3

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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 VoltAgent Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,44 +1,190 @@
1
- # @voltagent/core
1
+ <div align="center">
2
+ <a href="https://voltagent.dev/">
3
+ <img width="1800" alt="435380213-b6253409-8741-462b-a346-834cd18565a9" src="https://github.com/user-attachments/assets/452a03e7-eeda-4394-9ee7-0ffbcf37245c" />
4
+ </a>
2
5
 
3
- Core package for the VoltAgent framework - a framework for building AI-powered agents.
6
+ <br/>
7
+ <br/>
4
8
 
5
- ## Installation
9
+ <div align="center">
10
+ <a href="https://voltagent.dev">Home Page</a> |
11
+ <a href="https://voltagent.dev/docs/">Documentation</a> |
12
+ <a href="https://github.com/voltagent/voltagent/tree/main/examples">Examples</a> |
13
+ <a href="https://s.voltagent.dev/discord">Discord</a> |
14
+ <a href="https://voltagent.dev/blog/">Blog</a>
15
+ </div>
16
+ </div>
6
17
 
7
- You can install the package via npm, yarn, or pnpm:
18
+ <br/>
8
19
 
9
- ```bash
10
- # npm
11
- npm install @voltagent/core
20
+ <div align="center">
21
+ <strong>VoltAgent is an open source TypeScript framework for building and orchestrating AI agents.</strong><br>
22
+ Escape the limitations of no-code builders and the complexity of starting from scratch.
23
+ <br />
24
+ <br />
25
+ </div>
26
+
27
+ <div align="center">
28
+
29
+ [![npm version](https://img.shields.io/npm/v/@voltagent/core.svg)](https://www.npmjs.com/package/@voltagent/core)
30
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](CODE_OF_CONDUCT.md)
31
+ [![Discord](https://img.shields.io/discord/1361559153780195478.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://s.voltagent.dev/discord)
32
+ [![Twitter Follow](https://img.shields.io/twitter/follow/voltagent_dev?style=social)](https://twitter.com/voltagent_dev)
33
+
34
+ </div>
35
+
36
+ <br/>
37
+
38
+ <div align="center">
39
+ <a href="https://voltagent.dev/">
40
+ <img width="896" alt="flow" src="https://github.com/user-attachments/assets/f0627868-6153-4f63-ba7f-bdfcc5dd603d" />
41
+ </a>
42
+
43
+ </div>
44
+
45
+ ## What is VoltAgent?
46
+
47
+ > An **AI Agent Framework** provides the foundational structure and tools needed to build applications powered by autonomous agents. These agents, often driven by Large Language Models (LLMs), can perceive their environment, make decisions, and take actions to achieve specific goals. Building such agents from scratch involves managing complex interactions with LLMs, handling state, connecting to external tools and data, and orchestrating workflows.
48
+
49
+ **VoltAgent** is an open-source TypeScript framework that acts as this essential toolkit. It simplifies the development of AI agent applications by providing modular building blocks, standardized patterns, and abstractions. Whether you're creating chatbots, virtual assistants, automated workflows, or complex multi-agent systems, VoltAgent handles the underlying complexity, allowing you to focus on defining your agents' capabilities and logic.
50
+
51
+ Instead of building everything from scratch, VoltAgent provides ready-made, modular building blocks:
52
+
53
+ - **Core Engine (`@voltagent/core`)**: The heart of VoltAgent, providing fundamental capabilities for your AI agents Define individual agents with specific roles, tools, and memory.
54
+ - **Multi-Agent Systems**: Architect complex applications by coordinating multiple specialized agents using Supervisors.
55
+ - **Extensible Packages**: Enhance functionality with packages like `@voltagent/voice` for voice interactions.
56
+ - **Tooling & Integrations**: Equip agents with tools to connect to external APIs, databases, and services, enabling them to perform real-world tasks. **Supports the [Model Control Protocol (MCP)](https://modelcontextprotocol.io/) for standardized tool interactions.**
57
+ - **Data Retrieval & RAG**: Implement specialized retriever agents for efficient information fetching and **Retrieval-Augmented Generation (RAG)**.
58
+ - **Memory**: Enable agents to remember past interactions for more natural and context-aware conversations.
59
+ - **LLM Compatibility**: Works with popular AI models from OpenAI, Google, Anthropic, and more, allowing easy switching.
60
+ - **Developer Ecosystem**: Includes helpers like `create-voltagent-app`, `@voltagent/cli`, and the visual [VoltAgent Console](https://console.voltagent.dev) for quick setup, monitoring, and debugging.
61
+
62
+ In essence, VoltAgent helps developers build sophisticated AI applications faster and more reliably, avoiding repetitive setup and the limitations of simpler tools.
63
+
64
+ ## Why VoltAgent?
65
+
66
+ Building AI applications often involves a trade-off:
67
+
68
+ 1. **DIY Approach:** Using basic AI provider tools offers control but leads to complex, hard-to-manage code and repeated effort.
69
+ 2. **No-Code Builders:** Simpler initially but often restrictive, limiting customization, provider choice, and complexity.
70
+
71
+ VoltAgent provides a middle ground, offering structure and components without sacrificing flexibility:
72
+
73
+ - **Build Faster:** Accelerate development with pre-built components compared to starting from scratch.
74
+ - **Maintainable Code:** Encourages organization for easier updates and debugging.
75
+ - **Scalability:** Start simple and easily scale to complex, multi-agent systems handling intricate workflows.
76
+ - **Flexibility:** Full control over agent behavior, LLM choice, tool integrations, and UI connections.
77
+ - **Avoid Lock-in:** Freedom to switch AI providers and models as needed.
78
+ - **Cost Efficiency:** Features designed to optimize AI service usage and reduce redundant calls.
79
+ - **Visual Monitoring:** Use the [VoltAgent Console](https://console.voltagent.dev) to track agent performance, inspect state, and debug visually.
80
+
81
+ VoltAgent empowers developers to build their envisioned AI applications efficiently, from simple helpers to complex systems.
82
+
83
+ ## ⚡ Quick Start
12
84
 
13
- # yarn
14
- yarn add @voltagent/core
85
+ Create a new VoltAgent project in seconds using the `create-voltagent-app` CLI tool:
15
86
 
16
- # pnpm
17
- pnpm add @voltagent/core
87
+ ```bash
88
+ npm create voltagent-app@latest
18
89
  ```
19
90
 
20
- ## Basic Usage
91
+ This command guides you through setup.
92
+
93
+ You'll see the starter code in `src/index.ts` to get you started with the VoltAgent framework.
21
94
 
22
95
  ```typescript
23
- import { log, initVoltAgent } from "@voltagent/core";
96
+ import { VoltAgent, Agent } from "@voltagent/core";
97
+ import { VercelAIProvider } from "@voltagent/vercel-ai"; // Example provider
98
+ import { openai } from "@ai-sdk/openai"; // Example model
99
+
100
+ // Define a simple agent
101
+ const agent = new Agent({
102
+ name: "my-agent",
103
+ description: "A helpful assistant that answers questions without using tools",
104
+ // Note: You can swap VercelAIProvider and openai with other supported providers/models
105
+ llm: new VercelAIProvider(),
106
+ model: openai("gpt-4o-mini"),
107
+ });
108
+
109
+ // Initialize VoltAgent with your agent(s)
110
+ new VoltAgent({
111
+ agents: {
112
+ agent,
113
+ },
114
+ });
115
+ ```
24
116
 
25
- // Initialize the framework with debug mode
26
- initVoltAgent({ debug: true });
117
+ Afterwards, navigate to your project and run:
118
+
119
+ ```bash
120
+ npm run dev
121
+ ```
122
+
123
+ When you run the dev command, tsx will compile and run your code. You should see the VoltAgent server startup message in your terminal:
124
+
125
+ ```
126
+ ══════════════════════════════════════════════════
127
+ VOLTAGENT SERVER STARTED SUCCESSFULLY
128
+ ══════════════════════════════════════════════════
129
+ ✓ HTTP Server: http://localhost:3141
27
130
 
28
- // Use logging function
29
- log("Application started");
131
+ Developer Console: https://console.voltagent.dev
132
+ ══════════════════════════════════════════════════
30
133
  ```
31
134
 
32
- ## API Reference
135
+ Your agent is now running! To interact with it:
136
+
137
+ 1. Open the Console: Click the [VoltAgent Console](https://console.voltagent.dev) link in your terminal output (or copy-paste it into your browser).
138
+ 2. Find Your Agent: On the VoltAgent Console page, you should see your agent listed (e.g., "my-agent").
139
+ 3. Open Agent Details: Click on your agent's name.
140
+ 4. Start Chatting: On the agent detail page, click the chat icon in the bottom right corner to open the chat window.
141
+ 5. Send a Message: Type a message like "Hello" and press Enter.
142
+
143
+ ![VoltAgent Developer Console Demo](https://github.com/user-attachments/assets/0adbec33-1373-4cf4-b67d-825f7baf1cb4)
144
+
145
+ ## Key Features
146
+
147
+ - **Agent Core:** Define agents with descriptions, LLM providers, tools, and memory management.
148
+ - **Multi-Agent Systems:** Build complex workflows using Supervisor Agents coordinating multiple specialized Sub-Agents.
149
+ - **Tool Usage & Lifecycle:** Equip agents with custom or pre-built tools (functions) with type-safety (Zod), lifecycle hooks, and cancellation support to interact with external systems.
150
+ - **Flexible LLM Support:** Integrate seamlessly with various LLM providers (OpenAI, Anthropic, Google, etc.) and easily switch between models.
151
+ - **Memory Management:** Enable agents to retain context across interactions using different configurable memory providers.
152
+ - **Observability & Debugging:** Visually monitor agent states, interactions, logs, and performance via the [VoltAgent Console](https://console.voltagent.dev).
153
+ - **Voice Interaction:** Build voice-enabled agents capable of speech recognition and synthesis using the `@voltagent/voice` package.
154
+ - **Data Retrieval & RAG:** Integrate specialized retriever agents for efficient information fetching and **Retrieval-Augmented Generation (RAG)** from various sources.
155
+ - **Model Control Protocol (MCP) Support:** Connect to external tool servers (HTTP/stdio) adhering to the [MCP standard](https://modelcontextprotocol.io/) for extended capabilities.
156
+ - **Prompt Engineering Tools:** Leverage utilities like `createPrompt` for crafting and managing effective prompts for your agents.
157
+ - **Framework Compatibility:** Designed for easy integration into existing Node.js applications and popular frameworks.
158
+
159
+ ## Use Cases
160
+
161
+ VoltAgent is versatile and can power a wide range of AI-driven applications:
162
+
163
+ - **Complex Workflow Automation:** Orchestrate multi-step processes involving various tools, APIs, and decision points using coordinated agents.
164
+ - **Intelligent Data Pipelines:** Build agents that fetch, process, analyze, and transform data from diverse sources.
165
+ - **AI-Powered Internal Tools & Dashboards:** Create interactive internal applications that leverage AI for analysis, reporting, or task automation, often integrated with UIs using hooks.
166
+ - **Automated Customer Support Agents:** Develop sophisticated chatbots that can understand context (memory), use tools (e.g., check order status), and escalate complex issues.
167
+ - **Repository Analysis & Codebase Automation:** Analyze code repositories, automate refactoring tasks, generate documentation, or manage CI/CD processes.
168
+ - **Retrieval-Augmented Generation (RAG) Systems:** Build agents that retrieve relevant information from knowledge bases (using retriever agents) before generating informed responses.
169
+ - **Voice-Controlled Interfaces & Applications:** Utilize the `@voltagent/voice` package to create applications that respond to and generate spoken language.
170
+ - **Personalized User Experiences:** Develop agents that adapt responses and actions based on user history and preferences stored in memory.
171
+ - **Real-time Monitoring & Alerting:** Design agents that continuously monitor data streams or systems and trigger actions or notifications based on defined conditions.
172
+ - **And Virtually Anything Else...**: If you can imagine an AI agent doing it, VoltAgent can likely help you build it! ⚡
173
+
174
+ ## Learning VoltAgent
175
+
176
+ - **[Documentation](https://voltagent.dev/docs/)**: Dive into guides, concepts, and tutorials.
177
+ - **[Examples](https://github.com/voltagent/voltagent/tree/main/examples)**: Explore practical implementations.
178
+ - **[Blog](https://voltagent.dev/blog/)**: Read more about technical insights, and best practices.
33
179
 
34
- ### `initVoltAgent(options?: VoltAgentOptions)`
180
+ ## Contribution
35
181
 
36
- Initializes the VoltAgent framework.
182
+ We welcome contributions! Please refer to the contribution guidelines (link needed if available). Join our [Discord](https://s.voltagent.dev/discord) server for questions and discussions.
37
183
 
38
- ### `log(message: string, level?: LogLevel)`
184
+ ## Community ♥️ Thanks
39
185
 
40
- Logs a message with the VoltAgent prefix.
186
+ Your stars help us reach more developers! If you find VoltAgent useful, please consider giving us a star on GitHub to support the project and help others discover it.
41
187
 
42
188
  ## License
43
189
 
44
- MIT
190
+ Licensed under the MIT License, Copyright © 2025-present VoltAgent.
package/dist/index.js CHANGED
@@ -4083,9 +4083,8 @@ ${context}`;
4083
4083
  content: input
4084
4084
  }
4085
4085
  ];
4086
- } else {
4087
- return [...messages, ...input];
4088
4086
  }
4087
+ return [...messages, ...input];
4089
4088
  });
4090
4089
  }
4091
4090
  /**
@@ -4100,13 +4099,18 @@ ${context}`;
4100
4099
  prepareTextOptions(options = {}) {
4101
4100
  const { tools: dynamicTools } = options;
4102
4101
  const toolsToUse = this.toolManager.prepareToolsForGeneration(dynamicTools);
4103
- if (this.subAgentManager.hasSubAgents() && !toolsToUse.some((tool2) => tool2.name === "delegate_task")) {
4102
+ if (this.subAgentManager.hasSubAgents()) {
4104
4103
  const delegateTool = this.subAgentManager.createDelegateTool(__spreadValues({
4105
4104
  sourceAgent: this,
4106
4105
  currentHistoryEntryId: options.historyEntryId
4107
4106
  }, options));
4108
- toolsToUse.push(delegateTool);
4109
- this.toolManager.addTools([delegateTool]);
4107
+ const delegateIndex = toolsToUse.findIndex((tool2) => tool2.name === "delegate_task");
4108
+ if (delegateIndex >= 0) {
4109
+ toolsToUse[delegateIndex] = delegateTool;
4110
+ } else {
4111
+ toolsToUse.push(delegateTool);
4112
+ this.toolManager.addTools([delegateTool]);
4113
+ }
4110
4114
  }
4111
4115
  return {
4112
4116
  tools: toolsToUse,
@@ -4311,7 +4315,7 @@ ${context}`;
4311
4315
  usage: response.usage,
4312
4316
  status: "completed"
4313
4317
  });
4314
- this.addAgentEvent(context, "completed", "completed", {
4318
+ this.addAgentEvent(context, "finished", "completed", {
4315
4319
  output: response.text,
4316
4320
  usage: response.usage,
4317
4321
  affectedNodeId: `agent_${this.id}`,
@@ -4323,7 +4327,7 @@ ${context}`;
4323
4327
  return typedResponse;
4324
4328
  } catch (error) {
4325
4329
  context.eventUpdaters.clear();
4326
- this.addAgentEvent(context, "completed", "error", {
4330
+ this.addAgentEvent(context, "finished", "error", {
4327
4331
  error,
4328
4332
  errorMessage: error instanceof Error ? error.message : "Unknown error",
4329
4333
  affectedNodeId: `agent_${this.id}`,
@@ -4441,7 +4445,7 @@ ${context}`;
4441
4445
  usage: result == null ? void 0 : result.usage,
4442
4446
  status: "completed"
4443
4447
  });
4444
- this.addAgentEvent(context, "completed", "completed", {
4448
+ this.addAgentEvent(context, "finished", "completed", {
4445
4449
  output: (result == null ? void 0 : result.text) || ((_f = (_e = (_d = result == null ? void 0 : result.choices) == null ? void 0 : _d[0]) == null ? void 0 : _e.message) == null ? void 0 : _f.content) || "",
4446
4450
  usage: result == null ? void 0 : result.usage,
4447
4451
  affectedNodeId: `agent_${this.id}`,
@@ -4455,7 +4459,7 @@ ${context}`;
4455
4459
  }),
4456
4460
  onError: (error) => __async(this, null, function* () {
4457
4461
  context.eventUpdaters.clear();
4458
- this.addAgentEvent(context, "completed", "error", {
4462
+ this.addAgentEvent(context, "finished", "error", {
4459
4463
  error,
4460
4464
  errorMessage: error instanceof Error ? error.message : "Unknown error",
4461
4465
  affectedNodeId: `agent_${this.id}`,
@@ -4525,7 +4529,7 @@ ${context}`;
4525
4529
  })
4526
4530
  }));
4527
4531
  const responseStr = typeof response === "string" ? response : JSON.stringify(response == null ? void 0 : response.object);
4528
- this.addAgentEvent(context, "completed", "completed", {
4532
+ this.addAgentEvent(context, "finished", "completed", {
4529
4533
  output: responseStr,
4530
4534
  usage: response.usage,
4531
4535
  affectedNodeId: `agent_${this.id}`,
@@ -4541,7 +4545,7 @@ ${context}`;
4541
4545
  const typedResponse = response;
4542
4546
  return typedResponse;
4543
4547
  } catch (error) {
4544
- this.addAgentEvent(context, "completed", "error", {
4548
+ this.addAgentEvent(context, "finished", "error", {
4545
4549
  error,
4546
4550
  errorMessage: error instanceof Error ? error.message : "Unknown error",
4547
4551
  affectedNodeId: `agent_${this.id}`,
@@ -4604,7 +4608,7 @@ ${context}`;
4604
4608
  onFinish: (result) => __async(this, null, function* () {
4605
4609
  var _a2, _b2;
4606
4610
  const responseStr = typeof result === "string" ? result : JSON.stringify(result.object);
4607
- this.addAgentEvent(context, "completed", "completed", {
4611
+ this.addAgentEvent(context, "finished", "completed", {
4608
4612
  output: responseStr,
4609
4613
  usage: result == null ? void 0 : result.usage,
4610
4614
  affectedNodeId: `agent_${this.id}`,
@@ -4622,7 +4626,7 @@ ${context}`;
4622
4626
  }
4623
4627
  }),
4624
4628
  onError: (error) => __async(this, null, function* () {
4625
- this.addAgentEvent(context, "completed", "error", {
4629
+ this.addAgentEvent(context, "finished", "error", {
4626
4630
  error,
4627
4631
  errorMessage: error instanceof Error ? error.message : "Unknown error",
4628
4632
  affectedNodeId: `agent_${this.id}`,
@@ -4641,7 +4645,7 @@ ${context}`;
4641
4645
  const typedResponse = response;
4642
4646
  return typedResponse;
4643
4647
  } catch (error) {
4644
- this.addAgentEvent(context, "completed", "error", {
4648
+ this.addAgentEvent(context, "finished", "error", {
4645
4649
  error,
4646
4650
  errorMessage: error instanceof Error ? error.message : "Unknown error",
4647
4651
  affectedNodeId: `agent_${this.id}`,