dedalus-react useChat hook with a Python backend. This pattern enables real-time streaming, client-side tool execution, and model selection.
The
dedalus-react package was created by Colby Gilbert. See the npm package for full documentation.Architecture
Setup
Install Dependencies
Python Backend (FastAPI)
Create a streaming endpoint that wrapsDedalusRunner output as SSE:
React Frontend
Use theuseChat hook to manage messages and streaming:
Client-Side Tool Execution
TheuseChat hook supports executing tools on the client via onToolCall and addToolResult:
How It Works
- Model requests tool - Backend streams
tool_callsin the response - Hook invokes callback -
onToolCallfires for each tool call - Client executes - Your code runs the tool (API call, browser API, user prompt, etc.)
- Result sent back -
addToolResultadds atoolmessage to history - Auto-continue - If
sendAutomaticallyWhenreturns true, another request is made with the tool result
role: "tool" entries and continues the conversation.
Model Selection
Pass additional data via the transport body:Running the Example
Production Considerations
| Concern | Solution |
|---|---|
| CORS | Configure allowed origins for your domain |
| Authentication | Add JWT/session middleware, pass token in headers |
| Rate limiting | Implement per-user throttling |
| Error handling | Wrap stream in try/catch, surface errors to UI |