Express.js backend demonstrating the aidk Engine with:
- Agent execution via REST API
- Real-time channel updates via SSE
- In-memory persistence for demo purposes
- Node.js >= 24.0.0
- npm or yarn
npm installCopy the example environment file and fill in your values:
cp env.example .env| Variable | Required | Default | Description |
|---|---|---|---|
PORT |
No | 3000 |
Port the server listens on |
OPENAI_API_KEY |
Yes | - | Your OpenAI API key for GPT model access |
OPENAI_BASE_URL |
No | - | OpenAI Base URL |
OPENAI_MODEL |
No | gpt-4o-mini |
OpenAI model to use |
DEBUG |
No | false |
Enable verbose logging |
- Go to OpenAI Platform
- Sign up or log in
- Create a new API key
- Copy the key to your
.envfile
npm run devnpm run build
npm startGET /health
Returns { "status": "ok" } if the server is running.
POST /api/agents/:agentId/execute
POST /api/agents/:agentId/stream
Execute an agent with the given input. Available agents:
task-assistant- A todo list management assistant
Request Body:
{
"timeline": [
{
"message": {
"role": "user",
"content": [{ "type": "text", "text": "Create a task to buy groceries" }]
}
}
],
"sessionId": "optional-session-id"
}GET /api/channels/sse?sessionId=<id>&channels=<channel-names>
Subscribe to real-time channel updates via Server-Sent Events.
POST /api/channels/events
Publish an event to a channel.
GET /api/executions/thread/:threadId
GET /api/executions/:executionId
GET /api/executions/:executionId/graph
Query execution history and details.
┌─────────────────────────────────────────┐
│ Express Server │
│ └── Routes │
│ ├── /api/agents/* (execution) │
│ ├── /api/channels/* (SSE/events) │
│ └── /api/executions/* (history) │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ aidk Engine │
│ ├── ChannelService (with SSE Transport)│
│ ├── TaskAssistantAgent │
│ │ ├── OpenAI Model │
│ │ ├── TodoListTool │
│ │ └── CalculatorTool │
│ └── In-Memory Persistence │
└─────────────────────────────────────────┘
Make sure you've installed dependencies:
npm installVerify your OPENAI_API_KEY is set correctly in .env.
Change the PORT in your .env file or kill the process using that port:
lsof -ti:3000 | xargs kill -9