Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/agents-chat-starter/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Without the top-level `key`, the StreamDB won't materialize the event into the c
Entities need an `initialMessage` when spawned — the runtime skips the handler if there's no fresh input on first wake:

```typescript
await fetch(`${AGENTS_URL}/${type}/${id}`, {
await fetch(`${AGENTS_URL}/_electric/entities/${type}/${id}`, {
method: 'PUT',
body: JSON.stringify({
args: { chatroomId: roomId },
Expand All @@ -85,6 +85,8 @@ await fetch(`${AGENTS_URL}/${type}/${id}`, {
})
```

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.

### Preventing Agent Loops

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:
Expand Down
4 changes: 3 additions & 1 deletion examples/agents-chat-starter/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ async function spawnAgent(room: Room, type: string): Promise<string> {
const agentId = `${room.id}-${type}-${room.agents.length + 1}`
const entityUrl = `/${type}/${agentId}`

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