@arvo-tools/agentic 1.2.0 → 1.2.1
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 +212 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,223 @@
|
|
|
1
1
|
# @arvo-tools/agentic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Official AI Agent toolkit for the Arvo event-driven ecosystem**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@arvo-tools/agentic)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
`@arvo-tools/agentic` extends Arvo's event-driven architecture with production-grade AI agent capabilities. Agents built with this toolkit operate as standard Arvo event handlers, accepting and emitting events while participating in workflows alongside other handlers in your system. This design philosophy ensures that AI agents aren't isolated or special components in your system but rather first-class citizens in your event-driven infrastructure, capable of seamlessly integrating with existing Arvo-based services, workflows and mesh.
|
|
9
|
+
|
|
10
|
+
The toolkit provides a robust foundation for building intelligent agents that maintain consistency with Arvo's core principles: contract-first development, strong type safety, and infrastructure independence. Whether you're building a single autonomous agent or orchestrating multiple agents in complex workflows, `@arvo-tools/agentic` offers the abstractions and utilities needed to develop, test, and deploy AI-driven components that behave predictably within your distributed system.
|
|
4
11
|
|
|
5
12
|
## Installation
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
Before installing `@arvo-tools/agentic`, you'll need to install the Arvo peer dependencies. While you don't need to adopt the complete Arvo architecture to use Arvo Agent in your application, the peer dependencies are required for the agent to function correctly. These dependencies provide the foundational event-handling infrastructure, type definitions, and runtime utilities that enable agents to communicate effectively within the Arvo ecosystem.
|
|
15
|
+
|
|
16
|
+
For the most current Arvo peer dependencies and detailed installation instructions, please refer to the [official installation guide](https://www.arvo.land/#install-arvo). The guide includes version compatibility information and platform-specific considerations that will help ensure a smooth setup process.
|
|
17
|
+
|
|
18
|
+
After installing the peer dependencies, you can add this package to your application using your preferred package manager. The package is distributed through npm and is compatible with all major Node.js package managers:
|
|
19
|
+
```bash
|
|
8
20
|
npm install @arvo-tools/agentic
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
```
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @arvo-tools/agentic
|
|
24
|
+
```
|
|
25
|
+
```bash
|
|
26
|
+
pnpm install @arvo-tools/agentic
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The package is designed to work seamlessly with TypeScript, providing comprehensive type definitions that enhance development experience and catch potential issues at compile time.
|
|
30
|
+
|
|
31
|
+
## Core Concepts
|
|
32
|
+
|
|
33
|
+
### Agents as Event Handlers
|
|
34
|
+
|
|
35
|
+
Every agent created with `createArvoAgent` is an `ArvoResumable`—a specialized Arvo event handler that coordinates workflows through durable state execution. When an agent receives an event, it reasons about the request using an LLM, executes tools to gather information or perform actions, and emits a completion event with structured results.
|
|
36
|
+
|
|
37
|
+
**Key characteristics:**
|
|
38
|
+
- Accept events conforming to orchestrator contracts
|
|
39
|
+
- Maintain conversation history across multiple reasoning iterations
|
|
40
|
+
- Suspend and resume automatically when coordinating with external services
|
|
41
|
+
- Emit contract-compliant completion events
|
|
42
|
+
- Consume zero resources while waiting for service responses
|
|
43
|
+
|
|
44
|
+
### Tool Modalities
|
|
45
|
+
|
|
46
|
+
Agents coordinate three distinct types of tools, each with different execution characteristics:
|
|
47
|
+
|
|
48
|
+
**Internal Tools** are synchronous JavaScript functions that execute within the agent's process. Use these for fast computations, data transformations, or read-only operations. The agent calls them, awaits the result, and continues reasoning in the same execution cycle.
|
|
49
|
+
|
|
50
|
+
**MCP (Model Context Protocol)** provides standardized access to external systems like filesystems, databases, or APIs.
|
|
51
|
+
|
|
52
|
+
- **Arvo Services** are other Arvo Event Handlers in your system. When the LLM requests a service tool, the agent emits an event, persists its state to memory, and suspends execution. When the service responds, the agent resumes from where it left off and continues reasoning.
|
|
53
|
+
|
|
54
|
+
### Execution Flow
|
|
55
|
+
|
|
56
|
+
The agent follows a ReAct (Reason + Act) pattern:
|
|
57
|
+
|
|
58
|
+
1. **Initialize**: Receive an input event and build the initial context (system prompt and message history)
|
|
59
|
+
2. **Reason**: The LLM analyzes the context and decides what to do next (call tools or generate final output)
|
|
60
|
+
3. **Act**: Execute requested tools—internal/MCP tools run immediately, service tools trigger suspension
|
|
61
|
+
4. **Resume**: When service responses arrive, load persisted state and return to the Reason step
|
|
62
|
+
5. **Complete**: Once the LLM generates final output, validate against the contract schema and emit completion event
|
|
63
|
+
|
|
64
|
+
This cycle repeats until the agent reaches a conclusion or exhausts its tool interaction quota.
|
|
65
|
+
|
|
66
|
+
### Priority-Based Tool Execution
|
|
67
|
+
|
|
68
|
+
When the LLM requests multiple tools simultaneously, Arvo executes only the highest-priority batch and silently drops lower-priority calls. This mechanism helps enforces "priority-first" patterns e.g. authorization tools (priority 100) must execute before sensitive operations (priority 0).
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
tools: {
|
|
72
|
+
normalOperation: createAgentTool({
|
|
73
|
+
name: 'process_data',
|
|
74
|
+
priority: 0, // Default priority
|
|
75
|
+
// ...
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
services: {
|
|
79
|
+
humanApproval: {
|
|
80
|
+
contract: approvalContract.version('1.0.0'),
|
|
81
|
+
priority: 100, // Executes first, blocks others
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Permission Management
|
|
87
|
+
|
|
88
|
+
The permission manager provides deterministic authorization control independent of LLM reasoning. When enabled, tools in the permission policy require explicit approval before execution.
|
|
89
|
+
|
|
90
|
+
**Authorization workflow:**
|
|
91
|
+
1. LLM requests protected tool → Agent execution engine blocks tool execution
|
|
92
|
+
2. Agent emits permission request event to configured domain
|
|
93
|
+
3. External system (human approver, policy engine, IAM) responds with authorization
|
|
94
|
+
4. Agent updates permission database → LLM sees approval in conversation → Retries tool call → Execution proceeds
|
|
95
|
+
|
|
96
|
+
This architecture prevents prompt injection from bypassing security controls—authorization happens outside the LLM's decision-making process.
|
|
97
|
+
|
|
98
|
+
## Quick Start
|
|
99
|
+
|
|
100
|
+
Let's build a simple weather agent that uses an internal tool to check the current time.
|
|
101
|
+
|
|
102
|
+
**Step 1: Define the agent's contract**
|
|
103
|
+
|
|
104
|
+
The contract specifies what events the agent accepts and what it emits upon completion.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { createArvoOrchestratorContract } from 'arvo-core';
|
|
108
|
+
import { AgentDefaults } from '@arvo-tools/agentic'
|
|
109
|
+
import { z } from 'zod';
|
|
110
|
+
|
|
111
|
+
const weatherAgentContract = createArvoOrchestratorContract({
|
|
112
|
+
uri: '#/agents/weather',
|
|
113
|
+
name: 'agent.weather',
|
|
114
|
+
description: 'Provides weather information',
|
|
115
|
+
versions: {
|
|
116
|
+
'1.0.0': {
|
|
117
|
+
init: AgentDefaults.INIT_SCHEMA,
|
|
118
|
+
complete: AgentDefaults.COMPLETE_SCHEMA,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Step 2: Create internal tools**
|
|
125
|
+
|
|
126
|
+
Tools are Typescript functions wrapped with Zod validation and OpenTelemetry instrumentation.
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { createAgentTool } from '@arvo-tools/agentic';
|
|
130
|
+
|
|
131
|
+
const timeChecker = createAgentTool({
|
|
132
|
+
name: 'get_current_time',
|
|
133
|
+
description: 'Returns the current server time in ISO format',
|
|
134
|
+
input: z.object({}).passthrough(),
|
|
135
|
+
output: z.object({ time: z.string() }),
|
|
136
|
+
fn: async () => ({
|
|
137
|
+
time: new Date().toISOString(),
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Step 3: Configure the LLM integration**
|
|
143
|
+
|
|
144
|
+
Choose an LLM provider and configure its parameters.
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { openaiLLMIntegration } from '@arvo-tools/agentic';
|
|
148
|
+
import OpenAI from 'openai';
|
|
149
|
+
import * as dotenv from 'dotenv';
|
|
150
|
+
dotenv.config()
|
|
151
|
+
|
|
152
|
+
const llm = openaiLLMIntegration(
|
|
153
|
+
new OpenAI({ apiKey: process.env.OPENAI_API_KEY }),
|
|
154
|
+
{
|
|
155
|
+
invocationParam: {
|
|
156
|
+
model: 'gpt-4o',
|
|
157
|
+
temperature: 0.7,
|
|
158
|
+
max_completion_tokens: 2048,
|
|
159
|
+
},
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Step 4: Create the agent**
|
|
165
|
+
|
|
166
|
+
Combine the contract, tools, and LLM into an agent handler.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { createArvoAgent, AgentDefaults } from '@arvo-tools/agentic';
|
|
170
|
+
import { SimpleMachineMemory, EventHandlerFactory, type IMachineMemory } from 'arvo-event-handler';
|
|
171
|
+
|
|
172
|
+
export const weatherAgent: EventHandlerFactory<{
|
|
173
|
+
memory: IMachineMemory<Record<string, unknown>>;
|
|
174
|
+
}> = ({ memory }) =>
|
|
175
|
+
createArvoAgent({
|
|
176
|
+
contracts: {
|
|
177
|
+
self: weatherAgentContract,
|
|
178
|
+
services: {}, // Does not coordinate with other Arvo event driven services =
|
|
179
|
+
},
|
|
180
|
+
tools: {
|
|
181
|
+
timeChecker,
|
|
182
|
+
},
|
|
183
|
+
llm,
|
|
184
|
+
memory,
|
|
185
|
+
handler: {
|
|
186
|
+
'1.0.0': {
|
|
187
|
+
context: AgentDefaults.CONTEXT_BUILDER(({ tools }) =>
|
|
188
|
+
`You are a weather assistant. When discussing forecasts,
|
|
189
|
+
use ${tools.tools.timeChecker.name} to reference the current time.`
|
|
190
|
+
),
|
|
191
|
+
output: AgentDefaults.OUTPUT_BUILDER,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Step 5: Execute the agent**
|
|
198
|
+
|
|
199
|
+
Even though Arvo is an event-driven toolkit, you actually don't required event-driven setup or infrastructure for executing Arvo Agents (and the Arvo Event Handlers).
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { createArvoEventFactory } from 'arvo-core';
|
|
12
203
|
|
|
13
|
-
|
|
204
|
+
const memory = new SimpleMachineMemory();
|
|
205
|
+
const agent = weatherAgent({ memory });
|
|
14
206
|
|
|
15
|
-
|
|
16
|
-
|
|
207
|
+
const inputEvent = createArvoEventFactory(weatherAgentContract.version('1.0.0')).accepts({
|
|
208
|
+
source: 'weather.service',
|
|
209
|
+
data: {
|
|
210
|
+
message: 'What time is it?',
|
|
211
|
+
// This is a default Arvo field injected automatically for advanced operations
|
|
212
|
+
parentSubject$$: null,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
17
215
|
|
|
18
|
-
|
|
19
|
-
|
|
216
|
+
const result = await agent.execute(inputEvent, { inheritFrom: 'EVENT' });
|
|
217
|
+
console.log(result.events[0].data.response);
|
|
218
|
+
// Output: "The current time is 2025-01-15T10:30:00.000Z"
|
|
219
|
+
```
|
|
20
220
|
|
|
21
|
-
|
|
221
|
+
# Advanced Examples
|
|
22
222
|
|
|
23
|
-
|
|
223
|
+
... coming soon
|