# salikawtar/northstar-agent architecture

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

- Interactive diagram: https://gitdiagram.com/salikawtar/northstar-agent
- Repository: https://github.com/salikawtar/northstar-agent
- Video tour (about a minute): https://gitdiagram.com/salikawtar/northstar-agent/video

## Overview

Northstar is a bilingual dealership customer-support agent and an accompanying research system for generating synthetic data, testing safety, comparing agent configurations, and estimating operating costs. The main customer workflow routes a chat, sends it to a specialist or a safe handoff, uses permissioned dealer tools, and returns a guarded reply. The graph also preserves the documented data-generation, fine-tuned-router, red-team, evaluation, and economics capabilities. Relationships are cited from shown excerpts, the source index, or the README; unsampled implementations are not assumed to have been inspected.

Main entry points: [`src/northstar/agent/pipeline.py`](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/pipeline.py) (Agent pipeline), [`src/northstar/evaluation/harness.py`](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/evaluation/harness.py) (Evaluation harness), [`src/northstar/agent/specialist.py`](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/specialist.py) (Specialist desks), [`src/northstar/agent/router.py`](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/router.py) (Request router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Agent runtime"]
  node_pipeline["Agent pipeline<br/>[pipeline.py]"]
  node_router["Request router<br/>[router.py]"]
  node_specialist["Specialist desks<br/>[specialist.py]"]
  node_tools["Agent tool access<br/>[tools.py]"]
  node_handoff["Human handoff<br/>[handoff.py]"]
  node_llm["Model client<br/>[llm.py]"]
  node_contracts["Shared contracts<br/>[contracts.py]"]
  node_config["Settings and paths<br/>[config.py]"]
end

subgraph group_dealer_data["Data and dealership"]
  node_data["Dataset loader<br/>[data.py]"]
  node_datagen["Synthetic data pipeline<br/>[pipeline.py]"]
  node_dmsgen["Dealer data generator<br/>[generate.py]"]
  node_dms[("Mock dealer system<br/>[store.py]")]
end

subgraph group_safety["Safety controls"]
  node_inputguard["Input checks<br/>[input_check.py]"]
  node_outputguard["Output checks<br/>[output_check.py]"]
  node_masking["Log masking<br/>[log_masking.py]"]
  node_redteam["Red-team runner<br/>[redteam.py]"]
end

subgraph group_research["Evaluation and analysis"]
  node_finetune["Router fine-tuning<br/>[train_router.py]"]
  node_evaluation["Evaluation harness<br/>[harness.py]"]
  node_grader["Rule and model graders<br/>[grader.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.py]"]
  node_economics["Cost model<br/>[model.py]"]
end

node_customer(("Customer"))
node_openrouter{{"OpenRouter"}}

node_customer -->|"sends chat"| node_pipeline
node_pipeline -->|"routes chat"| node_router
node_pipeline -->|"dispatches to desk"| node_specialist
node_pipeline -->|"creates handoff"| node_handoff
node_pipeline -->|"checks input"| node_inputguard
node_pipeline -->|"checks reply"| node_outputguard
node_pipeline -->|"masks results"| node_masking
node_router -->|"requests route"| node_llm
node_specialist -->|"requests reply"| node_llm
node_specialist -->|"uses tools"| node_tools
node_tools -->|"calls dealer API"| node_dms
node_llm -->|"sends model calls"| node_openrouter
node_datagen -.->|"builds datasets"| node_data
node_data -->|"supplies chats"| node_dmsgen
node_dmsgen -->|"generates records"| node_dms
node_evaluation -->|"loads test chats"| node_data
node_evaluation -->|"runs agent"| node_pipeline
node_evaluation -->|"runs router setup"| node_router
node_evaluation -->|"runs desk setup"| node_specialist
node_evaluation -->|"uses dealer system"| node_dms
node_evaluation -->|"grades results"| node_grader
node_grader -->|"requests model grade"| node_llm
node_evaluation -.->|"summarizes scores"| node_metrics
node_redteam -->|"tests attacks"| node_pipeline
node_finetune -->|"trains router"| node_router
node_economics -->|"reads assumptions"| node_config
node_pipeline -.->|"uses shared shapes"| node_contracts
node_pipeline -.->|"reads settings"| node_config

click node_pipeline "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/pipeline.py"
click node_router "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/router.py"
click node_specialist "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/specialist.py"
click node_tools "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/tools.py"
click node_handoff "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/handoff.py"
click node_llm "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/llm.py"
click node_contracts "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/contracts.py"
click node_config "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/config.py"
click node_data "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/data.py"
click node_datagen "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/datagen/pipeline.py"
click node_dmsgen "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/dms/generate.py"
click node_dms "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/dms/store.py"
click node_inputguard "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/input_check.py"
click node_outputguard "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/output_check.py"
click node_masking "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/log_masking.py"
click node_redteam "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/redteam.py"
click node_finetune "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/finetune/train_router.py"
click node_evaluation "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/evaluation/harness.py"
click node_grader "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/evaluation/grader.py"
click node_metrics "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/evaluation/metrics.py"
click node_economics "https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/economics/model.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_pipeline,node_router,node_specialist,node_tools,node_handoff,node_llm,node_contracts,node_config toneBlue
class node_data,node_datagen,node_dmsgen,node_dms toneAmber
class node_inputguard,node_outputguard,node_masking,node_redteam,node_openrouter toneMint
class node_finetune,node_evaluation,node_grader,node_metrics,node_economics toneRose
class node_customer toneIndigo
```

## Components

### Agent runtime

- [Agent pipeline](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/pipeline.py): `src/northstar/agent/pipeline.py`
- [Request router](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/router.py): `src/northstar/agent/router.py`
- [Specialist desks](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/specialist.py): `src/northstar/agent/specialist.py`
- [Agent tool access](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/tools.py): `src/northstar/agent/tools.py`
- [Human handoff](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/agent/handoff.py): `src/northstar/agent/handoff.py`
- [Model client](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/llm.py): `src/northstar/llm.py`
- [Shared contracts](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/contracts.py): `src/northstar/contracts.py`
- [Settings and paths](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/config.py): `src/northstar/config.py`

### Data and dealership

- [Dataset loader](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/data.py): `src/northstar/data.py`
- [Synthetic data pipeline](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/datagen/pipeline.py): `src/northstar/datagen/pipeline.py`
- [Dealer data generator](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/dms/generate.py): `src/northstar/dms/generate.py`
- [Mock dealer system](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/dms/store.py): `src/northstar/dms/store.py`

### Safety controls

- [Input checks](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/input_check.py): `src/northstar/guardrails/input_check.py`
- [Output checks](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/output_check.py): `src/northstar/guardrails/output_check.py`
- [Log masking](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/log_masking.py): `src/northstar/guardrails/log_masking.py`
- [Red-team runner](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/guardrails/redteam.py): `src/northstar/guardrails/redteam.py`

### Evaluation and analysis

- [Router fine-tuning](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/finetune/train_router.py): `src/northstar/finetune/train_router.py`
- [Evaluation harness](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/evaluation/harness.py): `src/northstar/evaluation/harness.py`
- [Rule and model graders](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/evaluation/grader.py): `src/northstar/evaluation/grader.py`
- [Evaluation metrics](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/evaluation/metrics.py): `src/northstar/evaluation/metrics.py`
- [Cost model](https://github.com/salikawtar/northstar-agent/blob/main/src/northstar/economics/model.py): `src/northstar/economics/model.py`

### Other components

- **Customer**
- **OpenRouter**

## Connections

- Customer → Agent pipeline: sends chat
- Agent pipeline → Request router: routes chat (evidence: `src/northstar/agent/pipeline.py`)
- Agent pipeline → Specialist desks: dispatches to desk (evidence: `src/northstar/agent/pipeline.py`)
- Agent pipeline → Human handoff: creates handoff (evidence: `src/northstar/agent/pipeline.py`)
- Agent pipeline → Input checks: checks input (evidence: `src/northstar/agent/pipeline.py`)
- Agent pipeline → Output checks: checks reply (evidence: `src/northstar/agent/pipeline.py`)
- Agent pipeline → Log masking: masks results (evidence: `src/northstar/agent/pipeline.py`)
- Request router → Model client: requests route (evidence: `src/northstar/agent/router.py`)
- Specialist desks → Model client: requests reply (evidence: `src/northstar/agent/specialist.py`)
- Specialist desks → Agent tool access: uses tools (evidence: `src/northstar/agent/specialist.py`)
- Agent tool access → Mock dealer system: calls dealer API (evidence: `src/northstar/agent/tools.py`)
- Model client → OpenRouter: sends model calls (evidence: `src/northstar/llm.py`)
- Synthetic data pipeline → Dataset loader: builds datasets
- Dataset loader → Dealer data generator: supplies chats (evidence: `src/northstar/dms/generate.py`)
- Dealer data generator → Mock dealer system: generates records (evidence: `src/northstar/dms/store.py`)
- Evaluation harness → Dataset loader: loads test chats (evidence: `src/northstar/evaluation/harness.py`)
- Evaluation harness → Agent pipeline: runs agent (evidence: `src/northstar/evaluation/harness.py`)
- Evaluation harness → Request router: runs router setup (evidence: `src/northstar/evaluation/harness.py`)
- Evaluation harness → Specialist desks: runs desk setup (evidence: `src/northstar/evaluation/harness.py`)
- Evaluation harness → Mock dealer system: uses dealer system (evidence: `src/northstar/evaluation/harness.py`)
- Evaluation harness → Rule and model graders: grades results (evidence: `src/northstar/evaluation/__main__.py`)
- Rule and model graders → Model client: requests model grade (evidence: `src/northstar/evaluation/grader.py`)
- Evaluation harness → Evaluation metrics: summarizes scores
- Red-team runner → Agent pipeline: tests attacks (evidence: `src/northstar/guardrails/redteam.py`)
- Router fine-tuning → Request router: trains router (evidence: `src/northstar/finetune/train_router.py`)
- Cost model → Settings and paths: reads assumptions (evidence: `src/northstar/economics/model.py`)
- Agent pipeline → Shared contracts: uses shared shapes (evidence: `src/northstar/agent/pipeline.py`)
- Agent pipeline → Settings and paths: reads settings (evidence: `src/northstar/agent/pipeline.py`)
