doc/development/workhorse/ai_assisted_features_architecture.md
AI-assisted features in GitLab are powered by the GitLab Duo Workflow Service, an external service that runs and performs requests to large language models (LLMs) and orchestrates AI workflows. Workhorse acts as a bridge between the GitLab Rails application and the GitLab Duo Workflow Service, enabling secure and efficient communication while supporting various deployment scenarios (GitLab.com and GitLab Self-Managed).
graph TB
Client["Client
(Web Browser)"]
Workhorse["Workhorse
(Reverse Proxy)"]
Rails["GitLab Rails
(Application)"]
DWS["GitLab Duo Workflow Service
(AI Flows Orchestration)"]
MCP["MCP Servers
(Tools & Context)"]
Client -->|WebSocket| Workhorse
Workhorse -->|HTTP| Rails
Workhorse -->|gRPC| DWS
DWS -->|gRPC| Workhorse
Workhorse -->|HTTP| MCP
Rails -->|Configuration| Workhorse
style Workhorse fill:#f9f,stroke:#333,stroke-width:2px
style DWS fill:#bbf,stroke:#333,stroke-width:2px
style MCP fill:#bfb,stroke:#333,stroke-width:2px
For GitLab Self-Managed instances, the GitLab Duo Workflow Service cannot make direct HTTP requests to the GitLab instance due to network restrictions or security policies. Instead, Workhorse intercepts RunHTTPRequest actions and executes them on behalf of the GitLab Duo Workflow Service. The same approach is used for GitLab.com for consistency and to serve customers that have IP restrictions in place that would not accept direct requests from the GitLab Duo Workflow Service.
sequenceDiagram
participant User as User
(Browser)
participant WH as Workhorse
participant Rails as GitLab Rails
participant DWS as Duo Workflow
Service
participant MCP as MCP Server
User->>WH: 1. Establish WebSocket connection
WH->>Rails: 2. Pre-authorize request (/ws endpoint)
Rails->>WH: 3. Return DWS config & MCP servers
WH->>DWS: 4. Establish gRPC stream (ExecuteWorkflow)
User->>WH: 5. Send user input
WH->>DWS: 6. Forward ClientEvent
DWS->>WH: 7. Send Action (e.g., RunHTTPRequest)
WH->>Rails: 8. Execute action (API call)
Rails->>WH: 9. Return response
WH->>DWS: 10. Send ActionResponse
DWS->>WH: 11. Send Action (e.g., RunMCPTool)
WH->>MCP: 12. Call MCP tool
MCP->>WH: 13. Return tool result
WH->>DWS: 14. Send ActionResponse
DWS->>WH: 15. Send final response
WH->>User: 16. Forward response via WebSocket
In environments with IP restrictions or closed networks, Workhorse acts as a proxy for all external requests:
During server shutdown, Workhorse:
StopWorkflow requests to the GitLab Duo Workflow Service.