Skip to content

Commit 7f3800b

Browse files
committed
fix(agents-chat-starter): spawn entities via /_electric/entities
Since the routing refactor in #4307, a bare PUT /:type/:id on the agents-server falls through to the durable-streams proxy. The proxy creates a raw stream and returns 201, so the starter's ok-check passes, but no entity is created and the agent never wakes. Spawn through the entity API instead, and fix the same snippet in AGENTS.md. Fixes #4687
1 parent 9e3af10 commit 7f3800b

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

examples/agents-chat-starter/AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Without the top-level `key`, the StreamDB won't materialize the event into the c
7676
Entities need an `initialMessage` when spawned — the runtime skips the handler if there's no fresh input on first wake:
7777

7878
```typescript
79-
await fetch(`${AGENTS_URL}/${type}/${id}`, {
79+
await fetch(`${AGENTS_URL}/_electric/entities/${type}/${id}`, {
8080
method: 'PUT',
8181
body: JSON.stringify({
8282
args: { chatroomId: roomId },
@@ -85,6 +85,8 @@ await fetch(`${AGENTS_URL}/${type}/${id}`, {
8585
})
8686
```
8787

88+
Spawn through `/_electric/entities/:type/:id`. A bare `PUT /:type/:id` falls through to the durable-streams proxy: it returns `201` and creates a raw stream, but no entity is registered and the agent never wakes.
89+
8890
### Preventing Agent Loops
8991

9092
When agents write to shared state, their own writes trigger their own wake. To prevent infinite loops, check if this agent already responded after the latest user message:

examples/agents-chat-starter/src/server/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ async function spawnAgent(room: Room, type: string): Promise<string> {
103103
const agentId = `${room.id}-${type}-${room.agents.length + 1}`
104104
const entityUrl = `/${type}/${agentId}`
105105

106-
const putRes = await fetch(`${AGENTS_URL}${entityUrl}`, {
106+
// Spawn via the entity API — a bare PUT /:type/:id falls through to the
107+
// durable-streams proxy, which creates a raw stream instead of an entity
108+
const putRes = await fetch(`${AGENTS_URL}/_electric/entities${entityUrl}`, {
107109
method: `PUT`,
108110
headers: { 'Content-Type': `application/json` },
109111
body: JSON.stringify({

0 commit comments

Comments
 (0)