@elizaos/cli 1.3.0 → 1.3.2
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 +1 -1
- package/dist/{chunk-2CUIHNPL.js → chunk-5GUS4CFO.js} +7 -2
- package/dist/{chunk-2ALAPQLV.js → chunk-E6XYTE3A.js} +296 -311
- package/dist/chunk-GXWWPFBO.js +39 -0
- package/dist/{chunk-I77ZRNYO.js → chunk-T2QDIXGU.js} +2 -2
- package/dist/commands/agent/actions/index.d.ts +5 -0
- package/dist/commands/agent/actions/index.js +2 -2
- package/dist/commands/agent/index.d.ts +2 -2
- package/dist/commands/agent/index.js +2 -2
- package/dist/commands/create/actions/index.js +3 -3
- package/dist/commands/create/index.js +4 -4
- package/dist/commands/shared/index.d.ts +11 -28
- package/dist/commands/shared/index.js +7 -3
- package/dist/index.js +541 -450
- package/dist/{registry-N626N4VG.js → registry-433S5F3Y.js} +2 -2
- package/dist/templates/plugin-quick-starter/.gitignore +66 -0
- package/dist/templates/plugin-quick-starter/.npmignore +5 -0
- package/dist/templates/plugin-quick-starter/package.json +11 -3
- package/dist/templates/plugin-quick-starter/src/__tests__/plugin.test.ts +499 -146
- package/dist/templates/plugin-quick-starter/src/__tests__/test-utils.ts +316 -115
- package/dist/templates/plugin-quick-starter/src/plugin.ts +7 -13
- package/dist/templates/plugin-starter/.gitignore +66 -0
- package/dist/templates/plugin-starter/.npmignore +5 -0
- package/dist/templates/plugin-starter/README.md +1 -1
- package/dist/templates/plugin-starter/package.json +11 -3
- package/dist/templates/plugin-starter/src/__tests__/integration.test.ts +13 -13
- package/dist/templates/plugin-starter/src/__tests__/plugin.test.ts +556 -129
- package/dist/templates/plugin-starter/src/__tests__/test-utils.ts +347 -115
- package/dist/templates/plugin-starter/src/plugin.ts +18 -22
- package/dist/templates/project-starter/.gitignore +57 -0
- package/dist/templates/project-starter/.npmignore +11 -0
- package/dist/templates/project-starter/README.md +1 -1
- package/dist/templates/project-starter/package.json +4 -4
- package/dist/templates/project-starter/src/__tests__/env.test.ts +3 -1
- package/dist/templates/project-starter/src/__tests__/file-structure.test.ts +3 -2
- package/dist/templates/project-starter/src/__tests__/integration.test.ts +1 -1
- package/dist/templates/project-starter/tsup.config.ts +2 -1
- package/dist/templates/project-tee-starter/.dockerignore +64 -14
- package/dist/templates/project-tee-starter/.gitignore +57 -0
- package/dist/templates/project-tee-starter/.npmignore +6 -0
- package/dist/templates/project-tee-starter/Dockerfile +9 -5
- package/dist/templates/project-tee-starter/GUIDE.md +103 -42
- package/dist/templates/project-tee-starter/README.md +39 -19
- package/dist/templates/project-tee-starter/__tests__/build-order.test.ts +62 -0
- package/dist/templates/project-tee-starter/__tests__/character.test.ts +19 -17
- package/dist/templates/project-tee-starter/__tests__/config.test.ts +10 -3
- package/dist/templates/project-tee-starter/__tests__/env.test.ts +2 -1
- package/dist/templates/project-tee-starter/__tests__/file-structure.test.ts +14 -3
- package/dist/templates/project-tee-starter/__tests__/frontend.test.ts +459 -0
- package/dist/templates/project-tee-starter/__tests__/plugin.test.ts +4 -2
- package/dist/templates/project-tee-starter/__tests__/routes.test.ts +15 -6
- package/dist/templates/project-tee-starter/__tests__/tee-validation.test.ts +295 -0
- package/dist/templates/project-tee-starter/__tests__/vite-config-utils.ts +39 -0
- package/dist/templates/project-tee-starter/docker-compose.yaml +5 -2
- package/dist/templates/{plugin-starter/dist → project-tee-starter}/index.html +3 -3
- package/dist/templates/project-tee-starter/package.json +34 -14
- package/dist/templates/project-tee-starter/postcss.config.js +3 -0
- package/dist/templates/project-tee-starter/scripts/install-test-deps.js +52 -0
- package/dist/templates/project-tee-starter/scripts/test-all.sh +82 -0
- package/dist/templates/project-tee-starter/src/frontend/index.css +106 -0
- package/dist/templates/project-tee-starter/src/frontend/index.html +20 -0
- package/dist/templates/project-tee-starter/src/frontend/index.tsx +370 -0
- package/dist/templates/project-tee-starter/src/frontend/panels.tsx +17 -0
- package/dist/templates/project-tee-starter/src/frontend/utils.ts +6 -0
- package/dist/templates/project-tee-starter/src/index.ts +6 -6
- package/dist/templates/project-tee-starter/src/plugin.ts +209 -59
- package/dist/templates/project-tee-starter/tailwind.config.js +62 -0
- package/dist/templates/project-tee-starter/tsconfig.build.json +2 -2
- package/dist/templates/project-tee-starter/tsconfig.json +8 -5
- package/dist/templates/project-tee-starter/tsup.config.ts +3 -2
- package/dist/templates/project-tee-starter/vite.config.ts +39 -0
- package/dist/url-utils-CKc_Ebt_.d.ts +35 -0
- package/dist/{utils-H66532NB.js → utils-DBLSDYBF.js} +2 -2
- package/package.json +12 -7
- package/templates/plugin-quick-starter/.gitignore +66 -0
- package/templates/plugin-quick-starter/.npmignore +5 -0
- package/templates/plugin-quick-starter/package.json +11 -3
- package/templates/plugin-quick-starter/src/__tests__/plugin.test.ts +499 -146
- package/templates/plugin-quick-starter/src/__tests__/test-utils.ts +316 -115
- package/templates/plugin-quick-starter/src/plugin.ts +7 -13
- package/templates/plugin-starter/.gitignore +66 -0
- package/templates/plugin-starter/.npmignore +5 -0
- package/templates/plugin-starter/README.md +1 -1
- package/templates/plugin-starter/package.json +11 -3
- package/templates/plugin-starter/src/__tests__/integration.test.ts +13 -13
- package/templates/plugin-starter/src/__tests__/plugin.test.ts +556 -129
- package/templates/plugin-starter/src/__tests__/test-utils.ts +347 -115
- package/templates/plugin-starter/src/plugin.ts +18 -22
- package/templates/project-starter/.gitignore +57 -0
- package/templates/project-starter/.npmignore +11 -0
- package/templates/project-starter/README.md +1 -1
- package/templates/project-starter/package.json +4 -4
- package/templates/project-starter/src/__tests__/env.test.ts +3 -1
- package/templates/project-starter/src/__tests__/file-structure.test.ts +3 -2
- package/templates/project-starter/src/__tests__/integration.test.ts +1 -1
- package/templates/project-starter/tsup.config.ts +2 -1
- package/templates/project-tee-starter/.dockerignore +64 -14
- package/templates/project-tee-starter/.gitignore +57 -0
- package/templates/project-tee-starter/.npmignore +6 -0
- package/templates/project-tee-starter/Dockerfile +9 -5
- package/templates/project-tee-starter/GUIDE.md +103 -42
- package/templates/project-tee-starter/README.md +39 -19
- package/templates/project-tee-starter/__tests__/build-order.test.ts +62 -0
- package/templates/project-tee-starter/__tests__/character.test.ts +19 -17
- package/templates/project-tee-starter/__tests__/config.test.ts +10 -3
- package/templates/project-tee-starter/__tests__/env.test.ts +2 -1
- package/templates/project-tee-starter/__tests__/file-structure.test.ts +14 -3
- package/templates/project-tee-starter/__tests__/frontend.test.ts +459 -0
- package/templates/project-tee-starter/__tests__/plugin.test.ts +4 -2
- package/templates/project-tee-starter/__tests__/routes.test.ts +15 -6
- package/templates/project-tee-starter/__tests__/tee-validation.test.ts +295 -0
- package/templates/project-tee-starter/__tests__/vite-config-utils.ts +39 -0
- package/templates/project-tee-starter/docker-compose.yaml +5 -2
- package/templates/{plugin-starter/dist → project-tee-starter}/index.html +3 -3
- package/templates/project-tee-starter/package.json +34 -14
- package/templates/project-tee-starter/postcss.config.js +3 -0
- package/templates/project-tee-starter/scripts/install-test-deps.js +52 -0
- package/templates/project-tee-starter/scripts/test-all.sh +82 -0
- package/templates/project-tee-starter/src/frontend/index.css +106 -0
- package/templates/project-tee-starter/src/frontend/index.html +20 -0
- package/templates/project-tee-starter/src/frontend/index.tsx +370 -0
- package/templates/project-tee-starter/src/frontend/panels.tsx +17 -0
- package/templates/project-tee-starter/src/frontend/utils.ts +6 -0
- package/templates/project-tee-starter/src/index.ts +6 -6
- package/templates/project-tee-starter/src/plugin.ts +209 -59
- package/templates/project-tee-starter/tailwind.config.js +62 -0
- package/templates/project-tee-starter/tsconfig.build.json +2 -2
- package/templates/project-tee-starter/tsconfig.json +8 -5
- package/templates/project-tee-starter/tsup.config.ts +3 -2
- package/templates/project-tee-starter/vite.config.ts +39 -0
- package/dist/chunk-4O6EZU37.js +0 -14
- package/dist/migration-guides/advanced-migration-guide.md +0 -459
- package/dist/migration-guides/completion-requirements.md +0 -379
- package/dist/migration-guides/integrated-migration-loop.md +0 -392
- package/dist/migration-guides/migration-guide.md +0 -712
- package/dist/migration-guides/prompt-and-generation-guide.md +0 -702
- package/dist/migration-guides/state-and-providers-guide.md +0 -544
- package/dist/migration-guides/testing-guide.md +0 -1021
- package/dist/templates/plugin-starter/dist/assets/index-CgkejLs_.css +0 -1
- package/dist/templates/plugin-starter/dist/assets/index-D1cHX53P.js +0 -49
- package/dist/templates/plugin-starter/dist/index.js +0 -387
- package/dist/templates/plugin-starter/dist/index.js.map +0 -1
- package/templates/plugin-starter/dist/.vite/manifest.json +0 -11
- package/templates/plugin-starter/dist/assets/index-CgkejLs_.css +0 -1
- package/templates/plugin-starter/dist/assets/index-D1cHX53P.js +0 -49
- package/templates/plugin-starter/dist/index.d.ts +0 -14
- package/templates/plugin-starter/dist/index.js +0 -387
- package/templates/plugin-starter/dist/index.js.map +0 -1
|
@@ -1,544 +0,0 @@
|
|
|
1
|
-
# ElizaOS State Management & Providers Guide - v1.x
|
|
2
|
-
|
|
3
|
-
> **Important**: This guide provides comprehensive documentation for the `composeState` method and Providers in v1.x, including comparisons with v0.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [State Management with composeState](#state-management-with-composestate)
|
|
8
|
-
- [Basic Usage](#basic-usage)
|
|
9
|
-
- [State Filtering](#state-filtering)
|
|
10
|
-
- [Available State Keys](#available-state-keys)
|
|
11
|
-
- [Performance Optimization](#performance-optimization)
|
|
12
|
-
- [Providers in v1](#providers-in-v1)
|
|
13
|
-
- [Provider Interface](#provider-interface)
|
|
14
|
-
- [Creating Providers](#creating-providers)
|
|
15
|
-
- [Provider Options](#provider-options)
|
|
16
|
-
- [Provider Best Practices](#provider-best-practices)
|
|
17
|
-
- [v0 vs v1 Comparison](#v0-vs-v1-comparison)
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## State Management with composeState
|
|
22
|
-
|
|
23
|
-
The `composeState` method is the central mechanism for building the context state that powers agent responses. In v1, it has been enhanced with powerful filtering capabilities.
|
|
24
|
-
|
|
25
|
-
### Basic Usage
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
// v1: Basic state composition
|
|
29
|
-
const state = await runtime.composeState(message);
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
This creates a complete state object containing all available context:
|
|
33
|
-
|
|
34
|
-
- Agent information (bio, lore, personality)
|
|
35
|
-
- Conversation history
|
|
36
|
-
- Room and participant details
|
|
37
|
-
- Available actions and evaluators
|
|
38
|
-
- Knowledge and RAG data
|
|
39
|
-
- Provider-generated context
|
|
40
|
-
|
|
41
|
-
### State Filtering
|
|
42
|
-
|
|
43
|
-
The v1 `composeState` method introduces filtering capabilities for performance optimization:
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
// v1: Signature
|
|
47
|
-
composeState(
|
|
48
|
-
message: Memory,
|
|
49
|
-
includeList?: string[], // Keys to include
|
|
50
|
-
onlyInclude?: boolean, // If true, ONLY include listed keys
|
|
51
|
-
skipCache?: boolean // Skip caching mechanism
|
|
52
|
-
): Promise<State>
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
#### Filtering Examples
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
// Include only specific state keys
|
|
59
|
-
const minimalState = await runtime.composeState(
|
|
60
|
-
message,
|
|
61
|
-
['agentName', 'bio', 'recentMessages'],
|
|
62
|
-
true // onlyInclude = true
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
// Update only specific parts of existing state
|
|
66
|
-
const updatedState = await runtime.composeState(
|
|
67
|
-
message,
|
|
68
|
-
['RECENT_MESSAGES', 'GOALS'] // Update only these
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
// Skip cache for fresh data
|
|
72
|
-
const freshState = await runtime.composeState(
|
|
73
|
-
message,
|
|
74
|
-
undefined,
|
|
75
|
-
false,
|
|
76
|
-
true // skipCache = true
|
|
77
|
-
);
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Available State Keys
|
|
81
|
-
|
|
82
|
-
Here are the primary state keys you can filter:
|
|
83
|
-
|
|
84
|
-
#### Core Agent Information
|
|
85
|
-
|
|
86
|
-
- `agentId` - Agent's UUID
|
|
87
|
-
- `agentName` - Agent's display name
|
|
88
|
-
- `bio` - Agent biography (string or selected from array)
|
|
89
|
-
- `lore` - Random selection of lore bits
|
|
90
|
-
- `adjective` - Random adjective from character
|
|
91
|
-
- `topic` / `topics` - Agent's interests
|
|
92
|
-
|
|
93
|
-
#### Conversation Context
|
|
94
|
-
|
|
95
|
-
- `recentMessages` - Formatted recent messages
|
|
96
|
-
- `recentMessagesData` - Raw message Memory objects
|
|
97
|
-
- `recentPosts` - Formatted posts in thread
|
|
98
|
-
- `attachments` - Formatted attachment information
|
|
99
|
-
|
|
100
|
-
#### Interaction History
|
|
101
|
-
|
|
102
|
-
- `recentMessageInteractions` - Past interactions as messages
|
|
103
|
-
- `recentPostInteractions` - Past interactions as posts
|
|
104
|
-
- `recentInteractionsData` - Raw interaction Memory[]
|
|
105
|
-
|
|
106
|
-
#### Character Examples
|
|
107
|
-
|
|
108
|
-
- `characterPostExamples` - Example posts from character
|
|
109
|
-
- `characterMessageExamples` - Example conversations
|
|
110
|
-
|
|
111
|
-
#### Directions & Style
|
|
112
|
-
|
|
113
|
-
- `messageDirections` - Message style guidelines
|
|
114
|
-
- `postDirections` - Post style guidelines
|
|
115
|
-
|
|
116
|
-
#### Room & Participants
|
|
117
|
-
|
|
118
|
-
- `roomId` - Current room UUID
|
|
119
|
-
- `actors` - Formatted actor information
|
|
120
|
-
- `actorsData` - Raw Actor[] array
|
|
121
|
-
- `senderName` - Name of message sender
|
|
122
|
-
|
|
123
|
-
#### Goals & Actions
|
|
124
|
-
|
|
125
|
-
- `goals` - Formatted goals string
|
|
126
|
-
- `goalsData` - Raw Goal[] array
|
|
127
|
-
- `actionNames` - Available action names
|
|
128
|
-
- `actions` - Formatted action descriptions
|
|
129
|
-
- `actionExamples` - Action usage examples
|
|
130
|
-
|
|
131
|
-
#### Evaluators
|
|
132
|
-
|
|
133
|
-
- `evaluators` - Formatted evaluator information
|
|
134
|
-
- `evaluatorNames` - List of evaluator names
|
|
135
|
-
- `evaluatorExamples` - Evaluator examples
|
|
136
|
-
- `evaluatorsData` - Raw Evaluator[] array
|
|
137
|
-
|
|
138
|
-
#### Knowledge
|
|
139
|
-
|
|
140
|
-
- `knowledge` - Formatted knowledge text
|
|
141
|
-
- `knowledgeData` - Knowledge items
|
|
142
|
-
- `ragKnowledgeData` - RAG knowledge items
|
|
143
|
-
|
|
144
|
-
#### Providers
|
|
145
|
-
|
|
146
|
-
- `providers` - Additional context from providers
|
|
147
|
-
|
|
148
|
-
### Performance Optimization
|
|
149
|
-
|
|
150
|
-
Use filtering to optimize performance by only computing needed state:
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
// Minimal state for simple responses
|
|
154
|
-
const quickResponse = await runtime.composeState(
|
|
155
|
-
message,
|
|
156
|
-
['agentName', 'bio', 'recentMessages', 'messageDirections'],
|
|
157
|
-
true
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
// Full state for complex decision-making
|
|
161
|
-
const fullState = await runtime.composeState(message);
|
|
162
|
-
|
|
163
|
-
// Update pattern for ongoing conversations
|
|
164
|
-
let state = await runtime.composeState(message);
|
|
165
|
-
// ... later in conversation ...
|
|
166
|
-
state = await runtime.composeState(newMessage, ['RECENT_MESSAGES', 'GOALS', 'attachments']);
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## Providers in v1
|
|
172
|
-
|
|
173
|
-
Providers supply dynamic contextual information to the agent, acting as the agent's "senses" for perceiving external data.
|
|
174
|
-
|
|
175
|
-
### Provider Interface
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
interface Provider {
|
|
179
|
-
// REQUIRED: Unique identifier
|
|
180
|
-
name: string;
|
|
181
|
-
|
|
182
|
-
// Optional metadata
|
|
183
|
-
description?: string;
|
|
184
|
-
dynamic?: boolean;
|
|
185
|
-
position?: number;
|
|
186
|
-
private?: boolean;
|
|
187
|
-
|
|
188
|
-
// The data retrieval method
|
|
189
|
-
get: (runtime: IAgentRuntime, message: Memory, state: State) => Promise<ProviderResult>;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
interface ProviderResult {
|
|
193
|
-
values?: {
|
|
194
|
-
[key: string]: any;
|
|
195
|
-
};
|
|
196
|
-
data?: {
|
|
197
|
-
[key: string]: any;
|
|
198
|
-
};
|
|
199
|
-
text?: string;
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Creating Providers
|
|
204
|
-
|
|
205
|
-
#### Simple Text Provider
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
const weatherProvider: Provider = {
|
|
209
|
-
name: 'weatherProvider',
|
|
210
|
-
description: 'Provides current weather information',
|
|
211
|
-
dynamic: true,
|
|
212
|
-
|
|
213
|
-
get: async (runtime, message, state) => {
|
|
214
|
-
const weather = await fetchWeatherData();
|
|
215
|
-
|
|
216
|
-
return {
|
|
217
|
-
text: `Current weather: ${weather.temp}°F, ${weather.condition}`,
|
|
218
|
-
values: {
|
|
219
|
-
temperature: weather.temp,
|
|
220
|
-
condition: weather.condition,
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
#### Complex Data Provider
|
|
228
|
-
|
|
229
|
-
```typescript
|
|
230
|
-
const marketDataProvider: Provider = {
|
|
231
|
-
name: 'marketDataProvider',
|
|
232
|
-
description: 'Provides real-time market data',
|
|
233
|
-
dynamic: true,
|
|
234
|
-
position: 10, // Higher priority
|
|
235
|
-
|
|
236
|
-
get: async (runtime, message, state) => {
|
|
237
|
-
const symbols = extractSymbolsFromMessage(message.content.text);
|
|
238
|
-
const marketData = await fetchMarketData(symbols);
|
|
239
|
-
|
|
240
|
-
const summary = formatMarketSummary(marketData);
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
text: summary,
|
|
244
|
-
data: marketData,
|
|
245
|
-
values: {
|
|
246
|
-
mentionedSymbols: symbols,
|
|
247
|
-
marketStatus: marketData.status,
|
|
248
|
-
},
|
|
249
|
-
};
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
#### Conditional Provider
|
|
255
|
-
|
|
256
|
-
```typescript
|
|
257
|
-
const contextualProvider: Provider = {
|
|
258
|
-
name: 'contextualProvider',
|
|
259
|
-
description: 'Provides context based on conversation',
|
|
260
|
-
|
|
261
|
-
get: async (runtime, message, state) => {
|
|
262
|
-
// Access state to make decisions
|
|
263
|
-
const topic = state.topic;
|
|
264
|
-
const recentTopics = analyzeRecentTopics(state.recentMessagesData);
|
|
265
|
-
|
|
266
|
-
if (!topic || !recentTopics.includes(topic)) {
|
|
267
|
-
return { text: '' }; // No additional context needed
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const relevantInfo = await fetchTopicInfo(topic);
|
|
271
|
-
|
|
272
|
-
return {
|
|
273
|
-
text: `Relevant ${topic} information: ${relevantInfo}`,
|
|
274
|
-
data: { topic, info: relevantInfo },
|
|
275
|
-
};
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
### Provider Options
|
|
281
|
-
|
|
282
|
-
#### `dynamic` Property
|
|
283
|
-
|
|
284
|
-
Set to `true` for providers that return different data based on context:
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
const timeProvider: Provider = {
|
|
288
|
-
name: 'timeProvider',
|
|
289
|
-
dynamic: true, // Time always changes
|
|
290
|
-
get: async () => ({
|
|
291
|
-
text: `Current time: ${new Date().toLocaleString()}`,
|
|
292
|
-
values: { timestamp: Date.now() },
|
|
293
|
-
}),
|
|
294
|
-
};
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
#### `position` Property
|
|
298
|
-
|
|
299
|
-
Controls provider priority (higher = higher priority):
|
|
300
|
-
|
|
301
|
-
```typescript
|
|
302
|
-
const criticalProvider: Provider = {
|
|
303
|
-
name: 'criticalProvider',
|
|
304
|
-
position: 100, // Will be processed before lower position providers
|
|
305
|
-
get: async () => ({ text: 'Critical information...' }),
|
|
306
|
-
};
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
#### `private` Property
|
|
310
|
-
|
|
311
|
-
Hide from public provider lists:
|
|
312
|
-
|
|
313
|
-
```typescript
|
|
314
|
-
const internalProvider: Provider = {
|
|
315
|
-
name: 'internalProvider',
|
|
316
|
-
private: true, // Won't appear in provider lists
|
|
317
|
-
get: async () => ({ text: 'Internal data...' }),
|
|
318
|
-
};
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
### Provider Best Practices
|
|
322
|
-
|
|
323
|
-
1. **Always Return ProviderResult**
|
|
324
|
-
|
|
325
|
-
```typescript
|
|
326
|
-
// ❌ Bad - returning raw value
|
|
327
|
-
get: async () => 'Some text';
|
|
328
|
-
|
|
329
|
-
// ✅ Good - returning ProviderResult
|
|
330
|
-
get: async () => ({ text: 'Some text' });
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
2. **Use Appropriate Return Fields**
|
|
334
|
-
|
|
335
|
-
```typescript
|
|
336
|
-
return {
|
|
337
|
-
// Human-readable summary
|
|
338
|
-
text: 'Market is up 2.5% today',
|
|
339
|
-
|
|
340
|
-
// Simple key-value pairs for templates
|
|
341
|
-
values: {
|
|
342
|
-
marketChange: 2.5,
|
|
343
|
-
marketStatus: 'bullish'
|
|
344
|
-
},
|
|
345
|
-
|
|
346
|
-
// Complex nested data for processing
|
|
347
|
-
data: {
|
|
348
|
-
stocks: [...],
|
|
349
|
-
analysis: {...}
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
3. **Handle Errors Gracefully**
|
|
355
|
-
|
|
356
|
-
```typescript
|
|
357
|
-
get: async (runtime, message, state) => {
|
|
358
|
-
try {
|
|
359
|
-
const data = await fetchExternalData();
|
|
360
|
-
return { text: formatData(data), data };
|
|
361
|
-
} catch (error) {
|
|
362
|
-
elizaLogger.error('Provider error:', error);
|
|
363
|
-
return {
|
|
364
|
-
text: 'Unable to fetch data at this time',
|
|
365
|
-
values: { error: true },
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
4. **Optimize Performance**
|
|
372
|
-
|
|
373
|
-
```typescript
|
|
374
|
-
const cachedProvider: Provider = {
|
|
375
|
-
name: 'cachedProvider',
|
|
376
|
-
dynamic: false, // Indicates static data
|
|
377
|
-
|
|
378
|
-
get: async (runtime) => {
|
|
379
|
-
// Check cache first
|
|
380
|
-
const cached = await runtime.getSetting('providerCache');
|
|
381
|
-
if (cached && !isExpired(cached)) {
|
|
382
|
-
return { data: cached.data };
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Fetch fresh data
|
|
386
|
-
const fresh = await fetchData();
|
|
387
|
-
await runtime.setSetting('providerCache', {
|
|
388
|
-
data: fresh,
|
|
389
|
-
timestamp: Date.now(),
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
return { data: fresh };
|
|
393
|
-
},
|
|
394
|
-
};
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
---
|
|
398
|
-
|
|
399
|
-
## v0 vs v1 Comparison
|
|
400
|
-
|
|
401
|
-
### composeState Changes
|
|
402
|
-
|
|
403
|
-
#### Method Signature
|
|
404
|
-
|
|
405
|
-
```typescript
|
|
406
|
-
// v0: Simple with additional keys
|
|
407
|
-
composeState(
|
|
408
|
-
message: Memory,
|
|
409
|
-
additionalKeys?: { [key: string]: unknown }
|
|
410
|
-
): Promise<State>
|
|
411
|
-
|
|
412
|
-
// v1: Advanced with filtering
|
|
413
|
-
composeState(
|
|
414
|
-
message: Memory,
|
|
415
|
-
includeList?: string[],
|
|
416
|
-
onlyInclude?: boolean,
|
|
417
|
-
skipCache?: boolean
|
|
418
|
-
): Promise<State>
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
#### Key Differences:
|
|
422
|
-
|
|
423
|
-
1. **Filtering**: v1 allows selective state composition
|
|
424
|
-
2. **Performance**: Can request only needed state keys
|
|
425
|
-
3. **Caching**: Explicit cache control with `skipCache`
|
|
426
|
-
4. **Update Pattern**: Use same method for updates with specific keys
|
|
427
|
-
|
|
428
|
-
#### Migration Example:
|
|
429
|
-
|
|
430
|
-
```typescript
|
|
431
|
-
// v0: Update pattern
|
|
432
|
-
state = await runtime.updateRecentMessageState(state);
|
|
433
|
-
|
|
434
|
-
// v1: Update pattern
|
|
435
|
-
state = await runtime.composeState(message, ['RECENT_MESSAGES']);
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
### Provider Changes
|
|
439
|
-
|
|
440
|
-
#### Interface Changes
|
|
441
|
-
|
|
442
|
-
```typescript
|
|
443
|
-
// v0: Minimal interface
|
|
444
|
-
interface Provider {
|
|
445
|
-
get: (runtime, message, state?) => Promise<any>;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// v1: Rich interface
|
|
449
|
-
interface Provider {
|
|
450
|
-
name: string; // REQUIRED
|
|
451
|
-
description?: string;
|
|
452
|
-
dynamic?: boolean;
|
|
453
|
-
position?: number;
|
|
454
|
-
private?: boolean;
|
|
455
|
-
get: (runtime, message, state) => Promise<ProviderResult>;
|
|
456
|
-
}
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
#### Return Type Changes
|
|
460
|
-
|
|
461
|
-
```typescript
|
|
462
|
-
// v0: Return anything
|
|
463
|
-
return 'Some text';
|
|
464
|
-
return { data: 'value' };
|
|
465
|
-
|
|
466
|
-
// v1: Return ProviderResult
|
|
467
|
-
return {
|
|
468
|
-
text: 'Human readable',
|
|
469
|
-
values: { key: 'value' },
|
|
470
|
-
data: { complex: 'object' },
|
|
471
|
-
};
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
#### Key Differences:
|
|
475
|
-
|
|
476
|
-
1. **Required Name**: Every provider must have unique `name`
|
|
477
|
-
2. **Structured Returns**: Must return `ProviderResult` object
|
|
478
|
-
3. **Rich Metadata**: Can specify behavior with options
|
|
479
|
-
4. **State Parameter**: No longer optional in `get` method
|
|
480
|
-
5. **Better Organization**: Clear separation of text, values, and data
|
|
481
|
-
|
|
482
|
-
### Migration Checklist
|
|
483
|
-
|
|
484
|
-
- [ ] Add `name` property to all providers
|
|
485
|
-
- [ ] Update return statements to use `ProviderResult` format
|
|
486
|
-
- [ ] Remove optional `?` from state parameter in get method
|
|
487
|
-
- [ ] Consider adding `description` for documentation
|
|
488
|
-
- [ ] Use `dynamic: true` for context-dependent providers
|
|
489
|
-
- [ ] Replace `updateRecentMessageState` with filtered `composeState`
|
|
490
|
-
- [ ] Optimize performance by filtering state keys
|
|
491
|
-
- [ ] Add error handling with graceful fallbacks
|
|
492
|
-
- [ ] Consider caching strategies for expensive operations
|
|
493
|
-
|
|
494
|
-
---
|
|
495
|
-
|
|
496
|
-
## Examples & Patterns
|
|
497
|
-
|
|
498
|
-
### State Filtering Pattern
|
|
499
|
-
|
|
500
|
-
```typescript
|
|
501
|
-
// Initial load - get essential state
|
|
502
|
-
const initialState = await runtime.composeState(
|
|
503
|
-
message,
|
|
504
|
-
['agentName', 'bio', 'recentMessages', 'actions', 'providers'],
|
|
505
|
-
true
|
|
506
|
-
);
|
|
507
|
-
|
|
508
|
-
// Process message...
|
|
509
|
-
|
|
510
|
-
// Update only what changed
|
|
511
|
-
const updatedState = await runtime.composeState(message, [
|
|
512
|
-
'RECENT_MESSAGES',
|
|
513
|
-
'goals',
|
|
514
|
-
'attachments',
|
|
515
|
-
]);
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
### Provider Chain Pattern
|
|
519
|
-
|
|
520
|
-
```typescript
|
|
521
|
-
const providers = [
|
|
522
|
-
weatherProvider, // position: 10
|
|
523
|
-
newsProvider, // position: 5
|
|
524
|
-
marketProvider, // position: 15
|
|
525
|
-
fallbackProvider, // position: 1
|
|
526
|
-
];
|
|
527
|
-
|
|
528
|
-
// Will be processed in order: market, weather, news, fallback
|
|
529
|
-
runtime.providers = providers.sort((a, b) => (b.position || 0) - (a.position || 0));
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
### Conditional State Building
|
|
533
|
-
|
|
534
|
-
```typescript
|
|
535
|
-
const buildState = async (message: Memory, isDetailedResponse: boolean) => {
|
|
536
|
-
const baseKeys = ['agentName', 'bio', 'recentMessages'];
|
|
537
|
-
|
|
538
|
-
const keys = isDetailedResponse
|
|
539
|
-
? [...baseKeys, 'lore', 'topics', 'characterMessageExamples', 'knowledge']
|
|
540
|
-
: baseKeys;
|
|
541
|
-
|
|
542
|
-
return runtime.composeState(message, keys, true);
|
|
543
|
-
};
|
|
544
|
-
```
|