# metr/hawk architecture

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

- Interactive diagram: https://gitdiagram.com/metr/hawk
- Repository: https://github.com/metr/hawk

## Overview

#### Purpose and entry points
Inspect-Hawk is an AWS-hosted platform for running Inspect AI evaluation grids and transcript scans at scale. Users submit YAML through the Python CLI; the API schedules isolated Kubernetes jobs, results are imported into PostgreSQL, and a React SPA exposes browsing/search/export. Main entry points: `hawk/hawk/__main__.py`, `hawk/hawk/cli/cli.py`, `hawk/hawk/api/server.py`, `hawk/hawk/runner/entrypoint.py`, and Pulumi `infra/__main__.py`.

#### Submission, API, and authorization
The CLI authenticates, validates/submits eval-set or scan configurations, monitors jobs, and supports local execution. The FastAPI-style API owns request validation, job creation, Helm/Kubernetes launch, status/log/result endpoints, human workflows, and presigned artifact access. Authorization is a cross-cutting boundary: JWT/access-token checks and model-group permissions protect submission, logs, warehouse data, and files.
Paths: `hawk/hawk/cli/eval_set.py`, `hawk/hawk/api/run.py`, `hawk/hawk/api/auth/permission_checker.py`.

#### Evaluation execution plane
API-created Kubernetes jobs run the runner image. The runner establishes credentials, observability, resource/stop monitors, creates a per-job environment, and invokes Inspect evaluation or scan execution. Evaluation sandboxes are separate pods and are governed by network policies; lifecycle/checkpoint/approval logic supports interruption and human-gated work.
Paths: `hawk/hawk/runner/run_eval_set.py`, `hawk/hawk/runner/run_scan.py`, `hawk/hawk/api/helm_chart/templates/job.yaml`.

#### LLM mediation services
Runner pods call Middleman rather than providers directly. Middleman authenticates callers, selects permitted model/provider configuration, manages provider keys and token/cost/rate-limit behavior, proxies OpenAI-compatible and provider-specific requests, and emits telemetry. It integrates with OpenAI, Anthropic, OpenRouter, and Google/Vertex-related implementations.
Paths: `middleman/src/middleman/server.py`, `middleman/src/middleman/lab_apis/`, `middleman/src/middleman/provider_key_store.py`.

#### Log ingestion and warehouse
Inspect writes eval logs/artifacts to S3. Event-driven services read/import logs and job status into Aurora PostgreSQL, converting eval and scan records via PostgreSQL-specific writers. The warehouse is the durable query boundary, with Alembic migrations, row-level security infrastructure, indexed full-text/trigram search, and model-group access enforcement.
Paths: `hawk/hawk/core/importer/eval/importer.py`, `hawk/hawk/core/importer/scan/importer.py`, `hawk/hawk/core/db/models.py`.

#### Query, viewer, and artifacts
API routes serve eval sets, samples, timelines, searches, scans, usage, and artifacts from the warehouse/S3. The Vite/React viewer calls these APIs, supports OAuth/session handling, result exploration, transcript search, timelines, jobs, scans, and artifact rendering. Static viewer deployment is separate from the API runtime.
Paths: `hawk/hawk/api/transcript_search_router.py`, `hawk/www/src/AppRouter.tsx`, `hawk/www/src/components/SampleExplorer.tsx`.

#### Cloud runtime and operations
Pulumi defines the AWS system: VPC/ALB/DNS, ECS Fargate API/Middleman/viewer services, EKS with Karpenter capacity, Aurora PostgreSQL Serverless, S3, EventBridge/Lambda processing, Cognito, and supporting Valkey/monitoring integrations. Datadog, CloudWatch, OpenTelemetry/X-Ray-related code provide metrics, logs, traces, dashboards, alarms, and dead-letter monitoring.
Paths: `infra/hawk/api.py`, `infra/hawk/runner.py`, `infra/hawk/eventbridge.py`.

#### Key control flow
`hawk eval-set` → API auth/config validation → Helm job on EKS → runner/sandbox execution and Middleman LLM calls → S3 logs → EventBridge/Lambda import → Aurora results → API → browser viewer. Scan submission follows the same control plane but reads historical transcripts and persists structured scan results.

Main entry points: [`hawk/hawk/api/server.py`](https://github.com/metr/hawk/blob/main/hawk/hawk/api/server.py) (Hawk API), [`hawk/hawk/runner/run_eval_set.py`](https://github.com/metr/hawk/blob/main/hawk/hawk/runner/run_eval_set.py) (Evaluation runner), [`middleman/src/middleman/server.py`](https://github.com/metr/hawk/blob/main/middleman/src/middleman/server.py) (Middleman), [`hawk/hawk/core/db/models.py`](https://github.com/metr/hawk/blob/main/hawk/hawk/core/db/models.py) (Aurora PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Clients"]
  node_cli["Python CLI<br/>submission client<br/>[eval_set.py]"]
  node_viewer["React viewer<br/>SPA<br/>[AppRouter.tsx]"]
end

subgraph group_control["Control plane"]
  node_api["Hawk API<br/>FastAPI service<br/>[server.py]"]
  node_authorization{{"Authorization<br/>JWT and model-group ACL"}}
  node_job_launcher["Kubernetes job launcher<br/>Helm job template<br/>[job.yaml]"]
end

subgraph group_execution["Execution plane"]
  node_runner["Evaluation runner<br/>job runtime<br/>[run_eval_set.py]"]
  node_scan_runner["Scan execution<br/>job workflow<br/>[run_scan.py]"]
  node_sandbox_pods["Evaluation sandboxes<br/>isolated pods"]
  node_middleman["Middleman<br/>LLM mediation service<br/>[server.py]"]
  node_provider_keys[("Provider key store<br/>credential and limits")]
  node_llm_providers["LLM providers<br/>external APIs"]
end

subgraph group_data["Data and query"]
  node_s3[("S3 logs and artifacts<br/>object storage")]
  node_event_import["Event import pipeline<br/>EventBridge and Lambda<br/>[eventbridge.py]"]
  node_eval_importer["Evaluation importer<br/>log importer<br/>[importer.py]"]
  node_scan_importer["Scan importer<br/>log importer<br/>[importer.py]"]
  node_warehouse[("Aurora PostgreSQL<br/>results warehouse<br/>[models.py]")]
  node_search_api["Transcript search routes<br/>query API"]
end

subgraph group_cloud["Cloud operations"]
  node_aws_runtime["AWS runtime<br/>ECS, EKS, VPC, ALB<br/>[api.py]"]
  node_runner_infra["Runner infrastructure<br/>EKS capacity<br/>[runner.py]"]
end

node_cli -->|"submit eval-set or scan"| node_api
node_viewer -->|"query and render results"| node_api
node_api -->|"authorize requests"| node_authorization
node_api -->|"create job"| node_job_launcher
node_job_launcher -->|"launch eval job"| node_runner
node_job_launcher -->|"launch scan job"| node_scan_runner
node_runner -->|"run Inspect sandboxes"| node_sandbox_pods
node_runner -->|"LLM requests"| node_middleman
node_scan_runner -->|"LLM requests"| node_middleman
node_middleman -->|"resolve credentials and limits"| node_provider_keys
node_middleman -->|"proxy provider calls"| node_llm_providers
node_runner -->|"write eval logs and artifacts"| node_s3
node_scan_runner -->|"write scan results"| node_s3
node_s3 -->|"object events"| node_event_import
node_event_import -->|"evaluation logs"| node_eval_importer
node_event_import -->|"scan logs"| node_scan_importer
node_eval_importer -->|"persist evaluation records"| node_warehouse
node_scan_importer -->|"persist scan records"| node_warehouse
node_api -->|"results, jobs, and usage queries"| node_warehouse
node_api -->|"presigned artifact access"| node_s3
node_api -->|"mount search endpoint"| node_search_api
node_search_api -->|"full-text transcript search"| node_warehouse
node_aws_runtime -.->|"hosts"| node_api
node_aws_runtime -.->|"hosts"| node_middleman
node_aws_runtime -.->|"deploys static viewer"| node_viewer
node_runner_infra -.->|"provides EKS capacity"| node_runner

click node_cli "https://github.com/metr/hawk/blob/main/hawk/hawk/cli/eval_set.py"
click node_viewer "https://github.com/metr/hawk/blob/main/hawk/www/src/AppRouter.tsx"
click node_api "https://github.com/metr/hawk/blob/main/hawk/hawk/api/server.py"
click node_authorization "https://github.com/metr/hawk/blob/main/hawk/hawk/api/auth/permission_checker.py"
click node_job_launcher "https://github.com/metr/hawk/blob/main/hawk/hawk/api/helm_chart/templates/job.yaml"
click node_runner "https://github.com/metr/hawk/blob/main/hawk/hawk/runner/run_eval_set.py"
click node_scan_runner "https://github.com/metr/hawk/blob/main/hawk/hawk/runner/run_scan.py"
click node_middleman "https://github.com/metr/hawk/blob/main/middleman/src/middleman/server.py"
click node_provider_keys "https://github.com/metr/hawk/blob/main/middleman/src/middleman/provider_key_store.py"
click node_event_import "https://github.com/metr/hawk/blob/main/infra/hawk/eventbridge.py"
click node_eval_importer "https://github.com/metr/hawk/blob/main/hawk/hawk/core/importer/eval/importer.py"
click node_scan_importer "https://github.com/metr/hawk/blob/main/hawk/hawk/core/importer/scan/importer.py"
click node_warehouse "https://github.com/metr/hawk/blob/main/hawk/hawk/core/db/models.py"
click node_search_api "https://github.com/metr/hawk/blob/main/hawk/hawk/api/transcript_search_router.py"
click node_aws_runtime "https://github.com/metr/hawk/blob/main/infra/hawk/api.py"
click node_runner_infra "https://github.com/metr/hawk/blob/main/infra/hawk/runner.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_cli,node_viewer toneBlue
class node_api,node_authorization,node_job_launcher toneAmber
class node_runner,node_scan_runner,node_sandbox_pods,node_middleman,node_provider_keys,node_llm_providers toneMint
class node_s3,node_event_import,node_eval_importer,node_scan_importer,node_warehouse,node_search_api toneRose
class node_aws_runtime,node_runner_infra toneIndigo
```

## Components

### Clients

- [Python CLI](https://github.com/metr/hawk/blob/main/hawk/hawk/cli/eval_set.py): submission client · Authenticates, validates YAML, submits work, and monitors jobs. · `hawk/hawk/cli/eval_set.py`
- [React viewer](https://github.com/metr/hawk/blob/main/hawk/www/src/AppRouter.tsx): SPA · Browses evaluations, scans, timelines, search, and artifacts. · `hawk/www/src/AppRouter.tsx`

### Control plane

- [Hawk API](https://github.com/metr/hawk/blob/main/hawk/hawk/api/server.py): FastAPI service · Validates requests, creates jobs, and serves results and artifacts. · `hawk/hawk/api/server.py`
- [Authorization](https://github.com/metr/hawk/blob/main/hawk/hawk/api/auth/permission_checker.py): JWT and model-group ACL · Protects submission, logs, warehouse data, and files. · `hawk/hawk/api/auth/permission_checker.py`
- [Kubernetes job launcher](https://github.com/metr/hawk/blob/main/hawk/hawk/api/helm_chart/templates/job.yaml): Helm job template · Creates isolated runner jobs on EKS. · `hawk/hawk/api/helm_chart/templates/job.yaml`

### Execution plane

- [Evaluation runner](https://github.com/metr/hawk/blob/main/hawk/hawk/runner/run_eval_set.py): job runtime · Establishes job environment and runs evaluations or scans. · `hawk/hawk/runner/run_eval_set.py`
- [Scan execution](https://github.com/metr/hawk/blob/main/hawk/hawk/runner/run_scan.py): job workflow · Runs transcript scans and produces structured scan records. · `hawk/hawk/runner/run_scan.py`
- **Evaluation sandboxes**: isolated pods · Network-governed pods for Inspect evaluation sandboxes.
- [Middleman](https://github.com/metr/hawk/blob/main/middleman/src/middleman/server.py): LLM mediation service · Authenticates callers and selects permitted provider/model configuration. · `middleman/src/middleman/server.py`
- [Provider key store](https://github.com/metr/hawk/blob/main/middleman/src/middleman/provider_key_store.py): credential and limits · Manages provider keys, costs, tokens, and rate limits. · `middleman/src/middleman/provider_key_store.py`
- **LLM providers**: external APIs · OpenAI, Anthropic, OpenRouter, and Google/Vertex providers.

### Data and query

- **S3 logs and artifacts**: object storage · Durable Inspect logs and generated artifacts.
- [Event import pipeline](https://github.com/metr/hawk/blob/main/infra/hawk/eventbridge.py): EventBridge and Lambda · Imports emitted logs and job status into the warehouse. · `infra/hawk/eventbridge.py`
- [Evaluation importer](https://github.com/metr/hawk/blob/main/hawk/hawk/core/importer/eval/importer.py): log importer · Converts evaluation logs into PostgreSQL records. · `hawk/hawk/core/importer/eval/importer.py`
- [Scan importer](https://github.com/metr/hawk/blob/main/hawk/hawk/core/importer/scan/importer.py): log importer · Converts scan output into structured warehouse records. · `hawk/hawk/core/importer/scan/importer.py`
- [Aurora PostgreSQL](https://github.com/metr/hawk/blob/main/hawk/hawk/core/db/models.py): results warehouse · Durable query boundary with search and model-group enforcement. · `hawk/hawk/core/db/models.py`
- [Transcript search routes](https://github.com/metr/hawk/blob/main/hawk/hawk/api/transcript_search_router.py): query API · Serves transcript search from the warehouse. · `hawk/hawk/api/transcript_search_router.py`

### Cloud operations

- [AWS runtime](https://github.com/metr/hawk/blob/main/infra/hawk/api.py): ECS, EKS, VPC, ALB · Hosts API, Middleman, viewer, and runner capacity. · `infra/hawk/api.py`
- [Runner infrastructure](https://github.com/metr/hawk/blob/main/infra/hawk/runner.py): EKS capacity · Defines EKS runner deployment and capacity integration. · `infra/hawk/runner.py`

## Connections

- Python CLI → Hawk API: submit eval-set or scan
- React viewer → Hawk API: query and render results
- Hawk API → Authorization: authorize requests
- Hawk API → Kubernetes job launcher: create job
- Kubernetes job launcher → Evaluation runner: launch eval job
- Kubernetes job launcher → Scan execution: launch scan job
- Evaluation runner → Evaluation sandboxes: run Inspect sandboxes
- Evaluation runner → Middleman: LLM requests
- Scan execution → Middleman: LLM requests
- Middleman → Provider key store: resolve credentials and limits
- Middleman → LLM providers: proxy provider calls
- Evaluation runner → S3 logs and artifacts: write eval logs and artifacts
- Scan execution → S3 logs and artifacts: write scan results
- S3 logs and artifacts → Event import pipeline: object events
- Event import pipeline → Evaluation importer: evaluation logs
- Event import pipeline → Scan importer: scan logs
- Evaluation importer → Aurora PostgreSQL: persist evaluation records
- Scan importer → Aurora PostgreSQL: persist scan records
- Hawk API → Aurora PostgreSQL: results, jobs, and usage queries
- Hawk API → S3 logs and artifacts: presigned artifact access
- Hawk API → Transcript search routes: mount search endpoint
- Transcript search routes → Aurora PostgreSQL: full-text transcript search
- AWS runtime → Hawk API: hosts
- AWS runtime → Middleman: hosts
- AWS runtime → React viewer: deploys static viewer
- Runner infrastructure → Evaluation runner: provides EKS capacity
