How rithesh24/risk-intelligence-system works
1. This repo is a two-tier decision-intelligence system: a Python/FastAPI backend that runs the risk-analysis pipeline, and a separate Next.js frontend that renders both the business-facing dashboard and the developer monitor view.
2. The backend entrypoint is app/main.py, which wires the API layer in api/routes/* to the analysis and monitoring subsystems. The main externally visible capabilities are: run an analysis, inspect system state, and inspect agent execution/monitoring data.
3. The core runtime architecture is orchestrated in orchestrator/graph.py and orchestrator/nodes/*. This is the control plane for the multi-agent workflow: execute agents, aggregate results, detect conflicts, run a challenge phase, and break ties when agent outputs diverge.
4. The analysis pipeline is stateful. orchestrator/state/state_schema.py defines the shared analysis state passed between nodes and agents, so each step can add structured outputs without losing prior context. That state is the main boundary between orchestration and domain logic.
5. Domain intelligence is split across agent groups under agents/. The llm_agents infer business context and narrative meaning, the signal_agents evaluate specific risk dimensions like currency, commodities, demand, and policy, and agents/impact/impact_translation_agent.py converts upstream risk signals into business outcomes such as revenue, cost, and margin pressure.
6. The system is explicitly hybrid: LLM reasoning is combined with deterministic models. Deterministic support lives in services/risk_engine.py, risk/amplification_engine.py, and knowledge/knowledge_base.py, which provide score adjustment, fragility amplification, and curated mappings used when live data is incomplete.
7. External data enters through two main paths. First, ingestion/sources/rss_feed.py and ingestion/pipeline/event_builder.py turn RSS/news content into structured events in events/models/news_event.py and publish them via events/bus/event_bus.py. Second, data/market_data_service.py fetches live market inputs such as FX and commodity prices for the specific exposures identified by the analysis.
8. The analysis flow is therefore: business description in, business profile extraction, exposure mapping, market-data enrichment, specialized risk-agent execution, narrative/news interpretation, impact translation, then aggregation into a final score and explanation. The backend is designed to produce both the composite risk result and per-agent contributions for explainability.
9. Observability is a first-class subsystem. observability/agent_monitor.py tracks execution order, timestamps, confidence, errors, and agent-level scores, and the FastAPI routes expose that data for inspection. This monitoring layer is separate from the analysis logic so the pipeline can be debugged without changing risk behavior.
10. The frontend is a dedicated presentation boundary under frontend/. frontend/lib/api.ts connects the UI to the backend, while frontend/app/page.tsx serves the business dashboard and frontend/app/monitor/page.tsx serves the operator/debug dashboard. The components are mostly visualization and explanation surfaces rather than business logic.
11. The business dashboard emphasizes the final answer: risk score, confidence, driver explanations, agent contribution charts, and mitigation guidance. The monitor dashboard emphasizes the pipeline itself: execution flow, conflict detection, radar comparisons, low-confidence warnings, and per-agent output panels.
12. In deployment terms, this is not a monolith despite being in one repository. The backend is a Python service meant to run independently, and the frontend is a separate Next.js app. The main external integrations that materially affect architecture are the Groq LLM API for reasoning, Alpha Vantage-style market data for live signals, and RSS/news sources for event ingestion.
13. For an architecture diagram, the key boundaries are: user input/UI, API layer, orchestrator, agent groups, deterministic scoring/knowledge services, market/news ingestion, observability, and frontend visualization. The most important dataflow is one-way from raw business text and external signals into stateful agent execution, then out to explainable risk outputs and monitoring data.
Main entry points: agent_executor.py Agent exec · currency_agent.py Signal agents · state_schema.py Analysis state · main.py Main app
Components 28
Python backend
FastAPI service that runs analysis, orchestration, and monitoring
- Main app · Wires the backend API to analysis and monitoring subsystems
app/main.py - Analyze API · Starts a risk analysis request
api/routes/analyze.py - State API · Exposes current system and analysis state
api/routes/system_state.py - Monitor API · Serves agent execution and monitoring data
api/routes/agent_monitor.py - Agent monitor · Tracks execution order, timing, confidence, errors, and scores
observability/agent_monitor.py
Decision engine
Agent groups, deterministic scoring, and shared analysis state
- Workflow graph · Controls the multi-agent analysis flow
orchestrator/graph.py - Analysis state · Shared state passed between orchestration steps and agents
orchestrator/state/state_schema.py - Agent exec · Runs the active agents against the shared state
orchestrator/nodes/agent_executor.py - Conflict detect · Finds divergence between agent outputs
orchestrator/nodes/conflict_detector.py - Challenge phase · Re-runs reasoning to challenge uncertain conclusions
orchestrator/nodes/challenge_phase.py - Tie breaker · Resolves disagreement when agent outputs diverge
orchestrator/nodes/tie_breaker.py - Aggregator · Combines per-agent results into the final explanation and score
orchestrator/nodes/aggregator.py - LLM agents · Business-context and narrative reasoning agents
agents/llm_agents/business_profile_agent.py - Signal agents · Specialized risk agents for market and policy dimensions
agents/signal_agents/currency_agent.py - Impact translate · Converts upstream risks into business outcomes like revenue and margin pressure
agents/impact/impact_translation_agent.py - Risk engine · Performs score adjustment and hybrid risk calculation
services/risk_engine.py - Amplify model · Raises scores for fragile or high-sensitivity situations
risk/amplification_engine.py - Knowledge base · Provides fallback mappings and domain knowledge when live data is incomplete
knowledge/knowledge_base.py
Data inputs
News and market-data paths that feed the analysis pipeline
- RSS feed · Ingests external news content
ingestion/sources/rss_feed.py - Event builder · Turns news items into structured events
ingestion/pipeline/event_builder.py - News event · Structured event representation used by the pipeline
events/models/news_event.py - Event bus · Publishes and distributes news events
events/bus/event_bus.py - Market data · Fetches live FX and commodity inputs for exposed risks
data/market_data_service.py
Next.js frontend
Dashboard and operator UI that visualize results and pipeline behavior
- Frontend API · Connects the UI to backend endpoints
frontend/lib/api.ts - Dashboard · Business-facing risk summary and guidance view
frontend/app/page.tsx - Monitor page · Operator view for pipeline execution and debugging
frontend/app/monitor/page.tsx - Risk gauge · Shows final score and confidence
frontend/components/RiskGauge.tsx - Exec graph · Displays execution flow and conflict handling
frontend/components/monitor/ExecutionGraph.tsx
Connections 33
- Analyze API → Workflow graph: start analysis · Routes a user request into the workflow controller
- State API → Analysis state: read state · Returns the shared analysis state for inspection
- Monitor API → Agent monitor: read telemetry · Exposes monitoring records to the API layer
- Main app → Analyze API: mount · Registers analysis routes
- Main app → State API: mount · Registers system-state routes
- Main app → Monitor API: mount · Registers monitoring routes
- Workflow graph → Analysis state: share state · All steps operate on the same evolving analysis state
- Workflow graph → Agent exec: run · Drives the agent execution step
- Agent exec → LLM agents: invoke · Calls business-context and narrative agents
- Agent exec → Signal agents: invoke · Calls specialized risk agents
- Agent exec → Impact translate: invoke · Translates upstream risks into business impact
- LLM agents → Analysis state: write outputs · Adds extracted business profile and narrative context
- Signal agents → Market data: enrich · Uses live market inputs when available
- Signal agents → Knowledge base: fallbacks · Uses curated mappings when data is missing
- Signal agents → Amplify model: adjust · Applies fragility amplification to signals
- Impact translate → Analysis state: write impact · Stores business-outcome interpretation in shared state
- Agent exec → Conflict detect: check divergence · Compares agent outputs for disagreement
- Conflict detect → Challenge phase: challenge · Escalates uncertain or conflicting conclusions
- Challenge phase → Tie breaker: resolve · Breaks ties after the challenge phase
- Tie breaker → Aggregator: finalize · Hands resolved outputs to the aggregator
- Aggregator → Risk engine: score · Combines results into the composite risk score
- Risk engine → Analysis state: store result · Writes final score and explanation back to shared state
- Agent exec → Agent monitor: log run · Records execution order, timestamps, confidence, and errors
- RSS feed → Event builder: source items · Feeds raw news content into the builder
- Event builder → News event: shape · Produces structured news events
- Event builder → Event bus: publish · Publishes events for downstream consumers
- Event bus → Signal agents: news context · Supplies external news signals to analysis
- Frontend API → Analyze API: request analysis · Business dashboard submits analysis requests
- Frontend API → State API: fetch state · UI reads the current system state
- Frontend API → Monitor API: fetch telemetry · Monitor page reads agent telemetry
- Dashboard → Risk gauge: render · Shows the final risk summary
- Monitor page → Exec graph: render · Shows execution flow and pipeline behavior
- Monitor page → Agent monitor: inspect · Surfaces monitoring data in the operator UI