# mims-harvard/txagent architecture

> Architecture diagram of the GitHub repository mims-harvard/txagent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mims-harvard/txagent
- Repository: https://github.com/mims-harvard/txagent

## Overview

TxAgent is a therapeutic-reasoning agent that takes a clinical question through iterative language-model reasoning and biomedical tool use to produce an evidence-grounded response. The Gradio demo is the primary documented interactive entry point; the agent also supports a command-line example. ToolRAG selects tools from their descriptions, while the agent coordinates tool calls, incorporates results, and can summarize them. The README describes interaction, contraindication, and personalized-treatment analysis across biomedical sources. Some capabilities are documented rather than visible in the excerpts, so those links are marked as documented; unsampled implementation details are not inferred.

Main entry points: [`src/txagent/txagent.py`](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py) (Iterative reasoning), [`run_txagent_app.py`](https://github.com/mims-harvard/txagent/blob/main/run_txagent_app.py) (Gradio demo), [`src/txagent/toolrag.py`](https://github.com/mims-harvard/txagent/blob/main/src/txagent/toolrag.py) (ToolRAG selection), [`src/txagent/utils.py`](https://github.com/mims-harvard/txagent/blob/main/src/txagent/utils.py) (Trace checker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_demo["Gradio demo<br/>[run_txagent_app.py]"]
end

subgraph group_reasoning["Agent reasoning"]
  node_agent["TxAgent orchestration<br/>[txagent.py]"]
  node_inference["Language-model inference<br/>[txagent.py]"]
  node_reasoning_loop["Iterative reasoning<br/>[txagent.py]"]
  node_tool_calls["Tool execution<br/>[txagent.py]"]
  node_summaries["Tool-result summaries<br/>[txagent.py]"]
  node_checker["Trace checker<br/>[utils.py]"]
  node_treatment_analysis["Therapeutic analysis<br/>[txagent.py]"]
end

subgraph group_retrieval["Tool retrieval"]
  node_toolrag["ToolRAG selection<br/>[toolrag.py]"]
  node_tool_descriptions["Tool descriptions<br/>[txagent.py]"]
end

subgraph group_knowledge["Biomedical knowledge"]
  node_tooluniverse["ToolUniverse tools"]
  node_biomedical_sources["Biomedical sources"]
end

node_clinician(("Questioner"))
node_response["Treatment response"]

node_clinician -->|"submits question"| node_demo
node_demo -->|"runs chat"| node_agent
node_agent -->|"coordinates"| node_reasoning_loop
node_reasoning_loop -->|"requests generation"| node_inference
node_reasoning_loop -->|"selects tools"| node_toolrag
node_toolrag -->|"embeds descriptions"| node_tool_descriptions
node_toolrag -->|"retrieves tool metadata"| node_tooluniverse
node_reasoning_loop -->|"dispatches calls"| node_tool_calls
node_tool_calls -->|"executes functions"| node_tooluniverse
node_tooluniverse -.->|"retrieves evidence"| node_biomedical_sources
node_reasoning_loop -->|"summarizes results"| node_summaries
node_reasoning_loop -->|"checks trace"| node_checker
node_reasoning_loop -.->|"assesses interactions"| node_treatment_analysis
node_treatment_analysis -.->|"grounds recommendations"| node_biomedical_sources
node_agent -->|"returns answer"| node_response
node_demo -.->|"presents answer"| node_response

click node_demo "https://github.com/mims-harvard/txagent/blob/main/run_txagent_app.py"
click node_agent "https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py"
click node_inference "https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py"
click node_reasoning_loop "https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py"
click node_tool_calls "https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py"
click node_summaries "https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py"
click node_checker "https://github.com/mims-harvard/txagent/blob/main/src/txagent/utils.py"
click node_toolrag "https://github.com/mims-harvard/txagent/blob/main/src/txagent/toolrag.py"
click node_tool_descriptions "https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py"
click node_treatment_analysis "https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.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_demo toneBlue
class node_agent,node_inference,node_reasoning_loop,node_tool_calls,node_summaries,node_checker,node_treatment_analysis toneAmber
class node_toolrag,node_tool_descriptions toneMint
class node_tooluniverse,node_biomedical_sources toneRose
class node_clinician,node_response toneIndigo
```

## Components

### User interface

- [Gradio demo](https://github.com/mims-harvard/txagent/blob/main/run_txagent_app.py): `run_txagent_app.py`

### Agent reasoning

- [TxAgent orchestration](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py): `src/txagent/txagent.py`
- [Language-model inference](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py): `src/txagent/txagent.py`
- [Iterative reasoning](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py): `src/txagent/txagent.py`
- [Tool execution](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py): `src/txagent/txagent.py`
- [Tool-result summaries](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py): `src/txagent/txagent.py`
- [Trace checker](https://github.com/mims-harvard/txagent/blob/main/src/txagent/utils.py): `src/txagent/utils.py`
- [Therapeutic analysis](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py): `src/txagent/txagent.py`

### Tool retrieval

- [ToolRAG selection](https://github.com/mims-harvard/txagent/blob/main/src/txagent/toolrag.py): `src/txagent/toolrag.py`
- [Tool descriptions](https://github.com/mims-harvard/txagent/blob/main/src/txagent/txagent.py): `src/txagent/txagent.py`

### Biomedical knowledge

- **ToolUniverse tools**
- **Biomedical sources**

### Other components

- **Questioner**
- **Treatment response**

## Connections

- Questioner → Gradio demo: submits question (evidence: `run_txagent_app.py`)
- Gradio demo → TxAgent orchestration: runs chat (evidence: `run_txagent_app.py`)
- TxAgent orchestration → Iterative reasoning: coordinates (evidence: `src/txagent/txagent.py`)
- Iterative reasoning → Language-model inference: requests generation (evidence: `src/txagent/txagent.py`)
- Iterative reasoning → ToolRAG selection: selects tools (evidence: `src/txagent/txagent.py`)
- ToolRAG selection → Tool descriptions: embeds descriptions (evidence: `src/txagent/toolrag.py`)
- ToolRAG selection → ToolUniverse tools: retrieves tool metadata (evidence: `src/txagent/toolrag.py`)
- Iterative reasoning → Tool execution: dispatches calls (evidence: `src/txagent/txagent.py`)
- Tool execution → ToolUniverse tools: executes functions (evidence: `src/txagent/txagent.py`)
- ToolUniverse tools → Biomedical sources: retrieves evidence (evidence: `README.md`)
- Iterative reasoning → Tool-result summaries: summarizes results (evidence: `src/txagent/txagent.py`)
- Iterative reasoning → Trace checker: checks trace (evidence: `src/txagent/txagent.py`)
- Iterative reasoning → Therapeutic analysis: assesses interactions (evidence: `README.md`)
- Therapeutic analysis → Biomedical sources: grounds recommendations (evidence: `README.md`)
- TxAgent orchestration → Treatment response: returns answer
- Gradio demo → Treatment response: presents answer
