Pipeline and execution model for Simple Chat with LangGraph state management and MCP tool integration.
Simple Chat uses LangGraph and MCP integration for enhanced tool handling with support for Slack, GitHub, Google Drive, Gmail, and Google Calendar.

Processing Flow

1. Query Processing

  1. User sends query from frontend
  2. Python API forwards to Service Controller
  3. Controller selects Model Service based on chosen model
  4. LLM is initialized
  5. MultiServerClient fetches available tools from MCP server

2. Tool Management

  • Available Tools: Slack, GitHub, Google Drive, Google Calendar, Gmail
  • Tools are matched against current query
  • Unnecessary tools filtered out before LLM binding

3. StateGraph Construction

LangGraph StateGraph created with:
  • ToolNode - Tool execution
  • ChatbotNode - Standard LLM responses

4. Context Initialization

  • Chat Repository initialized with chat_id
  • Chat history retrieved and converted to memory
  • Context prepared for conversation flow

5. Execution Logic

StateGraph determines response path:
  • Tool usage detected → ToolNode execution
  • Standard query → ChatbotNode response
  • Combined context (query + history) passed to selected node

Tool Activation Rules

ToolActivation Condition
Web SearchGPT-4.1-search model only
Image GenerationGPT-based models only
MCP ToolsDynamically filtered per query

Response Processing

  1. Tool Invocation - Selected tool executed if needed
  2. LLM Integration - Tool may call LLM internally
  3. Streaming - Response streamed to frontend in real-time

Cost and Logging

MongoDB Handler logs:
  • Final response content
  • Token usage metrics
  • Tool activation records
  • Cost breakdown
Cost Calculation:
  • Input/output token lengths measured
  • Cost written via Cost Callback
  • Total breakdown stored in database

Architecture

Simple Chat Architecture Diagram

Simple Chat Architecture Flow

Web Search and Image Generation are model-gated. Verify model compatibility before tool invocation.

Troubleshooting

Tool Not Triggering

  • Check tool compatibility with selected model
  • Verify MultiServerClient pulled latest tools from MCP
  • Review filtering logic for tool exclusion
  • Validate LangGraph ChatbotNode → ToolNode transition

Streaming Issues

  • Confirm frontend WebSocket/SSE connections
  • Validate LangGraph state execution and transitions
  • Check for tool execution bottlenecks
  • Monitor MongoDB logs for latency indicators