@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.
Files changed (148) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunk-2CUIHNPL.js → chunk-5GUS4CFO.js} +7 -2
  3. package/dist/{chunk-2ALAPQLV.js → chunk-E6XYTE3A.js} +296 -311
  4. package/dist/chunk-GXWWPFBO.js +39 -0
  5. package/dist/{chunk-I77ZRNYO.js → chunk-T2QDIXGU.js} +2 -2
  6. package/dist/commands/agent/actions/index.d.ts +5 -0
  7. package/dist/commands/agent/actions/index.js +2 -2
  8. package/dist/commands/agent/index.d.ts +2 -2
  9. package/dist/commands/agent/index.js +2 -2
  10. package/dist/commands/create/actions/index.js +3 -3
  11. package/dist/commands/create/index.js +4 -4
  12. package/dist/commands/shared/index.d.ts +11 -28
  13. package/dist/commands/shared/index.js +7 -3
  14. package/dist/index.js +541 -450
  15. package/dist/{registry-N626N4VG.js → registry-433S5F3Y.js} +2 -2
  16. package/dist/templates/plugin-quick-starter/.gitignore +66 -0
  17. package/dist/templates/plugin-quick-starter/.npmignore +5 -0
  18. package/dist/templates/plugin-quick-starter/package.json +11 -3
  19. package/dist/templates/plugin-quick-starter/src/__tests__/plugin.test.ts +499 -146
  20. package/dist/templates/plugin-quick-starter/src/__tests__/test-utils.ts +316 -115
  21. package/dist/templates/plugin-quick-starter/src/plugin.ts +7 -13
  22. package/dist/templates/plugin-starter/.gitignore +66 -0
  23. package/dist/templates/plugin-starter/.npmignore +5 -0
  24. package/dist/templates/plugin-starter/README.md +1 -1
  25. package/dist/templates/plugin-starter/package.json +11 -3
  26. package/dist/templates/plugin-starter/src/__tests__/integration.test.ts +13 -13
  27. package/dist/templates/plugin-starter/src/__tests__/plugin.test.ts +556 -129
  28. package/dist/templates/plugin-starter/src/__tests__/test-utils.ts +347 -115
  29. package/dist/templates/plugin-starter/src/plugin.ts +18 -22
  30. package/dist/templates/project-starter/.gitignore +57 -0
  31. package/dist/templates/project-starter/.npmignore +11 -0
  32. package/dist/templates/project-starter/README.md +1 -1
  33. package/dist/templates/project-starter/package.json +4 -4
  34. package/dist/templates/project-starter/src/__tests__/env.test.ts +3 -1
  35. package/dist/templates/project-starter/src/__tests__/file-structure.test.ts +3 -2
  36. package/dist/templates/project-starter/src/__tests__/integration.test.ts +1 -1
  37. package/dist/templates/project-starter/tsup.config.ts +2 -1
  38. package/dist/templates/project-tee-starter/.dockerignore +64 -14
  39. package/dist/templates/project-tee-starter/.gitignore +57 -0
  40. package/dist/templates/project-tee-starter/.npmignore +6 -0
  41. package/dist/templates/project-tee-starter/Dockerfile +9 -5
  42. package/dist/templates/project-tee-starter/GUIDE.md +103 -42
  43. package/dist/templates/project-tee-starter/README.md +39 -19
  44. package/dist/templates/project-tee-starter/__tests__/build-order.test.ts +62 -0
  45. package/dist/templates/project-tee-starter/__tests__/character.test.ts +19 -17
  46. package/dist/templates/project-tee-starter/__tests__/config.test.ts +10 -3
  47. package/dist/templates/project-tee-starter/__tests__/env.test.ts +2 -1
  48. package/dist/templates/project-tee-starter/__tests__/file-structure.test.ts +14 -3
  49. package/dist/templates/project-tee-starter/__tests__/frontend.test.ts +459 -0
  50. package/dist/templates/project-tee-starter/__tests__/plugin.test.ts +4 -2
  51. package/dist/templates/project-tee-starter/__tests__/routes.test.ts +15 -6
  52. package/dist/templates/project-tee-starter/__tests__/tee-validation.test.ts +295 -0
  53. package/dist/templates/project-tee-starter/__tests__/vite-config-utils.ts +39 -0
  54. package/dist/templates/project-tee-starter/docker-compose.yaml +5 -2
  55. package/dist/templates/{plugin-starter/dist → project-tee-starter}/index.html +3 -3
  56. package/dist/templates/project-tee-starter/package.json +34 -14
  57. package/dist/templates/project-tee-starter/postcss.config.js +3 -0
  58. package/dist/templates/project-tee-starter/scripts/install-test-deps.js +52 -0
  59. package/dist/templates/project-tee-starter/scripts/test-all.sh +82 -0
  60. package/dist/templates/project-tee-starter/src/frontend/index.css +106 -0
  61. package/dist/templates/project-tee-starter/src/frontend/index.html +20 -0
  62. package/dist/templates/project-tee-starter/src/frontend/index.tsx +370 -0
  63. package/dist/templates/project-tee-starter/src/frontend/panels.tsx +17 -0
  64. package/dist/templates/project-tee-starter/src/frontend/utils.ts +6 -0
  65. package/dist/templates/project-tee-starter/src/index.ts +6 -6
  66. package/dist/templates/project-tee-starter/src/plugin.ts +209 -59
  67. package/dist/templates/project-tee-starter/tailwind.config.js +62 -0
  68. package/dist/templates/project-tee-starter/tsconfig.build.json +2 -2
  69. package/dist/templates/project-tee-starter/tsconfig.json +8 -5
  70. package/dist/templates/project-tee-starter/tsup.config.ts +3 -2
  71. package/dist/templates/project-tee-starter/vite.config.ts +39 -0
  72. package/dist/url-utils-CKc_Ebt_.d.ts +35 -0
  73. package/dist/{utils-H66532NB.js → utils-DBLSDYBF.js} +2 -2
  74. package/package.json +12 -7
  75. package/templates/plugin-quick-starter/.gitignore +66 -0
  76. package/templates/plugin-quick-starter/.npmignore +5 -0
  77. package/templates/plugin-quick-starter/package.json +11 -3
  78. package/templates/plugin-quick-starter/src/__tests__/plugin.test.ts +499 -146
  79. package/templates/plugin-quick-starter/src/__tests__/test-utils.ts +316 -115
  80. package/templates/plugin-quick-starter/src/plugin.ts +7 -13
  81. package/templates/plugin-starter/.gitignore +66 -0
  82. package/templates/plugin-starter/.npmignore +5 -0
  83. package/templates/plugin-starter/README.md +1 -1
  84. package/templates/plugin-starter/package.json +11 -3
  85. package/templates/plugin-starter/src/__tests__/integration.test.ts +13 -13
  86. package/templates/plugin-starter/src/__tests__/plugin.test.ts +556 -129
  87. package/templates/plugin-starter/src/__tests__/test-utils.ts +347 -115
  88. package/templates/plugin-starter/src/plugin.ts +18 -22
  89. package/templates/project-starter/.gitignore +57 -0
  90. package/templates/project-starter/.npmignore +11 -0
  91. package/templates/project-starter/README.md +1 -1
  92. package/templates/project-starter/package.json +4 -4
  93. package/templates/project-starter/src/__tests__/env.test.ts +3 -1
  94. package/templates/project-starter/src/__tests__/file-structure.test.ts +3 -2
  95. package/templates/project-starter/src/__tests__/integration.test.ts +1 -1
  96. package/templates/project-starter/tsup.config.ts +2 -1
  97. package/templates/project-tee-starter/.dockerignore +64 -14
  98. package/templates/project-tee-starter/.gitignore +57 -0
  99. package/templates/project-tee-starter/.npmignore +6 -0
  100. package/templates/project-tee-starter/Dockerfile +9 -5
  101. package/templates/project-tee-starter/GUIDE.md +103 -42
  102. package/templates/project-tee-starter/README.md +39 -19
  103. package/templates/project-tee-starter/__tests__/build-order.test.ts +62 -0
  104. package/templates/project-tee-starter/__tests__/character.test.ts +19 -17
  105. package/templates/project-tee-starter/__tests__/config.test.ts +10 -3
  106. package/templates/project-tee-starter/__tests__/env.test.ts +2 -1
  107. package/templates/project-tee-starter/__tests__/file-structure.test.ts +14 -3
  108. package/templates/project-tee-starter/__tests__/frontend.test.ts +459 -0
  109. package/templates/project-tee-starter/__tests__/plugin.test.ts +4 -2
  110. package/templates/project-tee-starter/__tests__/routes.test.ts +15 -6
  111. package/templates/project-tee-starter/__tests__/tee-validation.test.ts +295 -0
  112. package/templates/project-tee-starter/__tests__/vite-config-utils.ts +39 -0
  113. package/templates/project-tee-starter/docker-compose.yaml +5 -2
  114. package/templates/{plugin-starter/dist → project-tee-starter}/index.html +3 -3
  115. package/templates/project-tee-starter/package.json +34 -14
  116. package/templates/project-tee-starter/postcss.config.js +3 -0
  117. package/templates/project-tee-starter/scripts/install-test-deps.js +52 -0
  118. package/templates/project-tee-starter/scripts/test-all.sh +82 -0
  119. package/templates/project-tee-starter/src/frontend/index.css +106 -0
  120. package/templates/project-tee-starter/src/frontend/index.html +20 -0
  121. package/templates/project-tee-starter/src/frontend/index.tsx +370 -0
  122. package/templates/project-tee-starter/src/frontend/panels.tsx +17 -0
  123. package/templates/project-tee-starter/src/frontend/utils.ts +6 -0
  124. package/templates/project-tee-starter/src/index.ts +6 -6
  125. package/templates/project-tee-starter/src/plugin.ts +209 -59
  126. package/templates/project-tee-starter/tailwind.config.js +62 -0
  127. package/templates/project-tee-starter/tsconfig.build.json +2 -2
  128. package/templates/project-tee-starter/tsconfig.json +8 -5
  129. package/templates/project-tee-starter/tsup.config.ts +3 -2
  130. package/templates/project-tee-starter/vite.config.ts +39 -0
  131. package/dist/chunk-4O6EZU37.js +0 -14
  132. package/dist/migration-guides/advanced-migration-guide.md +0 -459
  133. package/dist/migration-guides/completion-requirements.md +0 -379
  134. package/dist/migration-guides/integrated-migration-loop.md +0 -392
  135. package/dist/migration-guides/migration-guide.md +0 -712
  136. package/dist/migration-guides/prompt-and-generation-guide.md +0 -702
  137. package/dist/migration-guides/state-and-providers-guide.md +0 -544
  138. package/dist/migration-guides/testing-guide.md +0 -1021
  139. package/dist/templates/plugin-starter/dist/assets/index-CgkejLs_.css +0 -1
  140. package/dist/templates/plugin-starter/dist/assets/index-D1cHX53P.js +0 -49
  141. package/dist/templates/plugin-starter/dist/index.js +0 -387
  142. package/dist/templates/plugin-starter/dist/index.js.map +0 -1
  143. package/templates/plugin-starter/dist/.vite/manifest.json +0 -11
  144. package/templates/plugin-starter/dist/assets/index-CgkejLs_.css +0 -1
  145. package/templates/plugin-starter/dist/assets/index-D1cHX53P.js +0 -49
  146. package/templates/plugin-starter/dist/index.d.ts +0 -14
  147. package/templates/plugin-starter/dist/index.js +0 -387
  148. package/templates/plugin-starter/dist/index.js.map +0 -1
@@ -1,702 +0,0 @@
1
- # ElizaOS Prompt Composition & Generation Guide - v1.x
2
-
3
- > **Important**: This guide provides comprehensive documentation for migrating from `composeContext` to the new prompt composition methods, and from the old generation functions to `useModel`.
4
-
5
- ## Table of Contents
6
-
7
- - [Overview of Changes](#overview-of-changes)
8
- - [Prompt Composition Migration](#prompt-composition-migration)
9
- - [composeContext → composePrompt/composePromptFromState](#composecontext--composepromptcomposepromptfromstate)
10
- - [Key Differences](#key-differences)
11
- - [Migration Examples](#migration-examples)
12
- - [Text Generation Migration](#text-generation-migration)
13
- - [generateText → useModel](#generatetext--usemodel)
14
- - [generateObject → useModel](#generateobject--usemodel)
15
- - [generateMessageResponse → useModel](#generatemessageresponse--usemodel)
16
- - [Template Format Migration](#template-format-migration)
17
- - [JSON → XML Templates](#json--xml-templates)
18
- - [Parsing Changes](#parsing-changes)
19
- - [Complete Migration Examples](#complete-migration-examples)
20
- - [Benefits of the New Approach](#benefits-of-the-new-approach)
21
- - [Real-World Migration Example: Gitcoin Passport Score Action](#real-world-migration-example-gitcoin-passport-score-action)
22
-
23
- ---
24
-
25
- ## Overview of Changes
26
-
27
- The v1 migration introduces several key improvements:
28
-
29
- 1. **Prompt Composition**: `composeContext` split into two specialized functions
30
- 2. **Unified Model Interface**: All generation functions consolidated into `runtime.useModel`
31
- 3. **Template Format**: JSON responses replaced with XML for better parsing
32
- 4. **Better Type Safety**: Improved TypeScript support throughout
33
-
34
- ---
35
-
36
- ## Prompt Composition Migration
37
-
38
- ### composeContext → composePrompt/composePromptFromState
39
-
40
- #### v0: Single composeContext Function
41
-
42
- ```typescript
43
- // v0: packages/core-0x/src/context.ts
44
- export const composeContext = ({
45
- state,
46
- template,
47
- templatingEngine,
48
- }: {
49
- state: State;
50
- template: TemplateType;
51
- templatingEngine?: 'handlebars';
52
- }) => {
53
- // Supported both simple replacement and handlebars
54
- if (templatingEngine === 'handlebars') {
55
- const templateFunction = handlebars.compile(templateStr);
56
- return templateFunction(state);
57
- }
58
- // Simple {{key}} replacement
59
- return templateStr.replace(/{{\w+}}/g, (match) => {
60
- const key = match.replace(/{{|}}/g, '');
61
- return state[key] ?? '';
62
- });
63
- };
64
- ```
65
-
66
- #### v1: Two Specialized Functions
67
-
68
- ```typescript
69
- // v1: packages/core/src/utils.ts
70
-
71
- // For simple key-value state objects
72
- export const composePrompt = ({
73
- state,
74
- template,
75
- }: {
76
- state: { [key: string]: string };
77
- template: TemplateType;
78
- }) => {
79
- const templateStr = typeof template === 'function' ? template({ state }) : template;
80
- const templateFunction = handlebars.compile(upgradeDoubleToTriple(templateStr));
81
- const output = composeRandomUser(templateFunction(state), 10);
82
- return output;
83
- };
84
-
85
- // For complex State objects from runtime
86
- export const composePromptFromState = ({
87
- state,
88
- template,
89
- }: {
90
- state: State;
91
- template: TemplateType;
92
- }) => {
93
- const templateStr = typeof template === 'function' ? template({ state }) : template;
94
- const templateFunction = handlebars.compile(upgradeDoubleToTriple(templateStr));
95
-
96
- // Intelligent state flattening
97
- const stateKeys = Object.keys(state);
98
- const filteredKeys = stateKeys.filter((key) => !['text', 'values', 'data'].includes(key));
99
-
100
- const filteredState = filteredKeys.reduce((acc, key) => {
101
- acc[key] = state[key];
102
- return acc;
103
- }, {});
104
-
105
- // Merges filtered state with state.values
106
- const output = composeRandomUser(templateFunction({ ...filteredState, ...state.values }), 10);
107
- return output;
108
- };
109
- ```
110
-
111
- ### Key Differences
112
-
113
- 1. **Handlebars by Default**: v1 always uses Handlebars (no simple replacement mode)
114
- 2. **Auto HTML Escaping**: v1 automatically converts `{{var}}` to `{{{var}}}` to prevent HTML escaping
115
- 3. **State Handling**: `composePromptFromState` intelligently flattens complex State objects
116
- 4. **Random User Names**: Both functions automatically replace `{{name1}}`, `{{name2}}`, etc. with random names
117
-
118
- ### Migration Examples
119
-
120
- #### Simple State Objects
121
-
122
- ```typescript
123
- // v0
124
- const prompt = composeContext({
125
- state: { userName: 'Alice', topic: 'weather' },
126
- template: "Hello {{userName}}, let's talk about {{topic}}",
127
- });
128
-
129
- // v1
130
- const prompt = composePrompt({
131
- state: { userName: 'Alice', topic: 'weather' },
132
- template: "Hello {{userName}}, let's talk about {{topic}}",
133
- });
134
- ```
135
-
136
- #### Complex Runtime State
137
-
138
- ```typescript
139
- // v0
140
- const prompt = composeContext({
141
- state: currentState,
142
- template: messageTemplate,
143
- templatingEngine: 'handlebars',
144
- });
145
-
146
- // v1 - Use composePromptFromState for State objects
147
- const prompt = composePromptFromState({
148
- state: currentState,
149
- template: messageTemplate,
150
- });
151
- ```
152
-
153
- #### Dynamic Templates
154
-
155
- ```typescript
156
- // v0
157
- const template = ({ state }) => {
158
- return state.isUrgent ? 'URGENT: {{message}}' : 'Info: {{message}}';
159
- };
160
-
161
- const prompt = composeContext({ state, template });
162
-
163
- // v1 - Same pattern works
164
- const prompt = composePrompt({ state, template });
165
- ```
166
-
167
- ---
168
-
169
- ## Text Generation Migration
170
-
171
- ### generateText → useModel
172
-
173
- #### v0: Standalone Function
174
-
175
- ```typescript
176
- // v0: Using generateText
177
- import { generateText, ModelClass } from '@elizaos/core';
178
-
179
- const response = await generateText({
180
- runtime,
181
- context: prompt,
182
- modelClass: ModelClass.SMALL,
183
- stop: ['\n'],
184
- temperature: 0.7,
185
- });
186
- ```
187
-
188
- #### v1: Runtime Method
189
-
190
- ```typescript
191
- // v1: Using runtime.useModel
192
- import { ModelType } from '@elizaos/core';
193
-
194
- const response = await runtime.useModel(ModelType.TEXT_SMALL, {
195
- prompt,
196
- stopSequences: ['\n'],
197
- temperature: 0.7,
198
- });
199
- ```
200
-
201
- ### generateObject → useModel
202
-
203
- #### v0: Object Generation
204
-
205
- ```typescript
206
- // v0: Using generateObject
207
- const content = await generateObject({
208
- runtime,
209
- context: prompt,
210
- modelClass: ModelClass.SMALL,
211
- });
212
-
213
- // Returned raw object
214
- console.log(content.name, content.value);
215
- ```
216
-
217
- #### v1: Using useModel with XML
218
-
219
- ```typescript
220
- // v1: Generate text with XML format
221
- const xmlResponse = await runtime.useModel(ModelType.TEXT_SMALL, {
222
- prompt,
223
- });
224
-
225
- // Parse XML to object
226
- const content = parseKeyValueXml(xmlResponse);
227
- console.log(content.name, content.value);
228
- ```
229
-
230
- ### generateMessageResponse → useModel
231
-
232
- #### v0: Message Response Generation
233
-
234
- ```typescript
235
- // v0: From getScore.ts example
236
- const addressRequest = await generateMessageResponse({
237
- runtime,
238
- context,
239
- modelClass: ModelClass.SMALL,
240
- });
241
-
242
- const address = addressRequest.address as string;
243
- ```
244
-
245
- #### v1: Using useModel with XML Template
246
-
247
- ```typescript
248
- // v1: Generate and parse XML response
249
- const xmlResponse = await runtime.useModel(ModelType.TEXT_SMALL, {
250
- prompt: context,
251
- });
252
-
253
- const addressRequest = parseKeyValueXml(xmlResponse);
254
- const address = addressRequest.address as string;
255
- ```
256
-
257
- ---
258
-
259
- ## Template Format Migration
260
-
261
- ### JSON → XML Templates
262
-
263
- The most significant change is moving from JSON to XML format for structured responses.
264
-
265
- #### v0: JSON Template
266
-
267
- ```typescript
268
- const addressTemplate = `From previous sentence extract only the Ethereum address being asked about.
269
- Respond with a JSON markdown block containing only the extracted value:
270
-
271
- \`\`\`json
272
- {
273
- "address": string | null
274
- }
275
- \`\`\`
276
- `;
277
- ```
278
-
279
- #### v1: XML Template
280
-
281
- ```typescript
282
- const addressTemplate = `From previous sentence extract only the Ethereum address being asked about.
283
- Respond with an XML block containing only the extracted value:
284
-
285
- <response>
286
- <address>extracted_address_here_or_null</address>
287
- </response>
288
- `;
289
- ```
290
-
291
- ### Parsing Changes
292
-
293
- #### v0: JSON Parsing
294
-
295
- ```typescript
296
- // v0: Parse JSON from text
297
- import { parseJSONObjectFromText } from '@elizaos/core';
298
-
299
- const parsedContent = parseJSONObjectFromText(response);
300
- if (parsedContent && parsedContent.address) {
301
- // Use the address
302
- }
303
- ```
304
-
305
- #### v1: XML Parsing
306
-
307
- ```typescript
308
- // v1: Parse XML key-value pairs
309
- import { parseKeyValueXml } from '@elizaos/core';
310
-
311
- const parsedContent = parseKeyValueXml(response);
312
- if (parsedContent && parsedContent.address) {
313
- // Use the address
314
- }
315
- ```
316
-
317
- ### Template Examples
318
-
319
- #### Complex Object Extraction
320
-
321
- ```typescript
322
- // v0: JSON Template
323
- const template = `Extract token information from the message.
324
- Return a JSON object:
325
-
326
- \`\`\`json
327
- {
328
- "name": "token name",
329
- "symbol": "token symbol",
330
- "supply": "total supply",
331
- "features": ["feature1", "feature2"]
332
- }
333
- \`\`\``;
334
-
335
- // v1: XML Template
336
- const template = `Extract token information from the message.
337
- Return an XML response:
338
-
339
- <response>
340
- <name>token name</name>
341
- <symbol>token symbol</symbol>
342
- <supply>total supply</supply>
343
- <features>feature1,feature2</features>
344
- </response>`;
345
- ```
346
-
347
- ---
348
-
349
- ## Complete Migration Examples
350
-
351
- ### Example 1: Simple Action Handler
352
-
353
- ```typescript
354
- // v0: Old Action Handler
355
- import { composeContext, generateMessageResponse, ModelClass } from '@elizaos/core';
356
-
357
- handler: async (runtime, message, state) => {
358
- // Compose context
359
- const context = composeContext({
360
- state,
361
- template: addressTemplate,
362
- });
363
-
364
- // Generate response
365
- const response = await generateMessageResponse({
366
- runtime,
367
- context,
368
- modelClass: ModelClass.SMALL,
369
- });
370
-
371
- const address = response.address;
372
- // Process address...
373
- };
374
- ```
375
-
376
- ```typescript
377
- // v1: New Action Handler
378
- import { composePromptFromState, parseKeyValueXml, ModelType } from '@elizaos/core';
379
-
380
- handler: async (runtime, message, state) => {
381
- // Compose prompt
382
- const prompt = composePromptFromState({
383
- state,
384
- template: addressTemplate, // Now using XML format
385
- });
386
-
387
- // Generate response
388
- const xmlResponse = await runtime.useModel(ModelType.TEXT_SMALL, {
389
- prompt,
390
- });
391
-
392
- // Parse XML
393
- const response = parseKeyValueXml(xmlResponse);
394
- const address = response.address;
395
- // Process address...
396
- };
397
- ```
398
-
399
- ### Example 2: Complex State Handling
400
-
401
- ```typescript
402
- // v0: Complex Context Building
403
- const context = composeContext({
404
- state: {
405
- ...baseState,
406
- recentMessages: formatMessages(messages),
407
- userName: user.name,
408
- customData: JSON.stringify(data),
409
- },
410
- template: complexTemplate,
411
- templatingEngine: 'handlebars',
412
- });
413
-
414
- const result = await generateObject({
415
- runtime,
416
- context,
417
- modelClass: ModelClass.LARGE,
418
- });
419
-
420
- // v1: Simplified with composePromptFromState
421
- const state = await runtime.composeState(message);
422
- const prompt = composePromptFromState({
423
- state, // Already contains recentMessages, userName, etc.
424
- template: complexTemplate,
425
- });
426
-
427
- const xmlResult = await runtime.useModel(ModelType.TEXT_LARGE, {
428
- prompt,
429
- });
430
-
431
- const result = parseKeyValueXml(xmlResult);
432
- ```
433
-
434
- ### Example 3: Custom Model Parameters
435
-
436
- ```typescript
437
- // v0: Limited control
438
- const response = await generateText({
439
- runtime,
440
- context,
441
- modelClass: ModelClass.SMALL,
442
- temperature: 0.7,
443
- stop: ['\n', 'END'],
444
- maxTokens: 100,
445
- });
446
-
447
- // v1: Full control with useModel
448
- const response = await runtime.useModel(ModelType.TEXT_SMALL, {
449
- prompt,
450
- temperature: 0.7,
451
- stopSequences: ['\n', 'END'],
452
- maxTokens: 100,
453
- frequencyPenalty: 0.5,
454
- presencePenalty: 0.5,
455
- // Any additional model-specific parameters
456
- });
457
- ```
458
-
459
- ---
460
-
461
- ## Benefits of the New Approach
462
-
463
- ### 1. Unified Interface
464
-
465
- **v0 Problems:**
466
-
467
- - Multiple generation functions (`generateText`, `generateObject`, `generateMessageResponse`)
468
- - Inconsistent parameter names
469
- - Different return types
470
-
471
- **v1 Solution:**
472
-
473
- - Single `useModel` method for all model interactions
474
- - Consistent parameter interface
475
- - Predictable return types
476
-
477
- ### 2. Better State Management
478
-
479
- **v0 Problems:**
480
-
481
- - Manual state flattening required
482
- - Confusion between State object and simple key-value objects
483
- - No intelligent handling of nested data
484
-
485
- **v1 Solution:**
486
-
487
- - `composePromptFromState` intelligently handles State objects
488
- - Automatic flattening of relevant fields
489
- - Preserves state.values for template access
490
-
491
- ### 3. XML Over JSON
492
-
493
- **v0 Problems:**
494
-
495
- - JSON parsing often failed with markdown code blocks
496
- - Complex escaping issues
497
- - Inconsistent formatting from LLMs
498
-
499
- **v1 Solution:**
500
-
501
- - XML is more forgiving and easier to parse
502
- - Better handling of special characters
503
- - More consistent LLM outputs
504
-
505
- ### 4. Type Safety
506
-
507
- **v0 Problems:**
508
-
509
- - Loose typing on generation functions
510
- - Runtime errors from type mismatches
511
- - Poor IDE support
512
-
513
- **v1 Solution:**
514
-
515
- - Strong TypeScript types throughout
516
- - `ModelType` enum for model selection
517
- - Better IDE autocomplete and error detection
518
-
519
- ### 5. Extensibility
520
-
521
- **v0 Problems:**
522
-
523
- - Hard-coded model providers
524
- - Limited customization options
525
- - Difficult to add new models
526
-
527
- **v1 Solution:**
528
-
529
- - Pluggable model system via `runtime.registerModel`
530
- - Easy to add custom model providers
531
- - Standardized model interface
532
-
533
- ### 6. Performance
534
-
535
- **v0 Problems:**
536
-
537
- - Multiple parsing attempts for JSON
538
- - Redundant context building
539
- - No caching mechanism
540
-
541
- **v1 Solution:**
542
-
543
- - Single-pass XML parsing
544
- - Efficient state composition
545
- - Built-in caching support in `composeState`
546
-
547
- ---
548
-
549
- ## Real-World Migration Example: Gitcoin Passport Score Action
550
-
551
- Here's a complete migration of a real action from the Gitcoin Passport plugin:
552
-
553
- ### Original v0 Action
554
-
555
- ```typescript
556
- import {
557
- type Action,
558
- elizaLogger,
559
- type IAgentRuntime,
560
- type Memory,
561
- type HandlerCallback,
562
- type State,
563
- getEmbeddingZeroVector,
564
- composeContext,
565
- generateMessageResponse,
566
- ModelClass,
567
- } from '@elizaos/core';
568
-
569
- export const addressTemplate = `From previous sentence extract only the Ethereum address being asked about.
570
- Respond with a JSON markdown block containing only the extracted value:
571
-
572
- \`\`\`json
573
- {
574
- "address": string | null
575
- }
576
- \`\`\`
577
- `;
578
-
579
- handler: async (runtime, _message, state, _options, callback) => {
580
- // Initialize or update state
581
- let currentState = state;
582
- if (!currentState) {
583
- currentState = (await runtime.composeState(_message)) as State;
584
- } else {
585
- currentState = await runtime.updateRecentMessageState(currentState);
586
- }
587
-
588
- const context = composeContext({
589
- state: currentState,
590
- template: `${_message.content.text}\n${addressTemplate}`,
591
- });
592
-
593
- const addressRequest = await generateMessageResponse({
594
- runtime,
595
- context,
596
- modelClass: ModelClass.SMALL,
597
- });
598
-
599
- const address = addressRequest.address as string;
600
- // ... rest of handler
601
- };
602
- ```
603
-
604
- ### Migrated v1 Action
605
-
606
- ```typescript
607
- import {
608
- type Action,
609
- elizaLogger,
610
- type IAgentRuntime,
611
- type Memory,
612
- type HandlerCallback,
613
- type State,
614
- composePromptFromState,
615
- parseKeyValueXml,
616
- ModelType,
617
- } from '@elizaos/core';
618
-
619
- export const addressTemplate = `From previous sentence extract only the Ethereum address being asked about.
620
- Respond with an XML block containing only the extracted value:
621
-
622
- <response>
623
- <address>extracted_ethereum_address_or_null</address>
624
- </response>
625
- `;
626
-
627
- handler: async (runtime, _message, state, _options, callback) => {
628
- // Initialize or update state
629
- let currentState = state;
630
- if (!currentState) {
631
- currentState = await runtime.composeState(_message);
632
- } else {
633
- currentState = await runtime.composeState(_message, ['RECENT_MESSAGES']);
634
- }
635
-
636
- const prompt = composePromptFromState({
637
- state: currentState,
638
- template: `${_message.content.text}\n${addressTemplate}`,
639
- });
640
-
641
- const xmlResponse = await runtime.useModel(ModelType.TEXT_SMALL, {
642
- prompt,
643
- });
644
-
645
- const addressRequest = parseKeyValueXml(xmlResponse);
646
- const address = addressRequest?.address as string;
647
- // ... rest of handler
648
- };
649
- ```
650
-
651
- ### Memory Creation Migration
652
-
653
- ```typescript
654
- // v0: Using deprecated fields
655
- const memory: Memory = {
656
- userId: _message.userId,
657
- agentId: _message.agentId,
658
- roomId: _message.roomId,
659
- content: { text: formattedOutput },
660
- createdAt: Date.now(),
661
- embedding: getEmbeddingZeroVector(),
662
- };
663
- await runtime.messageManager.createMemory(memory);
664
-
665
- // v1: Using new structure
666
- const memory: Memory = {
667
- entityId: _message.entityId,
668
- agentId: runtime.agentId,
669
- roomId: _message.roomId,
670
- content: { text: formattedOutput },
671
- createdAt: Date.now(),
672
- // embedding will be added by runtime if needed
673
- };
674
- await runtime.createMemory(memory);
675
- ```
676
-
677
- ### Complete Action Migration Summary
678
-
679
- 1. **Imports**: Replace old functions with new equivalents
680
- 2. **Template**: Convert JSON format to XML
681
- 3. **State Management**: Use `composeState` with filtering
682
- 4. **Generation**: Replace `generateMessageResponse` with `useModel`
683
- 5. **Parsing**: Use `parseKeyValueXml` instead of direct object access
684
- 6. **Memory**: Update to use `entityId` and new creation method
685
-
686
- ---
687
-
688
- ## Migration Checklist
689
-
690
- - [ ] Replace `composeContext` with `composePrompt` or `composePromptFromState`
691
- - [ ] Update all templates from JSON to XML format
692
- - [ ] Replace `generateText` with `runtime.useModel(ModelType.TEXT_*)`
693
- - [ ] Replace `generateObject` with `runtime.useModel` + `parseKeyValueXml`
694
- - [ ] Replace `generateMessageResponse` with `runtime.useModel` + `parseKeyValueXml`
695
- - [ ] Update `ModelClass` to `ModelType` enum values
696
- - [ ] Replace `parseJSONObjectFromText` with `parseKeyValueXml`
697
- - [ ] Update import statements to use new functions
698
- - [ ] Test XML parsing with your specific use cases
699
- - [ ] Consider using state filtering for performance optimization
700
- - [ ] Update Memory objects to use `entityId` instead of `userId`
701
- - [ ] Replace `runtime.updateRecentMessageState` with filtered `composeState`
702
- - [ ] Remove `getEmbeddingZeroVector` - embeddings are handled automatically