How codebykarthik/natwest-case-investigation-agent works
NatWest Case Investigation Agent is a staff-facing investigation assistant spanning an authenticated frontend, backend agent, MCP business-tool layer, and shared domain services. The main workflow is staff sign-in, chat submission, agent routing and investigation, governed business operations, and a grounded response. The README documents customer/case review, timelines, vulnerability signals, case updates, and evaluation hooks; unsampled implementations are represented only at supported directory paths. Relationships are limited to README statements and SOURCE INDEX references, so some internal workflow links remain unverified.
Main entry points: service.py Agent service · graph_builder.py Agent graph · app.py Staff UI · business_tools.py Case operations
Components 28
Staff experience
- Staff UI
natwest-frontend/src/natwest_frontend/app.py - Sign-in session
natwest-frontend/src/natwest_frontend/auth/session.py - OAuth client
natwest-frontend/src/natwest_frontend/auth/oauth.py - Assistant chat
natwest-frontend/src/natwest_frontend/ui/assistant.py - Backend client
natwest-frontend/src/natwest_frontend/client/api_client.py
API and agent
- Backend API
natwest-backend/src/natwest_backend/api/app.py - Chat endpoint
natwest-backend/src/natwest_backend/api/routes/chat.py - Agent service
natwest-backend/src/natwest_backend/agent/service.py - Agent graph
natwest-backend/src/natwest_backend/agent/graph_builder.py - Intent router
natwest-backend/src/natwest_backend/agent/nodes/router_node.py - Investigation flow
natwest-backend/src/natwest_backend/agent/skills/investigation_workflow.py - Input guardrails
natwest-backend/src/natwest_backend/agent/nodes/input_guardrail_node.py - Evaluation hooks
natwest-backend/src/natwest_backend/agent/evaluation - MCP client
natwest-backend/src/natwest_backend/agent/mcp_client/client_connection.py
Business tools
- MCP server
natwest-mcp/src/natwest_mcp/mcp/server.py - Tool registry
natwest-mcp/src/natwest_mcp/mcp/tools/tool_registry.py - Case operations
natwest-mcp/src/natwest_mcp/mcp/tools/business_tools.py
Shared domain
- Auth context
natwest-shared/src/natwest_shared/services/auth_context_service.py - Token verifier
natwest-shared/src/natwest_shared/auth/keycloak.py - Business services
natwest-shared/src/natwest_shared/services/business_service.py - Case and customer reads
natwest-shared/src/natwest_shared/db/repositories/business_read_repository.py - Case updates
natwest-shared/src/natwest_shared/db/repositories/business_write_repository.py - Staff user records
natwest-shared/src/natwest_shared/db/repositories/user_repository.py
Persistence and evaluation
- Domain database
natwest-shared/src/natwest_shared/db - Redis cache
natwest-backend/src/natwest_backend/agent/cache/redis_client.py
Other components
- Operations staff
- Keycloak
- LLM provider
Connections 29
- Operations staff → Staff UI: uses
README.md - Staff UI → Sign-in session: authenticates
natwest-frontend/src/natwest_frontend/app.py - Sign-in session → OAuth client: exchanges tokens
natwest-frontend/src/natwest_frontend/auth/session.py - OAuth client → Keycloak: requests tokens
natwest-frontend/src/natwest_frontend/auth/oauth.py - Staff UI → Assistant chat: renders
natwest-frontend/src/natwest_frontend/app.py - Assistant chat → Backend client: submits chat
natwest-frontend/src/natwest_frontend/ui/assistant.py - Backend client → Backend API: posts chat
natwest-frontend/src/natwest_frontend/client/api_client.py - Backend API → Chat endpoint: routes requests
natwest-backend/src/natwest_backend/api/app.py - Chat endpoint → Agent service: invokes agent
- Agent service → Agent graph: runs graph
natwest-backend/src/natwest_backend/agent/service.py - Agent graph → Intent router: dispatches
- Agent graph → Investigation flow: runs workflow
- Agent graph → Input guardrails: checks input
- Agent service → MCP client: connects tools
natwest-backend/src/natwest_backend/agent/service.py - MCP client → MCP server: calls MCP
natwest-backend/src/natwest_backend/agent/mcp_client/client_connection.py - MCP server → Tool registry: loads tools
natwest-mcp/src/natwest_mcp/mcp/server.py - Tool registry → Case operations: registers
natwest-mcp/src/natwest_mcp/mcp/tools/tool_registry.py - Case operations → Business services: invokes operations
natwest-mcp/src/natwest_mcp/mcp/tools/business_tools.py - Case operations → Auth context: gets authorization
- Auth context → Token verifier: verifies token
natwest-shared/src/natwest_shared/services/auth_context_service.py - Auth context → Staff user records: loads staff user
natwest-shared/src/natwest_shared/services/auth_context_service.py - Business services → Case and customer reads: queries domain
natwest-shared/src/natwest_shared/services/business_service.py - Business services → Case updates: updates domain
natwest-shared/src/natwest_shared/services/business_service.py - Staff user records → Domain database: reads users
natwest-shared/src/natwest_shared/db/repositories/user_repository.py - Case and customer reads → Domain database: reads cases
natwest-shared/src/natwest_shared/db/repositories/business_read_repository.py - Case updates → Domain database: writes cases
natwest-shared/src/natwest_shared/db/repositories/business_write_repository.py - Agent service → Redis cache: stores conversation
natwest-backend/src/natwest_backend/agent/service.py - Agent service → Evaluation hooks: records runs
- Agent service → LLM provider: generates response