@elizaos/core 2.0.0-alpha.5 → 2.0.0-alpha.51

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 (133) hide show
  1. package/README.md +213 -16
  2. package/dist/testing/index.js +22 -0
  3. package/dist/testing/index.js.map +9 -0
  4. package/package.json +45 -26
  5. package/dist/actions.d.ts +0 -22
  6. package/dist/actions.d.ts.map +0 -1
  7. package/dist/browser/index.browser.js +0 -770
  8. package/dist/browser/index.browser.js.map +0 -427
  9. package/dist/browser/index.d.ts +0 -2
  10. package/dist/character.d.ts +0 -39
  11. package/dist/character.d.ts.map +0 -1
  12. package/dist/constants/embedding.d.ts +0 -16
  13. package/dist/constants/index.d.ts +0 -7
  14. package/dist/constants/secrets.d.ts +0 -67
  15. package/dist/database.d.ts +0 -494
  16. package/dist/database.d.ts.map +0 -1
  17. package/dist/elizaos.d.ts +0 -194
  18. package/dist/elizaos.d.ts.map +0 -1
  19. package/dist/entities.d.ts +0 -40
  20. package/dist/entities.d.ts.map +0 -1
  21. package/dist/index.browser.d.ts +0 -39
  22. package/dist/index.browser.d.ts.map +0 -1
  23. package/dist/index.d.ts +0 -38
  24. package/dist/index.d.ts.map +0 -1
  25. package/dist/index.js +0 -2
  26. package/dist/index.node.d.ts +0 -37
  27. package/dist/index.node.d.ts.map +0 -1
  28. package/dist/logger.d.ts +0 -72
  29. package/dist/logger.d.ts.map +0 -1
  30. package/dist/memory.d.ts +0 -63
  31. package/dist/memory.d.ts.map +0 -1
  32. package/dist/node/index.d.ts +0 -2
  33. package/dist/node/index.node.js +0 -53429
  34. package/dist/node/index.node.js.map +0 -512
  35. package/dist/onboarding-state.d.ts +0 -209
  36. package/dist/plugin.d.ts +0 -55
  37. package/dist/plugin.d.ts.map +0 -1
  38. package/dist/prompts.d.ts +0 -7
  39. package/dist/prompts.d.ts.map +0 -1
  40. package/dist/request-context.d.ts +0 -142
  41. package/dist/request-context.d.ts.map +0 -1
  42. package/dist/request-context.node.d.ts +0 -36
  43. package/dist/request-context.node.d.ts.map +0 -1
  44. package/dist/roles.d.ts +0 -23
  45. package/dist/roles.d.ts.map +0 -1
  46. package/dist/runtime.d.ts +0 -366
  47. package/dist/runtime.d.ts.map +0 -1
  48. package/dist/schemas/character.d.ts +0 -151
  49. package/dist/schemas/character.d.ts.map +0 -1
  50. package/dist/search.d.ts +0 -316
  51. package/dist/search.d.ts.map +0 -1
  52. package/dist/secrets.d.ts +0 -11
  53. package/dist/secrets.d.ts.map +0 -1
  54. package/dist/services/default-message-service.d.ts +0 -69
  55. package/dist/services/default-message-service.d.ts.map +0 -1
  56. package/dist/services/message-service.d.ts +0 -171
  57. package/dist/services/message-service.d.ts.map +0 -1
  58. package/dist/services.d.ts +0 -56
  59. package/dist/services.d.ts.map +0 -1
  60. package/dist/sessions/index.d.ts +0 -10
  61. package/dist/sessions/paths.d.ts +0 -54
  62. package/dist/sessions/provider.d.ts +0 -73
  63. package/dist/sessions/session-key.d.ts +0 -133
  64. package/dist/sessions/store.d.ts +0 -75
  65. package/dist/sessions/types.d.ts +0 -195
  66. package/dist/settings.d.ts +0 -90
  67. package/dist/settings.d.ts.map +0 -1
  68. package/dist/streaming-context.browser.d.ts +0 -26
  69. package/dist/streaming-context.browser.d.ts.map +0 -1
  70. package/dist/streaming-context.d.ts +0 -95
  71. package/dist/streaming-context.d.ts.map +0 -1
  72. package/dist/streaming-context.node.d.ts +0 -15
  73. package/dist/streaming-context.node.d.ts.map +0 -1
  74. package/dist/types/agent.d.ts +0 -97
  75. package/dist/types/agent.d.ts.map +0 -1
  76. package/dist/types/components.d.ts +0 -155
  77. package/dist/types/components.d.ts.map +0 -1
  78. package/dist/types/database.d.ts +0 -414
  79. package/dist/types/database.d.ts.map +0 -1
  80. package/dist/types/elizaos.d.ts +0 -159
  81. package/dist/types/elizaos.d.ts.map +0 -1
  82. package/dist/types/environment.d.ts +0 -116
  83. package/dist/types/environment.d.ts.map +0 -1
  84. package/dist/types/events.d.ts +0 -203
  85. package/dist/types/events.d.ts.map +0 -1
  86. package/dist/types/index.d.ts +0 -20
  87. package/dist/types/index.d.ts.map +0 -1
  88. package/dist/types/knowledge.d.ts +0 -30
  89. package/dist/types/knowledge.d.ts.map +0 -1
  90. package/dist/types/memory.d.ts +0 -102
  91. package/dist/types/memory.d.ts.map +0 -1
  92. package/dist/types/messaging.d.ts +0 -137
  93. package/dist/types/messaging.d.ts.map +0 -1
  94. package/dist/types/model.d.ts +0 -513
  95. package/dist/types/model.d.ts.map +0 -1
  96. package/dist/types/plugin.d.ts +0 -91
  97. package/dist/types/plugin.d.ts.map +0 -1
  98. package/dist/types/primitives.d.ts +0 -96
  99. package/dist/types/primitives.d.ts.map +0 -1
  100. package/dist/types/runtime.d.ts +0 -140
  101. package/dist/types/runtime.d.ts.map +0 -1
  102. package/dist/types/service.d.ts +0 -150
  103. package/dist/types/service.d.ts.map +0 -1
  104. package/dist/types/settings.d.ts +0 -29
  105. package/dist/types/settings.d.ts.map +0 -1
  106. package/dist/types/state.d.ts +0 -56
  107. package/dist/types/state.d.ts.map +0 -1
  108. package/dist/types/streaming.d.ts +0 -71
  109. package/dist/types/streaming.d.ts.map +0 -1
  110. package/dist/types/task.d.ts +0 -67
  111. package/dist/types/task.d.ts.map +0 -1
  112. package/dist/types/tee.d.ts +0 -96
  113. package/dist/types/tee.d.ts.map +0 -1
  114. package/dist/types/testing.d.ts +0 -28
  115. package/dist/types/testing.d.ts.map +0 -1
  116. package/dist/utils/buffer.d.ts +0 -104
  117. package/dist/utils/buffer.d.ts.map +0 -1
  118. package/dist/utils/crypto-compat.d.ts +0 -183
  119. package/dist/utils/crypto-compat.d.ts.map +0 -1
  120. package/dist/utils/environment.d.ts +0 -50
  121. package/dist/utils/environment.d.ts.map +0 -1
  122. package/dist/utils/node.d.ts +0 -5
  123. package/dist/utils/node.d.ts.map +0 -1
  124. package/dist/utils/paths.d.ts +0 -92
  125. package/dist/utils/paths.d.ts.map +0 -1
  126. package/dist/utils/server-health.d.ts +0 -22
  127. package/dist/utils/server-health.d.ts.map +0 -1
  128. package/dist/utils/streaming.d.ts +0 -179
  129. package/dist/utils/streaming.d.ts.map +0 -1
  130. package/dist/utils/type-guards.d.ts +0 -23
  131. package/dist/utils/type-guards.d.ts.map +0 -1
  132. package/dist/utils.d.ts +0 -182
  133. package/dist/utils.d.ts.map +0 -1
package/README.md CHANGED
@@ -12,6 +12,7 @@ The `@elizaos/core` package provides a robust foundation for building AI agents
12
12
  - **Evaluators:** Process conversation data to extract insights, build long-term memory, and maintain contextual awareness.
13
13
  - **Plugin System:** Extensible architecture allowing for modular addition of functionalities.
14
14
  - **Entity and Memory Management:** Core support for tracking entities and their associated information.
15
+ - **Shared Config Helpers:** Common utilities for runtime-first setting resolution, typed coercion, and schema-based config validation.
15
16
 
16
17
  ## Installation
17
18
 
@@ -59,10 +60,17 @@ The following environment variables are used by `@elizaos/core`. Configure them
59
60
  - `LOG_JSON_FORMAT`: Output logs in JSON format (`true`/`false`).
60
61
  - `DEFAULT_LOG_LEVEL`: Default log level if not in debug mode.
61
62
  - `SECRET_SALT`: Secret salt for encryption purposes.
63
+ - `ALLOW_NO_DATABASE`: Allow running without a persistent database adapter. When `true`, `AgentRuntime.initialize()` will fall back to an in-memory adapter (useful for benchmarks/tests).
64
+ - `USE_MULTI_STEP`: Enable the iterative multi-step workflow (`true`/`false`). When enabled, the runtime may run multiple provider/action steps before producing a final response.
65
+ - `MAX_MULTISTEP_ITERATIONS`: Maximum number of iterations for multi-step mode (default: `6`).
62
66
  - `SENTRY_DSN`: Sentry DSN for error reporting.
63
67
  - `SENTRY_ENVIRONMENT`: Sentry deployment environment (e.g., 'production', 'staging').
64
68
  - `SENTRY_TRACES_SAMPLE_RATE`: Sentry performance tracing sample rate (0.0 - 1.0).
65
69
  - `SENTRY_SEND_DEFAULT_PII`: Send Personally Identifiable Information to Sentry (`true`/`false`).
70
+ - `LOG_FILE`: When set to `true`/`1` or a path, enables file logging: `output.log`, `prompts.log`, and `chat.log` (in cwd or at the given path). **Why:** Lets you inspect full prompts and chat flow without scraping console; ANSI is stripped so files stay grep-friendly.
71
+ - `BOOTSTRAP_KEEP_RESP`: When `true`, the message service does not discard a response when a newer message is being processed (avoids "stale reply" race). **Why:** Some deployments want to keep or display every response; this is the config equivalent of passing `keepExistingResponses: true` in options.
72
+ - `SHOULD_RESPOND_MODEL`: Which model size to use for the "should I respond?" decision (`small` or `large`). Defaults from runtime settings if not set in options.
73
+ - `DISABLE_MEMORY_CREATION` / `ALLOW_MEMORY_SOURCE_IDS`: Bootstrap-related; see plugin docs. Shown in the bootstrap banner when set.
66
74
 
67
75
  **Example `.env`:**
68
76
 
@@ -72,6 +80,9 @@ LOG_DIAGNOSTIC=true
72
80
  LOG_JSON_FORMAT=false
73
81
  DEFAULT_LOG_LEVEL=info
74
82
  SECRET_SALT=yourSecretSaltHere
83
+ ALLOW_NO_DATABASE=true
84
+ USE_MULTI_STEP=false
85
+ MAX_MULTISTEP_ITERATIONS=6
75
86
  SENTRY_DSN=yourSentryDsnHere
76
87
  SENTRY_ENVIRONMENT=development
77
88
  SENTRY_TRACES_SAMPLE_RATE=1.0
@@ -80,10 +91,198 @@ SENTRY_SEND_DEFAULT_PII=true
80
91
 
81
92
  **Note:** Add your `.env` file to `.gitignore` to protect sensitive information.
82
93
 
94
+ ### Design and rationale (WHY)
95
+
96
+ Key behaviors and APIs are documented with their **reasons** so future changes stay consistent with intent:
97
+
98
+ - **[docs/DESIGN.md](docs/DESIGN.md)** — Design decisions: message races, provider timeout, keepExistingResponses, JSON5, formatPosts fallbacks, HandlerCallback actionName, anxiety provider, file logging, and what we don’t do.
99
+ - **[CHANGELOG.md](CHANGELOG.md)** — Per-change notes with WHY for each addition or fix.
100
+ - **[ROADMAP.md](ROADMAP.md)** — Planned work and rationale (observability, robustness, API consistency, performance).
101
+
102
+ When adding or changing behavior, update these docs so the WHY stays accurate.
103
+
104
+ ### Shared config helpers (WHY)
105
+
106
+ `@elizaos/core` now exports a small config-loading helper layer for the repeated setup work that many plugins need:
107
+
108
+ - `resolveSettingRaw()`
109
+ - `collectSettings()`
110
+ - `getStringSetting()`
111
+ - `getBooleanSetting()`
112
+ - `getNumberSetting()`
113
+ - `getEnumSetting()`
114
+ - `getCsvSetting()`
115
+ - `formatConfigErrors()`
116
+ - `loadPluginConfig()`
117
+
118
+ These helpers live in `src/utils/plugin-config.ts` and are re-exported from `@elizaos/core`.
119
+
120
+ **Why this exists:** many plugins need the same boring plumbing:
121
+
122
+ - read a setting from `runtime.getSetting(key)`
123
+ - optionally fall back to `process.env`
124
+ - coerce the raw value into a useful type
125
+ - pass the collected object into a Zod schema
126
+ - report validation failures in one consistent format
127
+
128
+ Putting that plumbing in core reduces copy-paste drift without forcing all plugins into one config framework.
129
+
130
+ **What it intentionally does not do yet:**
131
+
132
+ - alias keys for one field
133
+ - character-settings merges
134
+ - plugin-specific derived values
135
+ - writing normalized values back into env/runtime
136
+
137
+ **Why those are excluded:** those behaviors vary too much by plugin, so lifting them into core too early would create a helper that is harder to reason about than the duplication it replaces.
138
+
139
+ **Example:**
140
+
141
+ ```typescript
142
+ import {
143
+ collectSettings,
144
+ loadPluginConfig,
145
+ type SettingSourceOptions,
146
+ } from "@elizaos/core";
147
+ import { z } from "zod";
148
+
149
+ const schema = z.object({
150
+ EXAMPLE_ENABLED: z.boolean().default(false),
151
+ EXAMPLE_TIMEOUT_MS: z.coerce.number().min(0).default(1000),
152
+ });
153
+
154
+ const sourceOptions: SettingSourceOptions = {
155
+ runtime,
156
+ envFallback: true,
157
+ };
158
+
159
+ const raw = collectSettings(
160
+ ["EXAMPLE_ENABLED", "EXAMPLE_TIMEOUT_MS"],
161
+ sourceOptions,
162
+ );
163
+
164
+ const config = loadPluginConfig({
165
+ schema,
166
+ raw,
167
+ scope: "Example",
168
+ });
169
+ ```
170
+
171
+ **Why the API is split into `collectSettings()` and `loadPluginConfig()`:** callers can still override or derive a few fields locally before validation, while the shared precedence and error formatting stay centralized.
172
+
173
+ ### Benchmark & Trajectory Tracing
174
+
175
+ Benchmarks and harnesses can attach metadata to inbound messages:
176
+
177
+ - `message.metadata.trajectoryStepId`: when present, provider access + model calls are captured for that step.
178
+ - `message.metadata.benchmarkContext`: when present, the `CONTEXT_BENCH` provider sets `state.values.benchmark_has_context=true`, and the message loop forces action-based execution (so the full Provider → Model → Action → Evaluator loop is exercised).
179
+
180
+ ### Model output contract (XML preferred, plain text tolerated)
181
+
182
+ The canonical message loop expects model outputs in the `<response>...</response>` XML format (with `<actions>`, `<providers>`, and `<text>` fields).
183
+
184
+ Some deterministic/offline backends may return **plain text** instead. In that case, the runtime will treat the raw output as a simple **`REPLY`** so the system remains usable even when strict XML formatting is unavailable.
185
+
186
+ ### Prompt cache hints
187
+
188
+ The core can pass **prompt segments** to model providers so they can use prompt-caching APIs when supported. Each segment has `content` (string) and `stable` (boolean). **Stable** means the content is the same across calls for the same schema/character (e.g. instructions, format, examples); **unstable** means it changes every call (e.g. state, validation codes).
189
+
190
+ **Why this exists:** Repeated calls (e.g. message handling, batched evaluators) often send the same instructions and format while only the context/state changes. Provider caching (Anthropic ephemeral cache, OpenAI/Gemini prefix cache) can reuse tokens for the stable prefix, reducing cost and latency. The core describes which parts are stable so providers can opt in without parsing the prompt.
191
+
192
+ - **Invariant:** When `promptSegments` is set on generation params, `prompt` MUST equal `promptSegments.map(s => s.content).join("")`. **Why:** Providers that ignore segments still get correct behavior by using `prompt`; those that use segments must send the same total text so model behavior is unchanged.
193
+ - **Providers:** Anthropic uses the Messages API with `cache_control: { type: "ephemeral" }` on stable blocks so the API can cache those blocks. OpenAI and Gemini use **prefix ordering**: when segments are present, the prompt sent to the API is built with stable segments first, then unstable. **Why:** OpenAI and Gemini cache by prefix (e.g. OpenAI ≥1024 tokens); putting stable content first maximizes cache hits.
194
+
195
+ **Pitfalls for operators:**
196
+
197
+ - OpenAI caching only applies when the prompt is ≥1024 tokens; very short prompts will not show cache savings.
198
+ - Small or low-parameter models may not support or benefit from caching; behavior is unchanged.
199
+ - Caching is a performance/cost optimization; correctness does not depend on it.
200
+
201
+ **Pitfalls for implementers:**
202
+
203
+ - Do not mutate segment objects; always create new `{ content, stable }` objects. **Why:** Params may be passed to multiple handlers or stored; mutation can cause cross-request bugs.
204
+ - Segment order must match the order in which the prompt string is built; add an assertion that `prompt === promptSegments.map(s => s.content).join("")`. **Why:** Wrong order breaks the invariant and can send the wrong prompt to the model.
205
+ - When using segments in the API (e.g. messages or reordered prompt), ensure the final text seen by the model equals the intended full prompt (e.g. `params.prompt` or the stable-first concatenation).
206
+ - Only mark content as `stable: true` if it is identical across calls for the same schema/character. **Why:** Content that includes per-call UUIDs or changing state will never cache; mislabeling it as stable wastes cache capacity and can confuse operators.
207
+
208
+ For more detail, implementer pitfalls, and rollback, see [docs/PROMPT_CACHE_HINTS.md](docs/PROMPT_CACHE_HINTS.md).
209
+
83
210
  ## Core Architecture
84
211
 
85
212
  `@elizaos/core` is built around a few key concepts that work together within the `AgentRuntime`.
86
213
 
214
+ ### Unified Prompt Batcher
215
+
216
+ `@elizaos/core` now includes a unified prompt batching subsystem on `runtime.promptBatcher`.
217
+
218
+ Why this exists:
219
+
220
+ - Evaluators, startup warmups, and autonomous reasoning were all paying separate LLM round trips for structurally similar work.
221
+ - Batching reduces cost, queue depth, and local GPU contention by turning many small prompt calls into fewer structured calls.
222
+ - The dispatcher keeps deployment flexibility: local inference can pack aggressively while frontier APIs can trade some density for latency.
223
+
224
+ What it does:
225
+
226
+ - `askOnce()` batches startup questions into a single post-init drain when possible. Returns a promise of the extracted **fields** (unwrapped). **Why:** callers get a thenable so they can `await` or `.then()` without a callback.
227
+ - `onDrain(id, opts)` registers a section that runs on the next drain for that affinity and returns a **promise that resolves with `{ fields, meta }`** (or `null` if the section ID was already registered). **Why:** evaluators can use linear `await` + `if (result) { ... }` instead of a large `onResult` callback; same batching benefits. You can still pass optional `onResult` for fire-and-forget or recurring use (e.g. logging).
228
+ - `think()` is used by **autonomy**: when `enableAutonomy` is true, the autonomy service registers one recurring section; a BATCHER_DRAIN task in the task system drives when that affinity drains (task system owns WHEN, batcher owns HOW). **Why:** one register for "what to ask" and the same orchestration path as evaluators and startup, with the same cache and packing benefits. Autonomy keeps using `onResult` because it is fire-and-forget per drain.
229
+ - `askNow()` supports blocking audits without creating a second subsystem. Returns a promise of the **fields** (unwrapped). **Why:** same thenable style as askOnce; fallback is required so the caller always gets an object.
230
+
231
+ Result shape and errors:
232
+
233
+ - Section promises (from `addSection` / `onDrain`) resolve with **`BatcherResult<T> | null`**: `{ fields: T, meta: DrainMeta }`. **Why:** callers get both the extracted data and drain metadata (e.g. `meta.fallbackUsed`, `meta.durationMs`) in one object; `null` means duplicate section ID so the caller can branch.
234
+ - When **onResult** throws or the batcher is **disposed**, the section promise **rejects** instead of resolving. **Why:** callers can `.catch()` or try/catch for real failures; fallback-used still resolves (with `meta.fallbackUsed: true`) so "soft" failure is not an exception.
235
+ - **Generic `onDrain<T>(...)`**: pass a type param so `result.fields` is typed (e.g. `onDrain<ReflectionFields>(...)`). **Why:** avoids casting at call sites; the runtime still returns `Record<string, unknown>` from the model—the generic is for developer convenience.
236
+
237
+ Important behavior:
238
+
239
+ - Sections are idempotent by ID, so developers can register them from handlers without tracking lifecycle manually.
240
+ - The promise returned by `onDrain` (or `addSection`) **resolves once**—on the first delivery for that registration. **Why:** per-drain sections run on every drain, but the thenable is for "give me the result of this registration"; subsequent drains do not resolve the same promise again. For recurring delivery (e.g. every drain), use the optional `onResult` callback.
241
+ - Context is declarative and composable: `providers`, `contextBuilder`, and `contextResolvers` can be mixed.
242
+ - Dispatching is affinity-aware, so unrelated prompt sections are not merged into the same call just because they arrived at the same time.
243
+
244
+ Relevant runtime knobs:
245
+
246
+ - `PROMPT_BATCH_SIZE`
247
+ - `PROMPT_MAX_DRAIN_INTERVAL_MS`
248
+ - `PROMPT_MAX_SECTIONS_PER_CALL`
249
+ - `PROMPT_PACKING_DENSITY`
250
+ - `PROMPT_MAX_TOKENS_PER_CALL`
251
+ - `PROMPT_MAX_PARALLEL_CALLS`
252
+ - `PROMPT_MODEL_SEPARATION`
253
+
254
+ For the deeper design rationale and rollout details, see `DESIGN.md`, `ROADMAP.md`, and `CHANGELOG.md` in this package.
255
+
256
+ ### Task system
257
+
258
+ The **task system** is the single place for *when* scheduled work runs. Only tasks with tag `queue` are polled by the scheduler (TaskService); other tasks (e.g. approval, follow-up) are stored and executed only when explicitly triggered (e.g. choice action, or `executeTaskById`).
259
+
260
+ **Why one scheduler:**
261
+
262
+ - Recurring work (e.g. batcher drains, future cron-like use) uses the same DB, same pause/resume, same visibility (`getTaskStatus`, `nextRunAt`, `lastError`). Retry and backoff (exponential backoff, auto-pause after `maxFailures`) live in one place so we avoid infinite retry storms.
263
+
264
+ **Why queue + repeat:**
265
+
266
+ - Tasks with `tags: ["queue"]` are fetched every tick. Non-repeat tasks run when `now >= dueAt` (or `metadata.scheduledAt`) then are deleted; repeat tasks use `updateInterval`/`baseInterval` and `metadata.updatedAt` as last-run time. **Why:** One-shot "run at time X" (e.g. follow-up) uses `dueAt`; interval-based scheduling covers batcher drains and recurring use.
267
+
268
+ **Cross-runtime scheduling (three modes):**
269
+
270
+ 1. **Local timer (default):** One `setInterval` per TaskService; each runtime fetches its own queue tasks every tick. **Why:** Zero config for single-process apps.
271
+ 2. **Per-daemon:** Host calls `startTaskScheduler(adapter)`; one shared timer runs, one batched `getTasks(agentIds)` per tick for all registered runtimes, then tasks are dispatched to each runtime’s `runTick(tasks)`. **Why:** Multi-agent daemons avoid N DB queries per second.
272
+ 3. **Serverless:** Construct runtime with `{ serverless: true }`; no timer. Host calls `taskService.runDueTasks()` from cron or on each request to run due queue tasks once. **Why:** No long-lived process; host controls when tasks run.
273
+
274
+ **Public API (TaskService):** `executeTaskById`, `pauseTask`, `resumeTask`, `getTaskStatus`, `markDirty`, `runDueTasks()` (serverless). **Why:** Operators and UIs can run, pause, resume, and inspect tasks without touching the DB directly.
275
+
276
+ See `docs/TASK_SCHEDULER.md` for full architecture, WHYs, and daemon/serverless usage. See `DESIGN.md` (§ Task system upgrades and batcher-on-tasks) for full rationale and consumer fit.
277
+
278
+ ### Autonomy
279
+
280
+ The autonomy service lets the agent "think" and act on a schedule without user messages. It uses the **prompt batcher** with the **task system** for scheduling: when `enableAutonomy` is true, a recurring section is registered with `think("autonomy", ...)`. A BATCHER_DRAIN task for the autonomy affinity determines when the section drains; results are delivered to `onResult`, which runs the same post-LLM steps as the message pipeline (actions, memory, evaluators) via an execution facade.
281
+
282
+ Why batcher-only:
283
+
284
+ - The batcher owns "what to ask"; the task system owns "when" (per-affinity BATCHER_DRAIN tasks). One scheduling surface and one packing path. Evaluators used after autonomy runs are the same as for user messages; as more evaluators move to the batcher, autonomy benefits automatically.
285
+
87
286
  ### AgentRuntime
88
287
 
89
288
  The `AgentRuntime` is the heart of the system. It manages the agent's lifecycle, loads plugins, orchestrates interactions, and provides a central point for actions, providers, and evaluators to operate. It's typically initialized with a set of plugins, including the `corePlugin` which provides foundational capabilities.
@@ -118,6 +317,12 @@ Evaluators analyze conversation data and other inputs to extract meaningful info
118
317
  - Reflect on past interactions to improve future responses.
119
318
  - Update the agent's knowledge base.
120
319
 
320
+ ### Database adapter
321
+
322
+ The runtime talks to persistence through the `IDatabaseAdapter` interface. Adapters (e.g. plugin-sql, plugin-localdb, InMemory) implement this contract so the same runtime code works with different backends.
323
+
324
+ **Why mutation methods return `Promise<boolean>`:** Methods such as `updateAgents`, `deleteAgents`, and `deleteParticipants` return a boolean so callers can tell success from failure. That supports error handling, retries, and UX (e.g. "Agent removed" vs "Failed to remove"). All adapters use this convention for consistency. See `packages/typescript/src/types/database.ts` for full JSDoc and design notes.
325
+
121
326
  ## Getting Started
122
327
 
123
328
  ### Initializing with `corePlugin`
@@ -125,7 +330,7 @@ Evaluators analyze conversation data and other inputs to extract meaningful info
125
330
  The `corePlugin` bundles essential actions, providers, and evaluators from `@elizaos/core`. To use it, add it to the `AgentRuntime` during initialization:
126
331
 
127
332
  ```typescript
128
- import { AgentRuntime, corePlugin } from '@elizaos/core';
333
+ import { AgentRuntime, corePlugin } from "@elizaos/core";
129
334
 
130
335
  const agentRuntime = new AgentRuntime({
131
336
  plugins: [
@@ -149,8 +354,8 @@ While `corePlugin` provides many actions, you might need to define custom action
149
354
  // (This is a simplified conceptual example)
150
355
 
151
356
  export const myCustomAction = {
152
- name: 'customGreet',
153
- description: 'Greets a user in a special way.',
357
+ name: "customGreet",
358
+ description: "Greets a user in a special way.",
154
359
  validate: async ({ context }) => {
155
360
  // Logic to determine if this action should run
156
361
  // e.g., return context.message.text.includes('special hello');
@@ -159,8 +364,8 @@ export const myCustomAction = {
159
364
  handler: async ({ runtime, context }) => {
160
365
  // Logic to execute the action
161
366
  // e.g., runtime.sendMessage(context.roomId, "A very special hello to you!");
162
- console.log('Custom Greet action executed!');
163
- return { success: true, message: 'Custom greeting sent.' };
367
+ console.log("Custom Greet action executed!");
368
+ return { success: true, message: "Custom greeting sent." };
164
369
  },
165
370
  };
166
371
 
@@ -173,21 +378,19 @@ For detailed instructions on creating and registering plugins and actions, refer
173
378
 
174
379
  ### Running Tests
175
380
 
176
- The `@elizaos/core` package uses **bun:test** for testing.
381
+ The `@elizaos/core` package uses **vitest** for testing.
177
382
 
178
383
  1. **Prerequisites**:
179
-
180
384
  - Ensure `bun` is installed (`npm install -g bun`).
181
385
  - Environment variables in `.env` (as described in Configuration) are generally **not required** for most core tests but might be for specific integration tests if any.
182
386
 
183
387
  2. **Setup**:
184
-
185
- - Navigate to the `packages/core` directory: `cd packages/core`
388
+ - Navigate to the `packages/typescript` directory: `cd packages/typescript`
186
389
  - Install dependencies: `bun install`
187
390
 
188
391
  3. **Execute Tests**:
189
392
  ```bash
190
- bun test
393
+ npx vitest
191
394
  ```
192
395
  Test results will be displayed in the terminal.
193
396
 
@@ -205,12 +408,10 @@ The following improvements and features are planned for `@elizaos/core`:
205
408
  ### Common Issues
206
409
 
207
410
  - **AgentRuntime not responding to triggers**:
208
-
209
411
  - **Cause**: Improperly defined action `validate` functions or handlers. Trigger conditions might not be met.
210
412
  - **Solution**: Verify `validate` functions correctly identify trigger conditions. Ensure `handler` functions execute as intended. Check console logs for errors during validation/handling.
211
413
 
212
414
  - **Provider data is outdated/incorrect**:
213
-
214
415
  - **Cause**: Issues with external data source integration or API failures.
215
416
  - **Solution**: Check API connections and ensure the provider's data fetching logic is accurate. Review network configurations if needed.
216
417
 
@@ -221,19 +422,15 @@ The following improvements and features are planned for `@elizaos/core`:
221
422
  ### Frequently Asked Questions
222
423
 
223
424
  - **Q: How do I define and use a new Action?**
224
-
225
425
  - **A**: Define an action object with `name`, `description`, `validate`, and `handler` functions. Integrate it into `AgentRuntime` usually by creating a plugin that registers the action. Ensure the action's name and description clearly align with its task for proper triggering.
226
426
 
227
427
  - **Q: My action is registered, but the agent is not calling it.**
228
-
229
428
  - **A**: Double-check the action's `name` and `description` for clarity and relevance to the triggering conditions. Verify that the `validate` function correctly returns `true` (or a truthy value indicating applicability) under the desired conditions. Inspect logs for any errors or warnings related to your action.
230
429
 
231
430
  - **Q: Can Providers access external API data?**
232
-
233
431
  - **A**: Yes, Providers are designed to interact with external systems, including fetching data from external APIs. This enables the agent to use real-time, dynamic context.
234
432
 
235
433
  - **Q: How do I extend the agent's evaluation capabilities?**
236
-
237
434
  - **A**: Implement custom evaluators and integrate them with `AgentRuntime` (typically via a plugin). These can be tailored to extract specific information, enhancing the agent's memory and contextual understanding.
238
435
 
239
436
  - **Q: How can I create a mock environment for testing?**
@@ -0,0 +1,22 @@
1
+ export {
2
+ withTestRuntime,
3
+ waitFor,
4
+ testDataGenerators,
5
+ retry,
6
+ requireInferenceProvider,
7
+ measureTime,
8
+ listOllamaModels,
9
+ isOllamaAvailable,
10
+ hasInferenceProvider,
11
+ generateTestId,
12
+ expectRejection,
13
+ detectInferenceProviders,
14
+ createTestMemory,
15
+ createTestCharacter,
16
+ createOllamaModelHandlers,
17
+ createIntegrationTestRuntime,
18
+ DEFAULT_TEST_CHARACTER
19
+ };
20
+
21
+ //# debugId=795BF75BD7F38A0564756E2164756E21
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "795BF75BD7F38A0564756E2164756E21",
8
+ "names": []
9
+ }
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@elizaos/core",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-alpha.51",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
8
+ "types": "dist/node/index.d.ts",
9
9
  "browser": "dist/browser/index.browser.js",
10
10
  "sideEffects": false,
11
11
  "exports": {
12
12
  "./package.json": "./package.json",
13
13
  ".": {
14
- "types": "./dist/index.d.ts",
14
+ "types": "./dist/node/index.d.ts",
15
15
  "browser": {
16
16
  "types": "./dist/browser/index.d.ts",
17
17
  "import": "./dist/browser/index.browser.js",
@@ -37,6 +37,10 @@
37
37
  "types": "./dist/browser/index.d.ts",
38
38
  "import": "./dist/browser/index.browser.js",
39
39
  "default": "./dist/browser/index.browser.js"
40
+ },
41
+ "./testing": {
42
+ "import": "./dist/testing/index.js",
43
+ "default": "./dist/testing/index.js"
40
44
  }
41
45
  },
42
46
  "files": [
@@ -44,46 +48,61 @@
44
48
  ],
45
49
  "scripts": {
46
50
  "build": "bun run build.ts",
47
- "build:node": "bun run build.ts --target node",
48
- "build:browser": "bun run build.ts --target browser",
49
- "dev": "bun run build.ts --watch",
50
- "clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json *.tsbuildinfo",
51
- "build:docs": "cd docs && bun run build",
52
- "test": "bun test --coverage",
53
- "test:coverage": "bun test --coverage",
54
- "test:watch": "bun test --watch",
55
- "format": "prettier --write ./src",
56
- "format:check": "prettier --check ./src",
57
- "lint": "eslint src/ && prettier --write ./src",
58
- "lint:check": "eslint src/"
51
+ "build:watch": "bun run build.ts --watch",
52
+ "dev": "bun run build:watch",
53
+ "clean": "rm -rf dist .turbo node_modules .turbo-tsconfig.json *.tsbuildinfo && find src -type f \\( -name '*.js' -o -name '*.d.ts' -o -name '*.d.ts.map' \\) -delete 2>/dev/null || true",
54
+ "perf:settings": "bun run scripts/perf-settings.ts",
55
+ "test": "vitest run --coverage",
56
+ "test:coverage": "vitest run --coverage",
57
+ "test:e2e": "npx playwright test",
58
+ "test:watch": "vitest",
59
+ "lint": "bunx @biomejs/biome check --write ./src",
60
+ "lint:check": "bunx @biomejs/biome check ./src",
61
+ "lint:fix": "bunx @biomejs/biome check --write ./src",
62
+ "typecheck": "tsc --noEmit -p ./tsconfig.json",
63
+ "format": "bunx @biomejs/biome format --write ./src",
64
+ "format:check": "bunx @biomejs/biome format ./src"
59
65
  },
60
- "author": "ElizaOS",
66
+ "author": "elizaOS",
61
67
  "license": "MIT",
62
68
  "devDependencies": {
63
- "@elizaos/config": "workspace:*",
64
- "@types/bun": "^1.3.3",
69
+ "@playwright/test": "^1.52.0",
70
+ "@types/bun": "^1.3.5",
65
71
  "@types/fast-redact": "^3.0.4",
66
- "@types/node": "^25.0.9",
72
+ "@types/markdown-it": "^14.1.2",
73
+ "@types/node": "^25.0.3",
67
74
  "@types/uuid": "^11.0.0",
68
- "prettier": "^3.7.4",
69
- "typescript": "^5.9.3"
75
+ "@vitest/coverage-v8": "^4.0.0",
76
+ "esbuild": "^0.25.0",
77
+ "sharp": "^0.33.0",
78
+ "typescript": "^5.9.3",
79
+ "vitest": "^4.0.0"
70
80
  },
71
81
  "dependencies": {
72
- "@langchain/core": "^1.0.0",
73
- "@langchain/textsplitters": "^1.0.0",
82
+ "@anthropic-ai/sdk": "^0.32.1",
83
+ "@bufbuild/protobuf": "^2.11.0",
84
+ "@langchain/core": "^1.1.12",
85
+ "@langchain/textsplitters": "^1.0.1",
74
86
  "adze": "^2.2.5",
75
87
  "crypto-browserify": "^3.12.0",
88
+ "dedent": "^1.7.1",
76
89
  "dotenv": "^17.2.3",
90
+ "drizzle-orm": "^0.45.1",
77
91
  "fast-redact": "^3.5.0",
92
+ "file-type": "^21.3.0",
78
93
  "glob": "^13.0.0",
79
94
  "handlebars": "^4.7.8",
80
- "pdfjs-dist": "^5.2.133",
95
+ "json5": "^2.2.3",
96
+ "markdown-it": "^14.1.0",
97
+ "pdfjs-dist": "^5.4.530",
98
+ "undici": "^7.0.0",
81
99
  "unique-names-generator": "^4.7.1",
82
100
  "uuid": "^13.0.0",
83
- "zod": "^4.3.5"
101
+ "yaml": "^2.7.0",
102
+ "zod": "^4.3.6"
84
103
  },
85
104
  "publishConfig": {
86
105
  "access": "public"
87
106
  },
88
- "gitHead": "255e37c0e4a76da0b776219db5ebb9dadf20e89f"
107
+ "gitHead": "e70e5cf2a1855f31db7de79a6fa68d11995baf97"
89
108
  }
package/dist/actions.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { Action } from './types';
2
- /**
3
- * Composes a set of example conversations based on provided actions and a specified count.
4
- * It randomly selects examples from the provided actions and formats them with generated names.
5
- *
6
- * @param actionsData - An array of `Action` objects from which to draw examples.
7
- * @param count - The number of examples to generate.
8
- * @returns A string containing formatted examples of conversations.
9
- */
10
- export declare const composeActionExamples: (actionsData: Action[], count: number) => string;
11
- /**
12
- * Formats the names of the provided actions into a comma-separated string.
13
- * @param actions - An array of `Action` objects from which to extract names.
14
- * @returns A comma-separated string of action names.
15
- */
16
- export declare function formatActionNames(actions: Action[]): string;
17
- /**
18
- * Formats the provided actions into a detailed string listing each action's name and description.
19
- * @param actions - An array of `Action` objects to format.
20
- * @returns A detailed string of actions, including names and descriptions.
21
- */
22
- export declare function formatActions(actions: Action[]): string;
@@ -1 +0,0 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,SAAS,CAAC;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAI,aAAa,MAAM,EAAE,EAAE,OAAO,MAAM,KAAG,MA+C5E,CAAC;AAmCF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAQ3D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAQvD"}