Sign in

Chat Service

Chat session management and message routing with WebSocket streaming support

chat
chatwebsocketstreamingfastapisessions

Updated 2026-11-03

Verified 2026-11-03

The Chat Service (cosmos-chat-v3) manages chat sessions and routes messages between the frontend and the backend agentic framework. It transforms frontend parameters, adds required fields for the ADK service, and provides both REST and WebSocket endpoints for real-time conversation streaming.

Architecture

  • Framework: FastAPI + Uvicorn
  • Streaming: WebSocket at /api/v1/converse_stream
  • Authentication: Manual JWT middleware requiring Authorization + X-Org-Id on every route except /health/. WebSocket clients can send the token in the Authorization header or as a Sec-WebSocket-Protocol value.
  • Token Forwarding: Forwards the user's JWT, organization, and project context to ADK so downstream permissions stay user- and project-scoped
  • Event Consumer: Separate chat-consumer container for Kafka events
  • Dependencies: The image installs Python dependencies with pip into /app/.venv; after a dependency change, rebuild with ./manage.sh dev build chat and restart
  • Telemetry: Cloud deployments start the webserver and consumer under opentelemetry-instrument, which reports to Azure Monitor through APPLICATIONINSIGHTS_CONNECTION_STRING

Components

ComponentDescription
REST API ServerHTTP endpoints for chat interactions
WebSocket ServerReal-time streaming for conversations
Event ConsumerKafka consumer for agent/app configuration events
Transformation ServiceConverts frontend params to ADK-compatible format

API Overview

MethodEndpointDescription
WS/api/v1/converse_streamWebSocket streaming conversation
POST/api/v1/converseSynchronous chat message
POST/api/v1/converse/whatsappWhatsApp channel message
POST/api/v1/trig-add-eventAdd an event to a session
POST/api/v1/trig-end-sessionEnd a session
POST/api/v1/upload-fileUpload a file for use in a conversation
GET/health/Health check

→ Full API reference: Chat API

Configuration

VariableDescription
COSMOS_SERVICE_CLIENT_IDOAuth service client ID; compose sets cosmos-chat-v3
COSMOS_SERVICE_CLIENT_SECRETOAuth client secret; sourced from COSMOS_CHAT_SERVICE_CLIENT_SECRET
ADK_HOST_URLADK service URL
CONFIG_HOST_URLConfigurator service URL
USER_SERVICE_URLUser Service URL
KAFKA_BOOTSTRAP_SERVERKafka broker address
KAFKA_TOPIC_CONSUMER, KAFKA_TOPIC_PRODUCERKafka topics the consumer reads and the service writes
REDIS_HOST, REDIS_PORTRedis connection
HYPERSCALERlocal, azure, or gcp
CORS_ALLOWED_ORIGINSAllowed browser origins
CHAT_V2_TEST_RELAY_ENABLEDEnables the agent test-session relay protocol (off by default)

Integration Points

ServiceIntegration
ADKForwards processed messages for agent execution
User ServiceJWT token validation
FrontendPrimary consumer via REST and WebSocket
KafkaConsumes configurator topic for app/agent updates

Troubleshooting

WebSocket connection drops

  • Check Chat service logs: ./manage.sh dev logs chat
  • Verify ADK service is healthy: curl http://localhost:8103/health
  • Verify the Chat service WebSocket port is reachable (COSMOS_CHAT_HOST_PORT, default 8108)
  • Check the close code: 4401 and 4403 are authentication and authorization failures; see Chat Conversations API