AI Service: Sequence Diagram¶
This diagram illustrates the complete, end-to-end workflow orchestrated by the ai_service, from receiving user input to returning a final response. It correctly shows that tool execution is handled via the Model Context Protocol.
sequenceDiagram
participant User
participant Frontend
participant API Gateway
participant AI Service
participant MCP Service
participant Internal APIs
User->>Frontend: 1. Sends query/command
Frontend->>API Gateway: 2. Forwards query to /api/ai (JSON)
API Gateway->>AI Service: 3. Forwards authenticated request (gRPC)
AI Service->>AI Service: 4. Constructs execution plan (via LangGraph)
alt Data-Modifying Operation
AI Service-->>API Gateway: 5a. Sends plan for approval (gRPC)
API Gateway-->>Frontend: 5b. Forwards plan (JSON)
Frontend-->>User: 5c. Displays plan and asks for confirmation
User->>Frontend: 6a. Clicks "Confirm"
Frontend->>API Gateway: 6b. Sends confirmation (JSON)
API Gateway->>AI Service: 6c. Forwards confirmation (gRPC)
Note over AI Service, MCP Service: 7. LangGraph invokes tool on MCP Server
AI Service->>MCP Service: 8. Invoke Tool via Model Context Protocol
MCP Service->>Internal APIs: 9. Tool logic calls relevant internal API
Internal APIs-->>MCP Service: 10. Returns result to tool logic
MCP Service-->>AI Service: 11. Returns result to LangGraph agent
else Read-Only Query
Note over AI Service, MCP Service: 7 (alt). LangGraph invokes tool on MCP Server
AI Service->>MCP Service: 8 (alt). Invoke Tool via Model Context Protocol
MCP Service->>Internal APIs: 9 (alt). Tool logic calls internal API
Internal APIs-->>MCP Service: 10 (alt). Returns data to tool logic
MCP Service-->>AI Service: 11 (alt). Returns data to LangGraph agent
end
AI Service->>AI Service: 12. Synthesizes final response (via LLM)
AI Service-->>API Gateway: 13a. Sends final response (gRPC)
API Gateway-->>Frontend: 13b. Forwards response (JSON)
Frontend-->>User: 13c. Displays final response in chat