|
| 1 | +# UCSF BioRouter — Architecture |
| 2 | + |
| 3 | +UCSF BioRouter is an AI-powered integrated research environment that unifies commercial, institution-hosted, and local large language models (LLMs), AI agents, Information Commons databases, and customizable workflows into one extensible platform for explorative analysis, prototyping, automation, and federated cross-institution collaboration. |
| 4 | + |
| 5 | +**Developed by:** Wanjun Gu (wanjun.gu@ucsf.edu), Baranzini Lab (https://baranzinilab.ucsf.edu/), UCSF |
| 6 | +**Supported by:** UCSF IT and Information Commons |
| 7 | +**GitHub:** https://github.com/BaranziniLab/BioRouter |
| 8 | +**Releases:** https://github.com/BaranziniLab/BioRouter/releases |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## High-Level Overview |
| 13 | + |
| 14 | +BioRouter is built as a modular, plugin-based system. It consists of three main layers: |
| 15 | + |
| 16 | +1. **Interface** — The desktop GUI or CLI that accepts user input and displays responses. |
| 17 | +2. **Agent** — The core reasoning loop that manages LLM interaction, tool execution, and session state. |
| 18 | +3. **Extensions** — Pluggable MCP servers that give the agent access to tools (file operations, database queries, web access, code execution, etc.). |
| 19 | + |
| 20 | +In a typical session, the interface starts an agent instance, which connects to one or more extensions simultaneously and routes requests through the selected LLM provider. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Tech Stack |
| 25 | + |
| 26 | +### Backend — Rust |
| 27 | + |
| 28 | +The backend is a Rust workspace (`crates/`) organized into several crates: |
| 29 | + |
| 30 | +| Crate | Purpose | |
| 31 | +|---|---| |
| 32 | +| `biorouter` | Core agent library — agent loop, provider integrations, session management, recipes, scheduling | |
| 33 | +| `biorouter-server` | REST API server (`biorouterd`) that the desktop UI communicates with | |
| 34 | +| `biorouter-cli` | Command-line interface (`biorouter` binary) | |
| 35 | +| `biorouter-mcp` | Built-in MCP servers (Developer, Computer Controller, Memory, Tutorial, Auto Visualiser) | |
| 36 | +| `biorouter-acp` | Agent Communication Protocol support | |
| 37 | +| `biorouter-bench` | Benchmarking tools | |
| 38 | +| `biorouter-test` | Integration tests | |
| 39 | + |
| 40 | +Key Rust dependencies: |
| 41 | + |
| 42 | +- **tokio** — Async runtime |
| 43 | +- **axum** — HTTP web framework for the API server |
| 44 | +- **rmcp** — Model Context Protocol implementation |
| 45 | +- **reqwest** — HTTP client for provider API calls |
| 46 | +- **serde / serde_json** — Serialization |
| 47 | +- **tiktoken-rs** — Token counting for context management |
| 48 | +- **minijinja** — Jinja-style template engine for recipes |
| 49 | +- **tokio-cron-scheduler** — Cron-based job scheduling |
| 50 | +- **sqlx (SQLite)** — Persistent session and schedule storage |
| 51 | +- **etcetera** — Cross-platform config path resolution (`~/.config/biorouter/` on macOS/Linux) |
| 52 | + |
| 53 | +### Frontend — Electron + React |
| 54 | + |
| 55 | +The desktop application is an Electron app built with React and TypeScript. |
| 56 | + |
| 57 | +| Component | Details | |
| 58 | +|---|---| |
| 59 | +| Framework | Electron 39 + React 19 | |
| 60 | +| Build tool | Vite + Electron Forge | |
| 61 | +| Language | TypeScript (strict mode) | |
| 62 | +| Styling | TailwindCSS v4 with custom design tokens | |
| 63 | +| UI components | Radix UI primitives | |
| 64 | +| Routing | React Router DOM v7 | |
| 65 | +| Testing | Vitest (unit), Playwright (E2E) | |
| 66 | + |
| 67 | +The frontend communicates with the `biorouterd` REST server (started in the background by the Electron main process) via a local HTTP API. The OpenAPI spec is generated from the Rust server and used to type-safe frontend API calls. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Agent Interaction Loop |
| 72 | + |
| 73 | +The agent operates in a continuous loop: |
| 74 | + |
| 75 | +1. **Human request** — The user sends a message or task through the interface. |
| 76 | +2. **Provider chat** — The agent forwards the request plus a list of available tools to the configured LLM provider. |
| 77 | +3. **Tool call** — If the LLM decides to invoke a tool, the agent extracts the tool call (JSON) and executes it via the appropriate extension. |
| 78 | +4. **Result feedback** — The tool result is returned to the LLM as context. |
| 79 | +5. **Context revision** — Old or irrelevant messages are summarized or pruned to manage token usage efficiently. |
| 80 | +6. **Final response** — Once all tool calls are complete, the LLM sends a final response to the user. |
| 81 | + |
| 82 | +If a tool call produces an error (invalid JSON, missing tool, etc.), BioRouter captures and returns the error to the model as a tool response, allowing the LLM to self-correct without breaking the session. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## Configuration and Data Paths |
| 87 | + |
| 88 | +| Location | Purpose | |
| 89 | +|---|---| |
| 90 | +| `~/.config/biorouter/config.yaml` | Primary config — providers, API keys, extensions, settings | |
| 91 | +| `~/.config/biorouter/sessions/` | Session history (SQLite) | |
| 92 | +| `~/.config/biorouter/recipes/` | Saved recipes | |
| 93 | +| `~/.config/biorouter/skills/` | BioRouter-specific global skills | |
| 94 | +| `~/Library/Application Support/BioRouter/` | Electron app state (macOS) | |
| 95 | + |
| 96 | +The config file is shared between the Desktop UI and the CLI — changes in either interface are reflected in both. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Multi-Model and Multi-Agent Support |
| 101 | + |
| 102 | +BioRouter supports running multiple agents in parallel: |
| 103 | + |
| 104 | +- **Sub-agents** — A recipe can spawn sub-agents to handle parallel tasks, each with its own LLM provider and extension set. |
| 105 | +- **Lead/Worker orchestration** — A lead model delegates sub-tasks to worker models, enabling multi-model pipelines. |
| 106 | +- **Subrecipes** — Recipes can call other recipes as sub-tasks, running them sequentially or in parallel. |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## Security |
| 111 | + |
| 112 | +- Extensions are scanned for known malware before activation. |
| 113 | +- BioRouter enforces permission modes that control whether tool calls require user approval. |
| 114 | +- `.biorouterignore` files can restrict which files and directories the agent is allowed to access. |
| 115 | +- Allowlists can restrict which shell commands the agent may execute. |
0 commit comments