@elizaos/core 1.5.1 → 1.5.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 (88) hide show
  1. package/dist/browser/index.browser.js +120 -120
  2. package/dist/browser/index.browser.js.map +5 -21
  3. package/dist/browser/index.d.ts +3 -1
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.js +1 -5
  6. package/dist/node/index.d.ts +3 -1
  7. package/package.json +10 -4
  8. package/src/__tests__/action-chaining-simple.test.ts +203 -0
  9. package/src/__tests__/actions.test.ts +218 -0
  10. package/src/__tests__/buffer.test.ts +337 -0
  11. package/src/__tests__/character-validation.test.ts +309 -0
  12. package/src/__tests__/database.test.ts +750 -0
  13. package/src/__tests__/entities.test.ts +727 -0
  14. package/src/__tests__/env.test.ts +23 -0
  15. package/src/__tests__/environment.test.ts +285 -0
  16. package/src/__tests__/logger-browser-node.test.ts +716 -0
  17. package/src/__tests__/logger.test.ts +403 -0
  18. package/src/__tests__/messages.test.ts +196 -0
  19. package/src/__tests__/mockCharacter.ts +544 -0
  20. package/src/__tests__/parsing.test.ts +58 -0
  21. package/src/__tests__/prompts.test.ts +159 -0
  22. package/src/__tests__/roles.test.ts +331 -0
  23. package/src/__tests__/runtime-embedding.test.ts +343 -0
  24. package/src/__tests__/runtime.test.ts +978 -0
  25. package/src/__tests__/search.test.ts +15 -0
  26. package/src/__tests__/services-by-type.test.ts +204 -0
  27. package/src/__tests__/services.test.ts +136 -0
  28. package/src/__tests__/settings.test.ts +810 -0
  29. package/src/__tests__/utils.test.ts +1105 -0
  30. package/src/__tests__/uuid.test.ts +94 -0
  31. package/src/actions.ts +122 -0
  32. package/src/database.ts +579 -0
  33. package/src/entities.ts +406 -0
  34. package/src/index.browser.ts +48 -0
  35. package/src/index.node.ts +39 -0
  36. package/src/index.ts +50 -0
  37. package/src/logger.ts +527 -0
  38. package/src/prompts.ts +243 -0
  39. package/src/roles.ts +85 -0
  40. package/src/runtime.ts +2514 -0
  41. package/src/schemas/character.ts +149 -0
  42. package/src/search.ts +1543 -0
  43. package/src/sentry/instrument.browser.ts +65 -0
  44. package/src/sentry/instrument.node.ts +57 -0
  45. package/src/sentry/instrument.ts +82 -0
  46. package/src/services.ts +105 -0
  47. package/src/settings.ts +409 -0
  48. package/src/test_resources/constants.ts +12 -0
  49. package/src/test_resources/testSetup.ts +21 -0
  50. package/src/test_resources/types.ts +22 -0
  51. package/src/types/agent.ts +112 -0
  52. package/src/types/browser.ts +145 -0
  53. package/src/types/components.ts +184 -0
  54. package/src/types/database.ts +348 -0
  55. package/src/types/email.ts +162 -0
  56. package/src/types/environment.ts +129 -0
  57. package/src/types/events.ts +249 -0
  58. package/src/types/index.ts +29 -0
  59. package/src/types/knowledge.ts +65 -0
  60. package/src/types/lp.ts +124 -0
  61. package/src/types/memory.ts +228 -0
  62. package/src/types/message.ts +233 -0
  63. package/src/types/messaging.ts +57 -0
  64. package/src/types/model.ts +359 -0
  65. package/src/types/pdf.ts +77 -0
  66. package/src/types/plugin.ts +78 -0
  67. package/src/types/post.ts +271 -0
  68. package/src/types/primitives.ts +97 -0
  69. package/src/types/runtime.ts +190 -0
  70. package/src/types/service.ts +198 -0
  71. package/src/types/settings.ts +30 -0
  72. package/src/types/state.ts +60 -0
  73. package/src/types/task.ts +72 -0
  74. package/src/types/tee.ts +107 -0
  75. package/src/types/testing.ts +30 -0
  76. package/src/types/token.ts +96 -0
  77. package/src/types/transcription.ts +133 -0
  78. package/src/types/video.ts +108 -0
  79. package/src/types/wallet.ts +56 -0
  80. package/src/types/web-search.ts +146 -0
  81. package/src/utils/__tests__/buffer.test.ts +80 -0
  82. package/src/utils/__tests__/environment.test.ts +58 -0
  83. package/src/utils/__tests__/stringToUuid.test.ts +88 -0
  84. package/src/utils/buffer.ts +312 -0
  85. package/src/utils/environment.ts +316 -0
  86. package/src/utils/server-health.ts +117 -0
  87. package/src/utils.ts +1076 -0
  88. package/dist/tsconfig.build.tsbuildinfo +0 -1
package/src/prompts.ts ADDED
@@ -0,0 +1,243 @@
1
+ export const shouldRespondTemplate = `<task>Decide on behalf of {{agentName}} whether they should respond to the message, ignore it or stop the conversation.</task>
2
+
3
+ <providers>
4
+ {{providers}}
5
+ </providers>
6
+
7
+ <instructions>Decide if {{agentName}} should respond to or interact with the conversation.
8
+ If the message is directed at or relevant to {{agentName}}, respond with RESPOND action.
9
+ If a user asks {{agentName}} to be quiet, respond with STOP action.
10
+ If {{agentName}} should ignore the message, respond with IGNORE action.</instructions>
11
+
12
+ <output>
13
+ Do NOT include any thinking, reasoning, or <think> sections in your response.
14
+ Go directly to the XML response format without any preamble or explanation.
15
+
16
+ Respond using XML format like this:
17
+ <response>
18
+ <name>{{agentName}}</name>
19
+ <reasoning>Your reasoning here</reasoning>
20
+ <action>RESPOND | IGNORE | STOP</action>
21
+ </response>
22
+
23
+ IMPORTANT: Your response must ONLY contain the <response></response> XML block above. Do not include any text, thinking, or reasoning before or after this XML block. Start your response immediately with <response> and end with </response>.
24
+ </output>`;
25
+
26
+ export const messageHandlerTemplate = `<task>Generate dialog and actions for the character {{agentName}}.</task>
27
+
28
+ <providers>
29
+ {{providers}}
30
+ </providers>
31
+
32
+ <instructions>
33
+ Write a thought and plan for {{agentName}} and decide what actions to take. Also include the providers that {{agentName}} will use to have the right context for responding and acting, if any.
34
+
35
+ IMPORTANT ACTION ORDERING RULES:
36
+ - Actions are executed in the ORDER you list them - the order MATTERS!
37
+ - REPLY should come FIRST to acknowledge the user's request before executing other actions
38
+ - Common patterns:
39
+ - For requests requiring tool use: REPLY,CALL_MCP_TOOL (acknowledge first, then gather info)
40
+ - For task execution: REPLY,SEND_MESSAGE or REPLY,EVM_SWAP_TOKENS (acknowledge first, then do the task)
41
+ - For multi-step operations: REPLY,ACTION1,ACTION2 (acknowledge first, then complete all steps)
42
+ - REPLY is used to acknowledge and inform the user about what you're going to do
43
+ - Follow-up actions execute the actual tasks after acknowledgment
44
+ - Use IGNORE only when you should not respond at all
45
+ - If you use IGNORE, do not include any other actions. IGNORE should be used alone when you should not respond or take any actions.
46
+
47
+ IMPORTANT PROVIDER SELECTION RULES:
48
+ - Only include providers if they are needed to respond accurately.
49
+ - If the message mentions images, photos, pictures, attachments, or visual content, OR if you see "(Attachments:" in the conversation, you MUST include "ATTACHMENTS" in your providers list
50
+ - If the message asks about or references specific people, include "ENTITIES" in your providers list
51
+ - If the message asks about relationships or connections between people, include "RELATIONSHIPS" in your providers list
52
+ - If the message asks about facts or specific information, include "FACTS" in your providers list
53
+ - If the message asks about the environment or world context, include "WORLD" in your providers list
54
+ - If no additional context is needed, you may leave the providers list empty.
55
+
56
+ IMPORTANT CODE BLOCK FORMATTING RULES:
57
+ - If {{agentName}} includes code examples, snippets, or multi-line code in the response, ALWAYS wrap the code with \`\`\` fenced code blocks (specify the language if known, e.g., \`\`\`python).
58
+ - ONLY use fenced code blocks for actual code. Do NOT wrap non-code text, instructions, or single words in fenced code blocks.
59
+ - If including inline code (short single words or function names), use single backticks (\`) as appropriate.
60
+ - This ensures the user sees clearly formatted and copyable code when relevant.
61
+
62
+ First, think about what you want to do next and plan your actions. Then, write the next message and include the actions you plan to take.
63
+ </instructions>
64
+
65
+ <keys>
66
+ "thought" should be a short description of what the agent is thinking about and planning.
67
+ "actions" should be a comma-separated list of the actions {{agentName}} plans to take based on the thought, IN THE ORDER THEY SHOULD BE EXECUTED (if none, use IGNORE, if simply responding with text, use REPLY)
68
+ "providers" should be a comma-separated list of the providers that {{agentName}} will use to have the right context for responding and acting (NEVER use "IGNORE" as a provider - use specific provider names like ATTACHMENTS, ENTITIES, FACTS, KNOWLEDGE, etc.)
69
+ "text" should be the text of the next message for {{agentName}} which they will send to the conversation.
70
+ </keys>
71
+
72
+ <output>
73
+ Do NOT include any thinking, reasoning, or <think> sections in your response.
74
+ Go directly to the XML response format without any preamble or explanation.
75
+
76
+ Respond using XML format like this:
77
+ <response>
78
+ <thought>Your thought here</thought>
79
+ <actions>ACTION1,ACTION2</actions>
80
+ <providers>PROVIDER1,PROVIDER2</providers>
81
+ <text>Your response text here</text>
82
+ </response>
83
+
84
+ IMPORTANT: Your response must ONLY contain the <response></response> XML block above. Do not include any text, thinking, or reasoning before or after this XML block. Start your response immediately with <response> and end with </response>.
85
+ </output>`;
86
+
87
+ export const postCreationTemplate = `# Task: Create a post in the voice and style and perspective of {{agentName}} @{{twitterUserName}}.
88
+
89
+ Example task outputs:
90
+ 1. A post about the importance of AI in our lives
91
+ <response>
92
+ <thought>I am thinking about writing a post about the importance of AI in our lives</thought>
93
+ <post>AI is changing the world and it is important to understand how it works</post>
94
+ <imagePrompt>A futuristic cityscape with flying cars and people using AI to do things</imagePrompt>
95
+ </response>
96
+
97
+ 2. A post about dogs
98
+ <response>
99
+ <thought>I am thinking about writing a post about dogs</thought>
100
+ <post>Dogs are man's best friend and they are loyal and loving</post>
101
+ <imagePrompt>A dog playing with a ball in a park</imagePrompt>
102
+ </response>
103
+
104
+ 3. A post about finding a new job
105
+ <response>
106
+ <thought>Getting a job is hard, I bet there's a good tweet in that</thought>
107
+ <post>Just keep going!</post>
108
+ <imagePrompt>A person looking at a computer screen with a job search website</imagePrompt>
109
+ </response>
110
+
111
+ {{providers}}
112
+
113
+ Write a post that is {{adjective}} about {{topic}} (without mentioning {{topic}} directly), from the perspective of {{agentName}}. Do not add commentary or acknowledge this request, just write the post.
114
+ Your response should be 1, 2, or 3 sentences (choose the length at random).
115
+ Your response should not contain any questions. Brief, concise statements only. The total character count MUST be less than 280. No emojis. Use \\n\\n (double spaces) between statements if there are multiple statements in your response.
116
+
117
+ Your output should be formatted in XML like this:
118
+ <response>
119
+ <thought>Your thought here</thought>
120
+ <post>Your post text here</post>
121
+ <imagePrompt>Optional image prompt here</imagePrompt>
122
+ </response>
123
+
124
+ The "post" field should be the post you want to send. Do not including any thinking or internal reflection in the "post" field.
125
+ The "imagePrompt" field is optional and should be a prompt for an image that is relevant to the post. It should be a single sentence that captures the essence of the post. ONLY USE THIS FIELD if it makes sense that the post would benefit from an image.
126
+ The "thought" field should be a short description of what the agent is thinking about before responding, including a brief justification for the response. Includate an explanation how the post is relevant to the topic but unique and different than other posts.
127
+
128
+ Do NOT include any thinking, reasoning, or <think> sections in your response.
129
+ Go directly to the XML response format without any preamble or explanation.
130
+
131
+ IMPORTANT: Your response must ONLY contain the <response></response> XML block above. Do not include any text, thinking, or reasoning before or after this XML block. Start your response immediately with <response> and end with </response>.`;
132
+
133
+ export const booleanFooter = 'Respond with only a YES or a NO.';
134
+
135
+ export const imageDescriptionTemplate = `<task>Analyze the provided image and generate a comprehensive description with multiple levels of detail.</task>
136
+
137
+ <instructions>
138
+ Carefully examine the image and provide:
139
+ 1. A concise, descriptive title that captures the main subject or scene
140
+ 2. A brief summary description (1-2 sentences) highlighting the key elements
141
+ 3. An extensive, detailed description that covers all visible elements, composition, lighting, colors, mood, and any other relevant details
142
+
143
+ Be objective and descriptive. Focus on what you can actually see in the image rather than making assumptions about context or meaning.
144
+ </instructions>
145
+
146
+ <output>
147
+ Do NOT include any thinking, reasoning, or <think> sections in your response.
148
+ Go directly to the XML response format without any preamble or explanation.
149
+
150
+ Respond using XML format like this:
151
+ <response>
152
+ <title>A concise, descriptive title for the image</title>
153
+ <description>A brief 1-2 sentence summary of the key elements in the image</description>
154
+ <text>An extensive, detailed description covering all visible elements, composition, lighting, colors, mood, setting, objects, people, activities, and any other relevant details you can observe in the image</text>
155
+ </response>
156
+
157
+ IMPORTANT: Your response must ONLY contain the <response></response> XML block above. Do not include any text, thinking, or reasoning before or after this XML block. Start your response immediately with <response> and end with </response>.
158
+ </output>`;
159
+
160
+ export const multiStepDecisionTemplate = `<task>
161
+ Determine the next step the assistant should take in this conversation to help the user reach their goal.
162
+ </task>
163
+
164
+ {{recentMessages}}
165
+
166
+ # Multi-Step Workflow
167
+
168
+ In each step, decide:
169
+
170
+ 1. **Which providers (if any)** should be called to gather necessary data.
171
+ 2. **Which action (if any)** should be executed after providers return.
172
+ 3. Decide whether the task is complete. If so, set \`isFinish: true\`. Do not select the \`REPLY\` action; replies are handled separately after task completion.
173
+
174
+ ⚠️ IMPORTANT: Do **not** mark the task as \`isFinish: true\` immediately after calling an action like. Wait for the action to complete before deciding the task is finished.
175
+
176
+ You can select **multiple providers** and at most **one action** per step.
177
+
178
+ If the task is fully resolved and no further steps are needed, mark the step as \`isFinish: true\`.
179
+
180
+ ---
181
+
182
+ {{actionsWithDescriptions}}
183
+
184
+ {{providersWithDescriptions}}
185
+
186
+ These are the actions or data provider calls that have already been used in this run. Use this to avoid redundancy and guide your next move.
187
+
188
+ {{actionResults}}
189
+
190
+ <keys>
191
+ "thought" Clearly explain your reasoning for the selected providers and/or action, and how this step contributes to resolving the user's request.
192
+ "action" Name of the action to execute after providers return (can be null if no action is needed).
193
+ "providers" List of provider names to call in this step (can be empty if none are needed).
194
+ "isFinish" Set to true only if the task is fully complete.
195
+ </keys>
196
+
197
+ <output>
198
+ <response>
199
+ <thought>Your thought here</thought>
200
+ <action>ACTION</action>
201
+ <providers>PROVIDER1,PROVIDER2</providers>
202
+ <isFinish>true | false</isFinish>
203
+ </response>
204
+ </output>`;
205
+
206
+ export const multiStepSummaryTemplate = `<task>
207
+ Summarize what the assistant has done so far and provide a final response to the user based on the completed steps.
208
+ </task>
209
+
210
+ # Context Information
211
+ {{bio}}
212
+
213
+ ---
214
+
215
+ {{system}}
216
+
217
+ ---
218
+
219
+ {{messageDirections}}
220
+
221
+ # Conversation Summary
222
+ Below is the user’s original request and conversation so far:
223
+ {{recentMessages}}
224
+
225
+ # Execution Trace
226
+ Here are the actions taken by the assistant to fulfill the request:
227
+ {{actionResults}}
228
+
229
+ # Assistant’s Last Reasoning Step
230
+ {{recentMessage}}
231
+
232
+ # Instructions
233
+
234
+ - Review the execution trace and last reasoning step carefully
235
+
236
+ - Your final output MUST be in this XML format:
237
+ <output>
238
+ <response>
239
+ <thought>Your thought here</thought>
240
+ <text>Your final message to the user</text>
241
+ </response>
242
+ </output>
243
+ `;
package/src/roles.ts ADDED
@@ -0,0 +1,85 @@
1
+ // File: /swarm/shared/ownership/core.ts
2
+ // Updated to use world metadata instead of cache
3
+
4
+ import { createUniqueUuid } from './entities';
5
+ import { logger } from './logger';
6
+ import { type IAgentRuntime, Role, type World, type UUID } from './types';
7
+
8
+ /**
9
+ * Represents the state of server ownership, including a mapping of server IDs to their respective World objects.
10
+ */
11
+ /**
12
+ * Interface representing the ownership state of servers.
13
+ * @property {Object.<string, World>} servers - The servers and their corresponding worlds, where the key is the server ID and the value is the World object.
14
+ */
15
+ export interface ServerOwnershipState {
16
+ servers: {
17
+ [serverId: string]: World;
18
+ };
19
+ }
20
+
21
+ /**
22
+ * Gets a user's role from world metadata
23
+ */
24
+ /**
25
+ * Retrieve the server role of a specified user entity within a given server.
26
+ *
27
+ * @param {IAgentRuntime} runtime - The runtime object containing necessary configurations and services.
28
+ * @param {string} entityId - The unique identifier of the user entity.
29
+ * @param {string} serverId - The unique identifier of the server.
30
+ * @returns {Promise<Role>} The role of the user entity within the server, resolved as a Promise.
31
+ */
32
+ export async function getUserServerRole(
33
+ runtime: IAgentRuntime,
34
+ entityId: string,
35
+ serverId: string
36
+ ): Promise<Role> {
37
+ const worldId = createUniqueUuid(runtime, serverId);
38
+ const world = await runtime.getWorld(worldId);
39
+
40
+ if (!world || !world.metadata?.roles) {
41
+ return Role.NONE;
42
+ }
43
+
44
+ if (world.metadata.roles[entityId as UUID]) {
45
+ return world.metadata.roles[entityId as UUID] as Role;
46
+ }
47
+
48
+ // Also check original ID format
49
+ if (world.metadata.roles[entityId as UUID]) {
50
+ return world.metadata.roles[entityId as UUID] as Role;
51
+ }
52
+
53
+ return Role.NONE;
54
+ }
55
+
56
+ /**
57
+ * Finds a server where the given user is the owner
58
+ */
59
+ export async function findWorldsForOwner(
60
+ runtime: IAgentRuntime,
61
+ entityId: string
62
+ ): Promise<World[] | null> {
63
+ if (!entityId) {
64
+ logger.error('User ID is required to find server');
65
+ return null;
66
+ }
67
+
68
+ // Get all worlds for this agent
69
+ const worlds = await runtime.getAllWorlds();
70
+
71
+ if (!worlds || worlds.length === 0) {
72
+ logger.info('No worlds found for this agent');
73
+ return null;
74
+ }
75
+
76
+ const ownerWorlds: World[] = [];
77
+ // Find world where the user is the owner
78
+ for (const world of worlds) {
79
+ if (world.metadata?.ownership?.ownerId === entityId) {
80
+ ownerWorlds.push(world);
81
+ }
82
+ }
83
+
84
+ return ownerWorlds.length ? ownerWorlds : null;
85
+ }