@electric-ax/agents 0.2.1 → 0.2.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 (49) hide show
  1. package/dist/entrypoint.js +5 -3
  2. package/dist/index.cjs +5 -3
  3. package/dist/index.js +5 -3
  4. package/docs/entities/agents/horton.md +89 -0
  5. package/docs/entities/agents/worker.md +102 -0
  6. package/docs/entities/patterns/blackboard.md +111 -0
  7. package/docs/entities/patterns/dispatcher.md +77 -0
  8. package/docs/entities/patterns/manager-worker.md +127 -0
  9. package/docs/entities/patterns/map-reduce.md +81 -0
  10. package/docs/entities/patterns/pipeline.md +101 -0
  11. package/docs/entities/patterns/reactive-observers.md +125 -0
  12. package/docs/examples/mega-draw.md +106 -0
  13. package/docs/examples/playground.md +46 -0
  14. package/docs/index.md +208 -0
  15. package/docs/quickstart.md +201 -0
  16. package/docs/reference/agent-config.md +82 -0
  17. package/docs/reference/agent-tool.md +58 -0
  18. package/docs/reference/built-in-collections.md +334 -0
  19. package/docs/reference/cli.md +238 -0
  20. package/docs/reference/entity-definition.md +57 -0
  21. package/docs/reference/entity-handle.md +63 -0
  22. package/docs/reference/entity-registry.md +73 -0
  23. package/docs/reference/handler-context.md +108 -0
  24. package/docs/reference/runtime-handler.md +136 -0
  25. package/docs/reference/shared-state-handle.md +74 -0
  26. package/docs/reference/state-collection-proxy.md +41 -0
  27. package/docs/reference/wake-event.md +132 -0
  28. package/docs/usage/app-setup.md +165 -0
  29. package/docs/usage/clients-and-react.md +191 -0
  30. package/docs/usage/configuring-the-agent.md +136 -0
  31. package/docs/usage/context-composition.md +204 -0
  32. package/docs/usage/defining-entities.md +181 -0
  33. package/docs/usage/defining-tools.md +229 -0
  34. package/docs/usage/embedded-builtins.md +180 -0
  35. package/docs/usage/managing-state.md +93 -0
  36. package/docs/usage/overview.md +284 -0
  37. package/docs/usage/programmatic-runtime-client.md +216 -0
  38. package/docs/usage/shared-state.md +169 -0
  39. package/docs/usage/spawning-and-coordinating.md +165 -0
  40. package/docs/usage/testing.md +76 -0
  41. package/docs/usage/waking-entities.md +148 -0
  42. package/docs/usage/writing-handlers.md +267 -0
  43. package/package.json +2 -1
  44. package/skills/quickstart/scaffold/package.json +16 -3
  45. package/skills/quickstart/scaffold/tsconfig.json +8 -3
  46. package/skills/quickstart/scaffold/vite.config.ts +21 -0
  47. package/skills/quickstart/scaffold-ui/index.html +12 -0
  48. package/skills/quickstart/scaffold-ui/main.tsx +235 -0
  49. package/skills/quickstart.md +244 -334
@@ -0,0 +1,238 @@
1
+ ---
2
+ title: CLI
3
+ titleTemplate: '... - Electric Agents'
4
+ description: >-
5
+ Command reference for the Electric Agents CLI: spawn, send, observe, inspect, list, and manage entities.
6
+ outline: [2, 3]
7
+ ---
8
+
9
+ # CLI reference
10
+
11
+ The Electric Agents CLI manages entity types and entities. Install it from `electric-ax`, then use the `electric agents` command. You can also run one-off commands with `npx electric-ax agents ...`.
12
+
13
+ ```bash
14
+ npm install -g electric-ax
15
+ ```
16
+
17
+ ## Environment variables
18
+
19
+ | Variable | Default | Purpose |
20
+ | --------------------------------- | ----------------------- | --------------------------------------------- |
21
+ | `ELECTRIC_AGENTS_URL` | `http://localhost:4437` | Server URL for entity commands and built-ins |
22
+ | `ELECTRIC_AGENTS_IDENTITY` | `user@hostname` | Sender identity for messages |
23
+ | `ELECTRIC_AGENTS_PORT` | `4437` | Port used by `start` / `quickstart` |
24
+ | `ELECTRIC_AGENTS_BUILTIN_PORT` | `4448` | Webhook port for `start-builtin` |
25
+ | `ELECTRIC_AGENTS_COMPOSE_PROJECT` | `electric-agents` | Docker Compose project name |
26
+ | `ANTHROPIC_API_KEY` | - | Required for `start-builtin` and `quickstart` |
27
+
28
+ ## Commands
29
+
30
+ ### <span class="cli-command"><code>types</code></span> {#types}
31
+
32
+ List registered entity types.
33
+
34
+ ```bash
35
+ electric agents types
36
+ ```
37
+
38
+ ### <span class="cli-command"><code>types inspect &lt;name&gt;</code></span> {#types-inspect-name}
39
+
40
+ Show entity type details. Outputs JSON.
41
+
42
+ ```bash
43
+ electric agents types inspect chat
44
+ ```
45
+
46
+ ### <span class="cli-command"><code>types delete &lt;name&gt;</code></span> {#types-delete-name}
47
+
48
+ Delete an entity type registration.
49
+
50
+ ```bash
51
+ electric agents types delete chat
52
+ ```
53
+
54
+ ### <span class="cli-command"><code>spawn &lt;url-path&gt; [--args &lt;json&gt;]</code></span> {#spawn-url-path-args-json}
55
+
56
+ Spawn an entity. URL path format: `/<type>/<id>`.
57
+
58
+ ```bash
59
+ electric agents spawn /chat/my-convo
60
+ electric agents spawn /chat/my-convo --args '{"topic": "AI safety"}'
61
+ ```
62
+
63
+ | Option | Description |
64
+ | --------------- | ------------------------------ |
65
+ | `--args <json>` | Spawn arguments as JSON object |
66
+
67
+ ### <span class="cli-command"><code>send &lt;url&gt; &lt;message...&gt; [--type &lt;msg-type&gt;] [--json]</code></span> {#send-url-message-type-json}
68
+
69
+ Send a message to an entity. By default, wraps the message string as `{ text: "..." }`. Use `--json` to send raw JSON.
70
+
71
+ ```bash
72
+ electric agents send /chat/my-convo 'Hello!'
73
+ electric agents send /chat/my-convo '{"custom": "payload"}' --json
74
+ electric agents send /chat/my-convo 'alert' --type warning
75
+ ```
76
+
77
+ | Option | Description |
78
+ | ------------------- | ---------------------------------------------------------------- |
79
+ | `--type <msg-type>` | Set the message type field |
80
+ | `--json` | Parse message argument as JSON instead of wrapping as `{ text }` |
81
+
82
+ ### <span class="cli-command"><code>observe &lt;url&gt; [--from &lt;offset&gt;]</code></span> {#observe-url-from-offset}
83
+
84
+ Stream entity events in real-time. Requires an interactive terminal.
85
+
86
+ ```bash
87
+ electric agents observe /chat/my-convo
88
+ electric agents observe /chat/my-convo --from 0
89
+ ```
90
+
91
+ | Option | Description |
92
+ | ----------------- | -------------------------------- |
93
+ | `--from <offset>` | Start streaming from this offset |
94
+
95
+ ### <span class="cli-command"><code>inspect &lt;url&gt;</code></span> {#inspect-url}
96
+
97
+ Show entity details. Outputs JSON.
98
+
99
+ ```bash
100
+ electric agents inspect /chat/my-convo
101
+ ```
102
+
103
+ ### <span class="cli-command"><code>ps [--type &lt;type&gt;] [--status &lt;status&gt;] [--parent &lt;url&gt;]</code></span> {#ps-type-status-parent}
104
+
105
+ List entities with optional filters.
106
+
107
+ ```bash
108
+ electric agents ps
109
+ electric agents ps --type chat --status running
110
+ electric agents ps --parent /manager/my-manager
111
+ ```
112
+
113
+ | Option | Description |
114
+ | ------------------- | --------------------------- |
115
+ | `--type <type>` | Filter by entity type |
116
+ | `--status <status>` | Filter by status |
117
+ | `--parent <url>` | Filter by parent entity URL |
118
+
119
+ Output shows `URL`, `STATUS`, `CREATED`, and `LAST ACTIVE` columns with human-readable relative timestamps. Results are sorted by most recently active first.
120
+
121
+ ### <span class="cli-command"><code>kill &lt;url&gt;</code></span> {#kill-url}
122
+
123
+ Delete an entity.
124
+
125
+ ```bash
126
+ electric agents kill /chat/my-convo
127
+ ```
128
+
129
+ ### <span class="cli-command"><code>start</code></span> {#start}
130
+
131
+ Start the local Electric Agents coordinator server, Postgres, Electric, and UI using Docker Compose.
132
+
133
+ ```bash
134
+ electric agents start
135
+ ```
136
+
137
+ ### <span class="cli-command"><code>start-builtin [--anthropic-api-key &lt;key&gt;]</code></span> {#start-builtin}
138
+
139
+ Start the built-in Horton runtime and register built-in agent types with the coordinator server.
140
+
141
+ ```bash
142
+ electric agents start-builtin --anthropic-api-key sk-ant-...
143
+ ```
144
+
145
+ | Option | Description |
146
+ | --------------------------- | ------------------------------------------------ |
147
+ | `--anthropic-api-key <key>` | Anthropic API key for the built-in Horton server |
148
+
149
+ ### <span class="cli-command"><code>quickstart [--anthropic-api-key &lt;key&gt;]</code></span> {#quickstart}
150
+
151
+ Start the coordinator server, print onboarding commands, and run the built-in agents runtime.
152
+
153
+ ```bash
154
+ electric agents quickstart --anthropic-api-key sk-ant-...
155
+ ```
156
+
157
+ | Option | Description |
158
+ | --------------------------- | ------------------------------------------------ |
159
+ | `--anthropic-api-key <key>` | Anthropic API key for the built-in Horton server |
160
+
161
+ ### <span class="cli-command"><code>stop [--remove-volumes]</code></span> {#stop}
162
+
163
+ Stop the local Electric Agents dev environment.
164
+
165
+ ```bash
166
+ electric agents stop
167
+ electric agents stop --remove-volumes
168
+ ```
169
+
170
+ | Option | Description |
171
+ | ------------------ | ------------------------------ |
172
+ | `--remove-volumes` | Remove Docker volumes as well. |
173
+
174
+ ### <span class="cli-command"><code>completion [action]</code></span> {#completion-action}
175
+
176
+ Set up shell completions. Without arguments, prints setup instructions.
177
+
178
+ ```bash
179
+ electric agents completion # Show setup instructions
180
+ electric agents completion install # Auto-install into your shell init file
181
+ ```
182
+
183
+ **Manual setup** (add to your shell init file):
184
+
185
+ ```bash
186
+ # Bash (~/.bashrc) or Zsh (~/.zshrc)
187
+ eval "$(electric --completion)"
188
+
189
+ # Fish (~/.config/fish/config.fish)
190
+ electric --completion-fish | source
191
+ ```
192
+
193
+ Completions provide tab-completion for commands, flags, entity types, and entity URLs.
194
+
195
+ ## Programmatic CLI
196
+
197
+ The `electric-ax` package also exports the Commander program and handler factory used by the binary. Use these APIs for tests, custom wrappers, or embedding the command tree in another tool.
198
+
199
+ ```ts
200
+ import {
201
+ createElectricCliHandlers,
202
+ createElectricProgram,
203
+ getElectricCliEnv,
204
+ run,
205
+ } from 'electric-ax'
206
+
207
+ const env = getElectricCliEnv({
208
+ ELECTRIC_AGENTS_URL: 'http://localhost:4437',
209
+ ELECTRIC_AGENTS_IDENTITY: 'docs@example.com',
210
+ })
211
+
212
+ const handlers = createElectricCliHandlers(env, 'electric agents')
213
+ const program = createElectricProgram({
214
+ env,
215
+ handlers,
216
+ commandName: 'electric',
217
+ commandPrefix: 'electric agents',
218
+ })
219
+
220
+ await program.parseAsync(['node', 'electric', 'agents', 'types'])
221
+ ```
222
+
223
+ | Export | Purpose |
224
+ | ---------------------------------- | --------------------------------------------------------------------- |
225
+ | `DEFAULT_ELECTRIC_AGENTS_URL` | Default server URL (`"http://localhost:4437"`). |
226
+ | `getElectricCliEnv(env?)` | Reads `ELECTRIC_AGENTS_URL` and `ELECTRIC_AGENTS_IDENTITY`. |
227
+ | `createElectricCliHandlers()` | Creates the default command handlers. |
228
+ | `createElectricProgram()` | Creates the Commander program. |
229
+ | `resolveCommandPrefix(argv, env?)` | Resolves help text examples for direct or package-manager invocation. |
230
+ | `run(argv?)` | Runs the CLI entrypoint. |
231
+
232
+ The installed binaries are `electric` and `electric-ax`. The package also includes `electric-dev` for development workflows.
233
+
234
+ <style scoped>
235
+ .cli-command code::before {
236
+ content: "electric agents ";
237
+ }
238
+ </style>
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: EntityDefinition
3
+ titleTemplate: '... - Electric Agents'
4
+ description: >-
5
+ Type reference for EntityDefinition: description, state, schemas, and handler function signature.
6
+ outline: [2, 3]
7
+ ---
8
+
9
+ # EntityDefinition
10
+
11
+ Defines an entity type's schema, state, and handler. Passed to `registry.define()` or `defineEntity()`.
12
+
13
+ **Source:** `@electric-ax/agents-runtime`
14
+
15
+ ```ts
16
+ interface EntityDefinition {
17
+ description?: string
18
+ state?: Record<string, CollectionDefinition>
19
+ actions?: (
20
+ collections: Record<string, unknown>
21
+ ) => Record<string, (...args: unknown[]) => void>
22
+ creationSchema?: StandardJSONSchemaV1
23
+ inboxSchemas?: Record<string, StandardJSONSchemaV1>
24
+ outputSchemas?: Record<string, StandardJSONSchemaV1>
25
+ handler(ctx: HandlerContext, wake: WakeEvent): void | Promise<void>
26
+ }
27
+ ```
28
+
29
+ ## Fields
30
+
31
+ | Field | Type | Required | Description |
32
+ | ---------------- | ---------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
33
+ | `description` | `string` | No | Human-readable description of the entity type. Used in type registration. |
34
+ | `state` | `Record<string, CollectionDefinition>` | No | Custom state collections exposed via `ctx.db.actions` (writes) and `ctx.db.collections` (reads). |
35
+ | `actions` | `(collections) => Record<string, (...args) => void>` | No | Factory for custom non-CRUD actions. Receives TanStack DB collections, returns named action functions exposed on `ctx.actions`. |
36
+ | `creationSchema` | `StandardJSONSchemaV1` | No | JSON Schema for spawn arguments validation. |
37
+ | `inboxSchemas` | `Record<string, StandardJSONSchemaV1>` | No | JSON Schemas for inbound message types, keyed by message type. |
38
+ | `outputSchemas` | `Record<string, StandardJSONSchemaV1>` | No | JSON Schemas for output event types. Defaults are provided by the runtime. |
39
+ | `handler` | `(ctx, wake) => void \| Promise<void>` | Yes | The function invoked on each wake. Receives [`HandlerContext`](./handler-context) and [`WakeEvent`](./wake-event). |
40
+
41
+ ## CollectionDefinition
42
+
43
+ Defines a custom state collection.
44
+
45
+ ```ts
46
+ interface CollectionDefinition {
47
+ schema?: StandardSchemaV1
48
+ type?: string
49
+ primaryKey?: string
50
+ }
51
+ ```
52
+
53
+ | Field | Type | Default | Description |
54
+ | ------------ | ------------------ | ---------------- | -------------------------------------------------- |
55
+ | `schema` | `StandardSchemaV1` | - | Zod or Standard Schema validator for the row type. |
56
+ | `type` | `string` | `"state:{name}"` | Event type string used in the durable stream. |
57
+ | `primaryKey` | `string` | `"key"` | Primary key field name on the row. |
@@ -0,0 +1,63 @@
1
+ ---
2
+ title: EntityHandle
3
+ titleTemplate: '... - Electric Agents'
4
+ description: >-
5
+ API reference for EntityHandle returned by spawn and observe: streams, status, text retrieval, and messaging.
6
+ outline: [2, 3]
7
+ ---
8
+
9
+ # EntityHandle
10
+
11
+ Handle returned by `ctx.spawn()` and `ctx.observe()`. Provides access to a child or observed entity's stream and status.
12
+
13
+ **Source:** `@electric-ax/agents-runtime`
14
+
15
+ ```ts
16
+ interface EntityHandle {
17
+ entityUrl: string
18
+ type?: string
19
+ db: EntityStreamDB
20
+ events: ChangeEvent[]
21
+ run: Promise<void>
22
+ text(): Promise<string[]>
23
+ send(msg: unknown): void
24
+ status(): ChildStatus | undefined
25
+ }
26
+ ```
27
+
28
+ ## Members
29
+
30
+ | Member | Type | Description |
31
+ | ----------- | -------------------------- | ----------------------------------------------------------------------------------- |
32
+ | `entityUrl` | `string` | URL path of the entity (e.g. `"/chat/my-child"`). |
33
+ | `type` | `string \| undefined` | Entity type name, if known. |
34
+ | `db` | `EntityStreamDB` | The entity's TanStack DB instance for querying its collections. |
35
+ | `events` | `ChangeEvent[]` | All change events received from this entity's stream. |
36
+ | `run` | `Promise<void>` | Promise that resolves when the entity's current run completes. Useful with `await`. |
37
+ | `text()` | `Promise<string[]>` | Returns all text outputs from the entity's stream. |
38
+ | `send(msg)` | `void` | Send a message to this entity. |
39
+ | `status()` | `ChildStatus \| undefined` | Current status of the entity, or `undefined` if unknown. |
40
+
41
+ ## ChildStatus
42
+
43
+ ```ts
44
+ type ChildStatus = ChildStatusEntry
45
+ ```
46
+
47
+ ```ts
48
+ interface ChildStatusEntry {
49
+ key: string
50
+ entity_url: string
51
+ entity_type: string
52
+ status: 'spawning' | 'running' | 'idle' | 'stopped'
53
+ }
54
+ ```
55
+
56
+ Status values:
57
+
58
+ | Status | Description |
59
+ | ---------- | ----------------------------------------------------------- |
60
+ | `spawning` | Entity creation is in progress. |
61
+ | `running` | Handler is currently executing. |
62
+ | `idle` | Handler has completed; entity is waiting for the next wake. |
63
+ | `stopped` | Entity has been stopped or deleted. |
@@ -0,0 +1,73 @@
1
+ ---
2
+ title: EntityRegistry
3
+ titleTemplate: '... - Electric Agents'
4
+ description: >-
5
+ API reference for EntityRegistry: define, get, list, and clear entity type registrations.
6
+ outline: [2, 3]
7
+ ---
8
+
9
+ # EntityRegistry
10
+
11
+ Manages entity type registrations. Create an isolated registry with `createEntityRegistry()`, or use the module-level convenience functions for a shared default registry.
12
+
13
+ **Source:** `@electric-ax/agents-runtime`
14
+
15
+ ```ts
16
+ class EntityRegistry {
17
+ define(name: string, definition: EntityDefinition): void
18
+ get(name: string): EntityTypeEntry | undefined
19
+ list(): EntityTypeEntry[]
20
+ clear(): void
21
+ }
22
+
23
+ function createEntityRegistry(): EntityRegistry
24
+ ```
25
+
26
+ ## Methods
27
+
28
+ | Method | Parameters | Return Type | Description |
29
+ | -------------------------- | ---------------------------------------------- | ------------------------------ | ---------------------------------------------------------------- |
30
+ | `define(name, definition)` | `name: string`, `definition: EntityDefinition` | `void` | Register an entity type. Throws if `name` is already registered. |
31
+ | `get(name)` | `name: string` | `EntityTypeEntry \| undefined` | Look up a registered type by name. |
32
+ | `list()` | - | `EntityTypeEntry[]` | Return all registered types. |
33
+ | `clear()` | - | `void` | Remove all registrations. |
34
+
35
+ ## EntityTypeEntry
36
+
37
+ ```ts
38
+ interface EntityTypeEntry {
39
+ name: string
40
+ definition: EntityDefinition
41
+ }
42
+ ```
43
+
44
+ | Field | Type | Description |
45
+ | ------------ | ----------------------------------------- | --------------------------- |
46
+ | `name` | `string` | The registered type name. |
47
+ | `definition` | [`EntityDefinition`](./entity-definition) | The full entity definition. |
48
+
49
+ ## Module-level functions
50
+
51
+ These operate on a shared default registry. Use them when you do not need isolated registries.
52
+
53
+ ```ts
54
+ function defineEntity(name: string, definition: EntityDefinition): void
55
+
56
+ function getEntityType(name: string): EntityTypeEntry | undefined
57
+
58
+ function listEntityTypes(): EntityTypeEntry[]
59
+
60
+ function clearRegistry(): void
61
+
62
+ function resolveDefine(
63
+ registry?: EntityRegistry
64
+ ): (name: string, definition: EntityDefinition) => void
65
+ ```
66
+
67
+ | Function | Description |
68
+ | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
69
+ | `defineEntity(name, definition)` | Register a type on the default registry. |
70
+ | `getEntityType(name)` | Look up a type on the default registry. |
71
+ | `listEntityTypes()` | List all types on the default registry. |
72
+ | `clearRegistry()` | Clear the default registry. |
73
+ | `resolveDefine(registry?)` | Returns `registry.define` if a registry is provided, otherwise `defineEntity`. Convenience for code that optionally accepts a registry. |
@@ -0,0 +1,108 @@
1
+ ---
2
+ title: HandlerContext
3
+ titleTemplate: '... - Electric Agents'
4
+ description: >-
5
+ API reference for HandlerContext: state, coordination, agent configuration, and execution control.
6
+ outline: [2, 3]
7
+ ---
8
+
9
+ # HandlerContext
10
+
11
+ The handler context is passed as the first argument to every entity handler. It provides access to state, coordination primitives, and agent configuration.
12
+
13
+ **Source:** `@electric-ax/agents-runtime`
14
+
15
+ ```ts
16
+ interface HandlerContext<TState extends StateProxy = StateProxy> {
17
+ firstWake: boolean
18
+ tags: Readonly<EntityTags>
19
+ entityUrl: string
20
+ entityType: string
21
+ args: Readonly<Record<string, unknown>>
22
+ db: EntityStreamDBWithActions
23
+ state: TState
24
+ events: Array<ChangeEvent>
25
+ actions: Record<string, (...args: unknown[]) => unknown>
26
+ electricTools: AgentTool[]
27
+ useAgent(config: AgentConfig): AgentHandle
28
+ useContext(config: UseContextConfig): void
29
+ timelineMessages(opts?: TimelineProjectionOpts): Array<TimestampedMessage>
30
+ insertContext(id: string, entry: ContextEntryInput): void
31
+ removeContext(id: string): void
32
+ getContext(id: string): ContextEntry | undefined
33
+ listContext(): Array<ContextEntry>
34
+ agent: AgentHandle
35
+ spawn(
36
+ type: string,
37
+ id: string,
38
+ args?: Record<string, unknown>,
39
+ opts?: {
40
+ initialMessage?: unknown
41
+ wake?: Wake
42
+ tags?: Record<string, string>
43
+ observe?: boolean
44
+ }
45
+ ): Promise<EntityHandle>
46
+ observe(
47
+ source: ObservationSource & { sourceType: 'entity' },
48
+ opts?: { wake?: Wake }
49
+ ): Promise<EntityHandle>
50
+ observe(
51
+ source: ObservationSource & { sourceType: 'db' },
52
+ opts?: { wake?: Wake }
53
+ ): Promise<SharedStateHandle & ObservationHandle>
54
+ observe(
55
+ source: ObservationSource,
56
+ opts?: { wake?: Wake }
57
+ ): Promise<ObservationHandle>
58
+ mkdb<T extends SharedStateSchemaMap>(
59
+ id: string,
60
+ schema: T
61
+ ): SharedStateHandle<T>
62
+ send(
63
+ entityUrl: string,
64
+ payload: unknown,
65
+ opts?: { type?: string; afterMs?: number }
66
+ ): void
67
+ setTag(key: string, value: string): Promise<void>
68
+ removeTag(key: string): Promise<void>
69
+ sleep(): void
70
+ }
71
+ ```
72
+
73
+ > **Tip:** Use the helper functions `entity()`, `cron()`, `entities()`, and `db()` from `@electric-ax/agents-runtime` to construct `ObservationSource` values for `observe()`.
74
+
75
+ ## Properties
76
+
77
+ | Property | Type | Description |
78
+ | --------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
79
+ | `firstWake` | `boolean` | `true` on the entity's first-ever handler invocation. |
80
+ | `tags` | `Readonly<EntityTags>` | Entity tags — key/value metadata associated with this entity. |
81
+ | `entityUrl` | `string` | URL path of this entity (e.g. `"/chat/my-convo"`). |
82
+ | `entityType` | `string` | Registered type name (e.g. `"chat"`). |
83
+ | `args` | `Readonly<Record<string, unknown>>` | Spawn arguments passed when the entity was created. |
84
+ | `db` | `EntityStreamDBWithActions` | The entity's TanStack DB instance with registered actions. |
85
+ | `state` | `TState` | Proxy object keyed by collection name. Each property is a [`StateCollectionProxy`](./state-collection-proxy). |
86
+ | `events` | `Array<ChangeEvent>` | Change events that triggered this wake. |
87
+ | `actions` | `Record<string, (...args: unknown[]) => unknown>` | Custom non-CRUD actions from the entity definition's `actions` factory. Auto-generated CRUD actions live on `ctx.db.actions` and `ctx.state`. |
88
+ | `electricTools` | `AgentTool[]` | Host-provided runtime-level tools to spread into agent config when needed. May be empty. |
89
+
90
+ ## Methods
91
+
92
+ | Method | Return Type | Description |
93
+ | --------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
94
+ | `useAgent(config)` | `AgentHandle` | Configure the LLM agent. Must be called before `agent.run()`. See [`AgentConfig`](./agent-config). |
95
+ | `useContext(config)` | `void` | Declare context sources with token budgets and cache tiers for the agent's context window. See [Context composition](/docs/agents/usage/context-composition). |
96
+ | `timelineMessages(opts?)` | `Array<TimestampedMessage>` | Project the entity timeline into an ordered array of LLM messages. Typically used as the `content` function of a volatile source. See [Context composition](/docs/agents/usage/context-composition#timelinemessages). |
97
+ | `insertContext(id, entry)` | `void` | Insert a durable context entry. Persists across wakes. Inserting with an existing `id` replaces the previous entry. See [Context entries](/docs/agents/usage/context-composition#context-entries). |
98
+ | `removeContext(id)` | `void` | Remove a context entry by id. |
99
+ | `getContext(id)` | `ContextEntry \| undefined` | Get a context entry by id, or `undefined` if not found. |
100
+ | `listContext()` | `Array<ContextEntry>` | List all context entries. |
101
+ | `agent.run(input?)` | `Promise<AgentRunResult>` | Run the configured agent loop. Optional `input` string is appended as a user message before the loop starts. |
102
+ | `spawn(type, id, args?, opts?)` | `Promise<EntityHandle>` | Spawn a child entity. `opts` accepts `tags`, `observe`, `initialMessage`, and `wake`. See [`EntityHandle`](./entity-handle). |
103
+ | `observe(source, opts?)` | `Promise<EntityHandle \| SharedStateHandle \| ObservationHandle>` | Observe a source. Return type depends on source type: `EntityHandle` for entities, `SharedStateHandle & ObservationHandle` for db, `ObservationHandle` otherwise. Use `entity()`, `cron()`, `entities()`, `db()` helpers to build sources. |
104
+ | `mkdb(id, schema)` | `SharedStateHandle<T>` | Create a new shared state stream. See [`SharedStateHandle`](./shared-state-handle). |
105
+ | `send(entityUrl, payload, opts?)` | `void` | Send a message to another entity. `opts` accepts `type` and `afterMs` (delay in milliseconds). |
106
+ | `setTag(key, value)` | `Promise<void>` | Set a tag on this entity. |
107
+ | `removeTag(key)` | `Promise<void>` | Remove a tag from this entity. |
108
+ | `sleep()` | `void` | End the handler without running an agent. The entity remains idle until the next wake. |