bff-chat-service
Backend for Frontend service powering the dashboard chat interface. Implements a CrewAI multi-agent system running in Workers Containers for AI-powered conversational access to all platform data. The TypeScript worker handles HTTP routing, chat history, and asset storage while the Python container handles tool-calling and reasoning.
Worker name: crow-bff-chat-service
Domain (prod): internal.chat.crowai.dev
Domain (dev): dev.internal.chat.crowai.dev
Architecture
The chat service uses a two-tier architecture:
- TypeScript Worker -- Hono HTTP server managing chat sessions, message history (D1), and generated artifacts (R2)
- Python Container (
ChatCrewContainer) -- CrewAI multi-agent crew running in a Workers Container via Durable Objects. Handles reasoning, tool calls, and response generation using@cf/meta/llama-3.3-70b-instruct-fp8-fast
Container Details
- Class:
ChatCrewContainer - Image:
./Dockerfile - Max instances: 3
- Tools: The container calls back to the gateway API to fetch interactions, patterns, products, and organization context
Routes
Key routes (gateway path chat):
| Method | Path | Description |
|---|---|---|
| POST | /api/v1/chat/messages | Send a message and get AI response (streamed) |
| GET | /api/v1/chat/history | Get chat message history |
| GET | /api/v1/chat/sessions | List chat sessions |
| POST | /api/v1/chat/sessions | Create a new chat session |
| DELETE | /api/v1/chat/sessions/{id} | Delete a chat session |
Environment Variables
| Variable | Example |
|---|---|
| ENVIRONMENT | dev |
| API_GATEWAY_URL | https://dev.api.crowai.dev |
Bindings
| Binding | Type | Name |
|---|---|---|
| DB | D1 | crow-bff-chat-service-db |
| R2_BUCKET | R2 | crow-bff-chat-service-store (artifacts, assets) |
| AI | Workers AI | LLM inference |
| CHAT_CREW_CONTAINER | Durable Object | ChatCrewContainer (Workers Container) |
Dependencies
- Inbound: gateway (dashboard chat requests)
- Outbound: gateway API (interactions, patterns, products, organizations -- via container tool calls)
Key Behaviors
- Dashboard-specific: This is a BFF service, not a generic reusable service. It is designed specifically for the dashboard chat interface.
- Streamed responses: Chat responses are streamed back to the client as they are generated
- Artifact generation: The AI can produce artifacts (charts, summaries, tables) stored in R2
- Multi-agent: The CrewAI crew dispatches work to multiple specialized agents concurrently
Related: core-chat-service
There is also a core-chat-service that provides basic chat history storage via D1. It uses Workers AI (@cf/meta/llama-3.3-70b-instruct-fp8-fast) for simple response generation without the CrewAI multi-agent architecture. Its D1 database is crow-core-chat-service-db.