@electric-ax/agents 0.4.19 → 0.6.0

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 (40) hide show
  1. package/docs/entities/agents/horton.md +22 -17
  2. package/docs/entities/agents/worker.md +13 -6
  3. package/docs/entities/patterns/blackboard.md +1 -1
  4. package/docs/entities/patterns/dispatcher.md +1 -1
  5. package/docs/entities/patterns/manager-worker.md +10 -5
  6. package/docs/entities/patterns/map-reduce.md +1 -1
  7. package/docs/entities/patterns/pipeline.md +1 -1
  8. package/docs/entities/patterns/reactive-observers.md +1 -1
  9. package/docs/index.md +6 -4
  10. package/docs/quickstart.md +2 -2
  11. package/docs/reference/agent-config.md +13 -3
  12. package/docs/reference/built-in-collections.md +128 -9
  13. package/docs/reference/cli.md +34 -4
  14. package/docs/reference/entity-definition.md +39 -7
  15. package/docs/reference/entity-handle.md +19 -1
  16. package/docs/reference/handler-context.md +130 -5
  17. package/docs/reference/runtime-handler.md +42 -14
  18. package/docs/reference/wake-event.md +29 -1
  19. package/docs/usage/app-setup.md +38 -7
  20. package/docs/usage/attachments.md +129 -0
  21. package/docs/usage/clients-and-react.md +23 -2
  22. package/docs/usage/configuring-the-agent.md +15 -5
  23. package/docs/usage/context-composition.md +2 -1
  24. package/docs/usage/defining-entities.md +9 -5
  25. package/docs/usage/defining-tools.md +1 -1
  26. package/docs/usage/embedded-builtins.md +82 -31
  27. package/docs/usage/managing-state.md +5 -0
  28. package/docs/usage/mcp-servers.md +16 -8
  29. package/docs/usage/overview.md +39 -14
  30. package/docs/usage/permissions-and-principals.md +160 -0
  31. package/docs/usage/programmatic-runtime-client.md +158 -16
  32. package/docs/usage/sandboxing.md +162 -0
  33. package/docs/usage/signals.md +138 -0
  34. package/docs/usage/spawning-and-coordinating.md +30 -11
  35. package/docs/usage/testing.md +1 -1
  36. package/docs/usage/waking-entities.md +34 -6
  37. package/docs/usage/webhook-sources.md +171 -0
  38. package/docs/usage/writing-handlers.md +13 -55
  39. package/docs/walkthrough.md +13 -5
  40. package/package.json +3 -3
@@ -18,56 +18,7 @@ handler(ctx: HandlerContext, wake: WakeEvent) => void | Promise<void>
18
18
 
19
19
  ## HandlerContext
20
20
 
21
- ```ts
22
- interface HandlerContext<TState extends StateProxy = StateProxy> {
23
- firstWake: boolean
24
- tags: Readonly<EntityTags>
25
- entityUrl: string
26
- entityType: string
27
- args: Readonly<Record<string, unknown>>
28
- db: EntityStreamDBWithActions
29
- state: TState
30
- events: Array<ChangeEvent>
31
- actions: Record<string, (...args: unknown[]) => unknown>
32
- electricTools: AgentTool[]
33
- useAgent: (config: AgentConfig) => AgentHandle
34
- useContext: (config: UseContextConfig) => void
35
- timelineMessages: (opts?: TimelineProjectionOpts) => Array<TimestampedMessage>
36
- insertContext: (id: string, entry: ContextEntryInput) => void
37
- removeContext: (id: string) => void
38
- getContext: (id: string) => ContextEntry | undefined
39
- listContext: () => Array<ContextEntry>
40
- agent: AgentHandle
41
- spawn: (
42
- type: string,
43
- id: string,
44
- args?: Record<string, unknown>,
45
- opts?: {
46
- initialMessage?: unknown
47
- wake?: Wake
48
- tags?: Record<string, string>
49
- observe?: boolean
50
- }
51
- ) => Promise<EntityHandle>
52
- observe: (
53
- source: ObservationSource,
54
- opts?: { wake?: Wake }
55
- ) => Promise<EntityHandle | SharedStateHandle | ObservationHandle>
56
- mkdb: <T extends SharedStateSchemaMap>(
57
- id: string,
58
- schema: T
59
- ) => SharedStateHandle<T>
60
- send: (
61
- entityUrl: string,
62
- payload: unknown,
63
- opts?: { type?: string; afterMs?: number }
64
- ) => void
65
- recordRun: () => RunHandle
66
- setTag: (key: string, value: string) => Promise<void>
67
- removeTag: (key: string) => Promise<void>
68
- sleep: () => void
69
- }
70
- ```
21
+ `HandlerContext` includes identity, state, agent configuration, context composition, coordination, signals, sandboxing, attachments, goals, and lifecycle helpers. The table below summarizes the most common members; see the [HandlerContext reference](../reference/handler-context) for the full interface.
71
22
 
72
23
  ### Property reference
73
24
 
@@ -97,7 +48,7 @@ interface HandlerContext<TState extends StateProxy = StateProxy> {
97
48
  | `send` | Sends a message to another entity's inbox. Supports delayed delivery via `afterMs`. |
98
49
  | `recordRun` | Records non-LLM work in the built-in `runs` collection so `runFinished` observers are woken. |
99
50
  | `setTag` | Sets a tag on this entity. |
100
- | `removeTag` | Removes a tag from this entity. |
51
+ | `deleteTag` | Deletes a tag from this entity. |
101
52
  | `sleep` | Returns the entity to idle without re-waking. |
102
53
 
103
54
  ## WakeEvent
@@ -146,7 +97,7 @@ registry.define("assistant", {
146
97
 
147
98
  ctx.useAgent({
148
99
  systemPrompt: "You are a helpful assistant.",
149
- model: "claude-sonnet-4-5-20250929",
100
+ model: "claude-sonnet-4-6",
150
101
  tools: [...ctx.electricTools],
151
102
  })
152
103
  await ctx.agent.run()
@@ -162,11 +113,18 @@ Passed to `ctx.useAgent()`:
162
113
  interface AgentConfig {
163
114
  systemPrompt: string
164
115
  model: string | Model<any>
165
- provider?: KnownProvider
116
+ provider?: Provider
166
117
  tools: AgentTool[]
167
118
  streamFn?: StreamFn
168
119
  getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined
169
120
  onPayload?: SimpleStreamOptions["onPayload"]
121
+ onStepEnd?: (stats: {
122
+ input: number
123
+ uncachedInput: number
124
+ output: number
125
+ }) => void
126
+ modelTimeoutMs?: number
127
+ modelMaxRetries?: number
170
128
  testResponses?: string[] | TestResponseFn
171
129
  }
172
130
  ```
@@ -242,7 +200,7 @@ async handler(ctx) {
242
200
  const { systemPrompt } = ctx.args as { systemPrompt: string }
243
201
  ctx.useAgent({
244
202
  systemPrompt,
245
- model: 'claude-sonnet-4-5-20250929',
203
+ model: 'claude-sonnet-4-6',
246
204
  tools: [...ctx.electricTools],
247
205
  })
248
206
  await ctx.agent.run()
@@ -274,7 +232,7 @@ async handler(ctx) {
274
232
 
275
233
  ctx.useAgent({
276
234
  systemPrompt: 'You are an assistant with lookup capabilities.',
277
- model: 'claude-sonnet-4-5-20250929',
235
+ model: 'claude-sonnet-4-6',
278
236
  tools: [...ctx.electricTools, myTool],
279
237
  })
280
238
  await ctx.agent.run()
@@ -422,11 +422,15 @@ registry.define("manager", {
422
422
  description: "A manager agent that delegates work to assistants",
423
423
  async handler(ctx, wake) {
424
424
  if (wake.type === 'inbox') {
425
+ const message =
426
+ typeof wake.payload === "string"
427
+ ? wake.payload
428
+ : (wake.payload as { text?: string })?.text ?? wake.payload
425
429
  await ctx.spawn(
426
430
  'assistant',
427
431
  genId(),
428
432
  { systemPrompt: `Reverse the user message.` },
429
- { initialMessage: wake.payload.text, wake: { on: 'runFinished', includeResponse: true } }
433
+ { initialMessage: message, wake: { on: 'runFinished', includeResponse: true } }
430
434
  )
431
435
  }
432
436
 
@@ -445,16 +449,20 @@ This is very similar to our `assistant` type but, as you can see, adds this impe
445
449
 
446
450
  ```ts
447
451
  if (wake.type === 'inbox') {
452
+ const message =
453
+ typeof wake.payload === "string"
454
+ ? wake.payload
455
+ : (wake.payload as { text?: string })?.text ?? wake.payload
448
456
  await ctx.spawn(
449
457
  'assistant',
450
458
  genId(),
451
459
  { systemPrompt: `Reverse the user message.` },
452
- { initialMessage: wake.payload.text, wake: { on: 'runFinished', includeResponse: true } }
460
+ { initialMessage: message, wake: { on: 'runFinished', includeResponse: true } }
453
461
  )
454
462
  }
455
463
  ```
456
464
 
457
- What this does is say "if the notification you're responding to comes from the inbox stream", which means it's a user message, then spawn a sub-agent, specifically an `assistant` with a "Reverse the user message" systemPrompt, passing through the user message from `wake.payload.text`.
465
+ What this does is say "if the notification you're responding to comes from the inbox stream", which means it's a user message, then spawn a sub-agent, specifically an `assistant` with a "Reverse the user message" systemPrompt, passing through the user message from `wake.payload`.
458
466
 
459
467
  Now if you go back to the web UI on [https://localhost:4438](https://localhost:4438) you can now also create `manager` agents:
460
468
 
@@ -828,7 +836,7 @@ const rebut = (arg: string) =>
828
836
 
829
837
  ### Debate collection
830
838
 
831
- Now let's add the `debate` [collection](https://tanstack.com/db/latest/docs/overview#defining-collections) to the entity definition's [`state`](/docs/agents/usage/shared-state). This allows us to track the progress and status of a debate in the [durable state layer](/streams/).
839
+ Now let's add the `debate` [collection](https://tanstack.com/db/latest/docs/overview#defining-collections) to the entity definition's [`state`](/docs/agents/usage/managing-state). This allows us to track the progress and status of a debate in the [durable state layer](/streams/).
832
840
 
833
841
  Pull in two more imports from `@electric-ax/agents-runtime`:
834
842
 
@@ -1095,7 +1103,7 @@ registry.define(`manager`, {
1095
1103
  // ...,
1096
1104
  async handler(ctx, wake) {
1097
1105
  // When receiving wake notifications ...
1098
- if ((wake.type = `wake`)) {
1106
+ if (wake.type === `wake`) {
1099
1107
  const finishedChild = wake.payload?.finished_child
1100
1108
 
1101
1109
  // ... from a judge sub-agent ...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@electric-ax/agents",
3
- "version": "0.4.19",
3
+ "version": "0.6.0",
4
4
  "description": "Built-in Electric Agents runtimes such as Horton and worker",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,8 +49,8 @@
49
49
  "sqlite-vec": "^0.1.9",
50
50
  "undici": "^7.24.7",
51
51
  "zod": "^4.3.6",
52
- "@electric-ax/agents-runtime": "0.4.1",
53
- "@electric-ax/agents-mcp": "0.2.3"
52
+ "@electric-ax/agents-mcp": "0.6.0",
53
+ "@electric-ax/agents-runtime": "0.6.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/better-sqlite3": "^7.6.13",