AI chat agent with conversation memory, migrated from Motia to iii-sdk 0.11.0.
GPT-4o-mini, SerpAPI web search, 20-message sliding-window memory, real-time stream updates.
POST /chat ──► chat::receive-message
│ (queue: process-ai-agent)
▼
chat::process-ai-agent
│ │
needs search? direct answer
│ │ (queue: agent-response-ready)
▼ │
chat::web-search ─────┘
│ (queue: agent-response-ready)
▼
chat::finalize-response
(updates stream + state)
GET /chat/:sessionId ──► chat::get-conversation
DELETE /chat/:sessionId ──► chat::clear-conversation
pnpm install
export OPENAI_API_KEY=sk-...
export SERPAPI_KEY=... # optional, for web search
# Start the iii engine, then:
bun run --watch src/main.ts# Send message
curl -X POST http://localhost:3000/chat \
-H "Content-Type: application/json" \
-d '{"sessionId": "test-123", "message": "Hello!"}'
# Get history
curl http://localhost:3000/chat/test-123
# Clear history
curl -X DELETE http://localhost:3000/chat/test-123bun run build
bun run --enable-source-maps dist/index-production.js| Motia | iii-sdk |
|---|---|
motia package |
iii-sdk@0.11.0 |
Auto-discovered .step.ts files |
Explicit registerFunction + registerTrigger in handler files, imported in src/main.ts |
emit({ topic, data }) |
iii.trigger({ function_id: 'iii::durable::publish', payload: { topic, data } }) |
streams.chatResponse.set(...) |
iii.trigger({ function_id: 'stream::set', payload: { stream_name, group_id, item_id, data } }) |
state.get/set/delete(...) |
iii.trigger({ function_id: 'state::get' | 'state::set' | 'state::delete', payload: { scope, key, value? } }) |
return { status: 200, body } |
return { status_code: 200, body } |
req.pathParams |
input.path_params |
req.body |
input.body |