# rupalhpatel9/biosimilar-switch-agent architecture

> Architecture diagram of the GitHub repository rupalhpatel9/biosimilar-switch-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rupalhpatel9/biosimilar-switch-agent
- Repository: https://github.com/rupalhpatel9/biosimilar-switch-agent

## Overview

SwitchDossier researches a proposed generic or biosimilar switch and produces a cited draft dossier for pharmacist review. The principal workflow is a question through the web/API, orchestrated research, evidence retrieval and extraction, verification, code-based scoring and synthesis, then review and sign-off. The README documents the agent handoffs and capabilities; source excerpts and the index corroborate selected internal calls. Some subsystem details are documented but unsampled, so those links are cited to the README rather than presented as inspected implementation.

Main entry points: [`switchagent/orchestrator/agent.py`](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/orchestrator/agent.py) (Orchestrator), [`switchagent/server.py`](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/server.py) (Web and API), [`switchagent/synthesizer/synth_pipeline.py`](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/synthesizer/synth_pipeline.py) (Dossier synthesizer), [`switchagent/extract/pipeline.py`](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/extract/pipeline.py) (Study extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_research["Research workflow"]
  node_web["Web and API<br/>[server.py]"]
  node_orchestrator["Orchestrator<br/>[agent.py]"]
  node_session["Run session<br/>[session.py]"]
  node_resolver["Drug resolver<br/>[resolver.py]"]
end

subgraph group_evidence["Evidence pipeline"]
  node_retrieval["Hybrid retrieval<br/>[search.py]"]
  node_embedding["Embedding and reranking<br/>[embed.py]"]
  node_ingestion["Evidence ingestion<br/>[ingest.py]"]
  node_sources["Evidence sources"]
  node_extract["Study extraction<br/>[pipeline.py]"]
  node_extractor["Structured extractor<br/>[extractor.py]"]
end

subgraph group_decision["Decision support"]
  node_screener["Patient-fit screener<br/>[screen.py]"]
  node_calculator["Cost and timing<br/>[savings.py]"]
  node_state_rules["State substitution rules<br/>[state_rules.py]"]
  node_synth["Dossier synthesizer<br/>[synth_pipeline.py]"]
  node_strategy["Strategy tree<br/>[beam.py]"]
  node_writer["Dossier writer<br/>[writer.py]"]
end

subgraph group_trust["Review and trust"]
  node_verifier["Claim verifier<br/>[judge.py]"]
  node_verification_rules["Verification checks<br/>[checks.py]"]
  node_guardrails["Guardrails and sign-off"]
end

subgraph group_state["Persistence"]
  node_memory[("Dossier history<br/>[history.py]")]
  node_database[("Postgres evidence store<br/>[db.py]")]
  node_mcp["Read-only MCP access<br/>[mcp_server.py]"]
end

node_pharmacist(("Pharmacist"))

node_pharmacist -->|"asks question"| node_web
node_web -->|"starts research"| node_orchestrator
node_orchestrator -->|"resolves drug"| node_resolver
node_orchestrator -->|"searches evidence"| node_retrieval
node_orchestrator -->|"requests extraction"| node_extract
node_orchestrator -->|"computes scenarios"| node_calculator
node_orchestrator -->|"checks rules"| node_state_rules
node_web -->|"manages run"| node_session
node_retrieval -->|"reranks results"| node_embedding
node_ingestion -->|"loads evidence"| node_sources
node_extract -->|"searches studies"| node_retrieval
node_extract -->|"extracts fields"| node_extractor
node_extract -->|"verifies claims"| node_verifier
node_verifier -->|"checks claims"| node_verification_rules
node_synth -->|"builds strategy"| node_strategy
node_synth -->|"writes dossier"| node_writer
node_synth -->|"screens patient fit"| node_screener
node_synth -->|"uses code figures"| node_calculator
node_web -->|"applies safeguards"| node_guardrails
node_pharmacist -->|"reviews and signs"| node_web
node_session -->|"stores run state"| node_database
node_memory -->|"reads history"| node_database
node_mcp -->|"exposes dossiers"| node_memory
node_retrieval -->|"queries evidence"| node_database

click node_web "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/server.py"
click node_orchestrator "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/orchestrator/agent.py"
click node_session "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/orchestrator/session.py"
click node_resolver "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/resolver.py"
click node_retrieval "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/search.py"
click node_embedding "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/embed.py"
click node_ingestion "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/ingest.py"
click node_sources "https://github.com/rupalhpatel9/biosimilar-switch-agent/tree/main/switchagent/sources"
click node_extract "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/extract/pipeline.py"
click node_extractor "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/extract/extractor.py"
click node_verifier "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/verify/judge.py"
click node_verification_rules "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/verify/checks.py"
click node_screener "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/screener/screen.py"
click node_calculator "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/calculator/savings.py"
click node_state_rules "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/calculator/state_rules.py"
click node_synth "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/synthesizer/synth_pipeline.py"
click node_strategy "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/synthesizer/beam.py"
click node_writer "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/synthesizer/writer.py"
click node_guardrails "https://github.com/rupalhpatel9/biosimilar-switch-agent/tree/main/switchagent/guardrails"
click node_memory "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/memory/history.py"
click node_database "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/db.py"
click node_mcp "https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/memory/mcp_server.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web,node_orchestrator,node_session,node_resolver toneBlue
class node_retrieval,node_embedding,node_ingestion,node_sources,node_extract,node_extractor toneAmber
class node_screener,node_calculator,node_state_rules,node_synth,node_strategy,node_writer toneMint
class node_verifier,node_verification_rules,node_guardrails toneRose
class node_memory,node_database,node_mcp,node_pharmacist toneIndigo
```

## Components

### Research workflow

- [Web and API](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/server.py): `switchagent/server.py`
- [Orchestrator](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/orchestrator/agent.py): `switchagent/orchestrator/agent.py`
- [Run session](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/orchestrator/session.py): `switchagent/orchestrator/session.py`
- [Drug resolver](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/resolver.py): `switchagent/resolver.py`

### Evidence pipeline

- [Hybrid retrieval](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/search.py): `switchagent/search.py`
- [Embedding and reranking](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/embed.py): `switchagent/embed.py`
- [Evidence ingestion](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/ingest.py): `switchagent/ingest.py`
- [Evidence sources](https://github.com/rupalhpatel9/biosimilar-switch-agent/tree/main/switchagent/sources): `switchagent/sources`
- [Study extraction](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/extract/pipeline.py): `switchagent/extract/pipeline.py`
- [Structured extractor](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/extract/extractor.py): `switchagent/extract/extractor.py`

### Decision support

- [Patient-fit screener](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/screener/screen.py): `switchagent/screener/screen.py`
- [Cost and timing](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/calculator/savings.py): `switchagent/calculator/savings.py`
- [State substitution rules](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/calculator/state_rules.py): `switchagent/calculator/state_rules.py`
- [Dossier synthesizer](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/synthesizer/synth_pipeline.py): `switchagent/synthesizer/synth_pipeline.py`
- [Strategy tree](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/synthesizer/beam.py): `switchagent/synthesizer/beam.py`
- [Dossier writer](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/synthesizer/writer.py): `switchagent/synthesizer/writer.py`

### Review and trust

- [Claim verifier](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/verify/judge.py): `switchagent/verify/judge.py`
- [Verification checks](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/verify/checks.py): `switchagent/verify/checks.py`
- [Guardrails and sign-off](https://github.com/rupalhpatel9/biosimilar-switch-agent/tree/main/switchagent/guardrails): `switchagent/guardrails`

### Persistence

- [Dossier history](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/memory/history.py): `switchagent/memory/history.py`
- [Postgres evidence store](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/db.py): `switchagent/db.py`
- [Read-only MCP access](https://github.com/rupalhpatel9/biosimilar-switch-agent/blob/main/switchagent/memory/mcp_server.py): `switchagent/memory/mcp_server.py`

### Other components

- **Pharmacist**

## Connections

- Pharmacist → Web and API: asks question (evidence: `README.md`)
- Web and API → Orchestrator: starts research (evidence: `README.md`)
- Orchestrator → Drug resolver: resolves drug (evidence: `README.md`)
- Orchestrator → Hybrid retrieval: searches evidence (evidence: `README.md`)
- Orchestrator → Study extraction: requests extraction (evidence: `README.md`)
- Orchestrator → Cost and timing: computes scenarios (evidence: `README.md`)
- Orchestrator → State substitution rules: checks rules (evidence: `README.md`)
- Web and API → Run session: manages run (evidence: `switchagent/server.py`)
- Hybrid retrieval → Embedding and reranking: reranks results (evidence: `switchagent/search.py`)
- Evidence ingestion → Evidence sources: loads evidence (evidence: `switchagent/ingest.py`)
- Study extraction → Hybrid retrieval: searches studies (evidence: `switchagent/extract/pipeline.py`)
- Study extraction → Structured extractor: extracts fields (evidence: `switchagent/extract/pipeline.py`)
- Study extraction → Claim verifier: verifies claims (evidence: `switchagent/extract/pipeline.py`)
- Claim verifier → Verification checks: checks claims (evidence: `switchagent/verify/judge.py`)
- Dossier synthesizer → Strategy tree: builds strategy (evidence: `switchagent/synthesizer/synth_pipeline.py`)
- Dossier synthesizer → Dossier writer: writes dossier (evidence: `README.md`)
- Dossier synthesizer → Patient-fit screener: screens patient fit (evidence: `switchagent/synthesizer/synth_pipeline.py`)
- Dossier synthesizer → Cost and timing: uses code figures (evidence: `README.md`)
- Web and API → Guardrails and sign-off: applies safeguards (evidence: `README.md`)
- Pharmacist → Web and API: reviews and signs (evidence: `README.md`)
- Run session → Postgres evidence store: stores run state (evidence: `switchagent/orchestrator/session.py`)
- Dossier history → Postgres evidence store: reads history (evidence: `switchagent/memory/history.py`)
- Read-only MCP access → Dossier history: exposes dossiers (evidence: `README.md`)
- Hybrid retrieval → Postgres evidence store: queries evidence (evidence: `switchagent/search.py`)
