# huggingface/tau architecture

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

- Interactive diagram: https://gitdiagram.com/huggingface/tau
- Repository: https://github.com/huggingface/tau

## Overview

#### Purpose and entry points
Tau is a Python 3.12+ terminal coding agent and reusable agent-harness example. The installed `tau` command is implemented by the coding application CLI at `src/tau_coding/cli.py`; it supports an interactive Textual UI and non-interactive print mode. Library consumers can use the provider-neutral harness directly through `src/tau_agent/harness.py`.

#### Layered architecture
The repository is deliberately split into three dependency layers:
- **Provider adapter layer:** `src/tau_ai/provider.py`, `src/tau_ai/stream.py`, and provider implementations such as `src/tau_ai/anthropic.py` normalize vendor APIs into a typed streaming protocol.
- **Portable agent core:** `src/tau_agent/harness.py`, `src/tau_agent/loop.py`, and `src/tau_agent/events.py` own messages, tool calling, agent control flow, and emitted events without knowing local paths, UI, or rendering.
- **Coding application:** `src/tau_coding/session.py`, `src/tau_coding/tools.py`, and `src/tau_coding/commands.py` bind the generic harness to a project workspace and coding-agent features.

#### Agent execution flow
A user prompt enters through CLI/TUI, is assembled with system instructions and active session context, then reaches `AgentHarness`. The loop in `src/tau_agent/loop.py` streams model output, converts requested tool calls into typed tool execution, appends results to messages, and repeats until completion. Typed event contracts in `src/tau_agent/events.py` and provider events in `src/tau_agent/provider_events.py` are the key boundary: frontends consume events rather than participate in agent logic.

#### Providers, credentials, and model policy
`src/tau_coding/provider_catalog.py` and `src/tau_coding/provider_runtime.py` select configured models/providers from the bundled catalog at `src/tau_coding/data/catalog.toml` plus user overrides. `src/tau_coding/credentials.py` and the OAuth modules handle authentication, including provider-specific OAuth flows. The lower `tau_ai` package supports Anthropic, Google, Mistral, OpenAI/Codex, and OpenAI-compatible HTTP services; its retry and HTTP boundaries are `src/tau_ai/retry.py` and `src/tau_ai/http.py`.

#### Coding environment and context
`CodingSession` in `src/tau_coding/session.py` composes the harness with filesystem and shell capabilities from `src/tau_coding/tools.py`. It discovers project instructions, skills, prompts, and related resources through `src/tau_coding/resources.py` and `src/tau_coding/skills.py`, then builds the system prompt in `src/tau_coding/system_prompt.py`. Context-window measurement and compaction policy live in `src/tau_coding/context.py` and `src/tau_coding/context_window.py`.

#### Durable sessions
The generic session model is an append-only tree backed by JSONL: `src/tau_agent/session/tree.py`, `src/tau_agent/session/jsonl.py`, and `src/tau_agent/session/storage.py`. The application-level manager in `src/tau_coding/session_manager.py` handles create/resume/branch workflows and persisted Tau sessions under the user data directory. This separates immutable transcript history from the currently compacted model context.

#### Frontends, rendering, and extensibility
The Textual frontend is isolated in `src/tau_coding/tui/app.py` and `src/tau_coding/tui/adapter.py`; it translates harness events into UI state. Print mode uses event renderers in `src/tau_coding/rendering/plain.py`, `src/tau_coding/rendering/json.py`, and `src/tau_coding/rendering/transcript.py`. Extensions are loaded and executed at the coding-app boundary through `src/tau_coding/extensions/loader.py` and `src/tau_coding/extensions/runtime.py`, allowing custom tools without changing the portable core.

Main entry points: [`src/tau_coding/session.py`](https://github.com/huggingface/tau/blob/main/src/tau_coding/session.py) (Coding session), [`src/tau_agent/loop.py`](https://github.com/huggingface/tau/blob/main/src/tau_agent/loop.py) (Agent loop), [`src/tau_coding/provider_runtime.py`](https://github.com/huggingface/tau/blob/main/src/tau_coding/provider_runtime.py) (Provider runtime), [`src/tau_ai/provider.py`](https://github.com/huggingface/tau/blob/main/src/tau_ai/provider.py) (Provider protocol)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontends["Entry &amp; Frontends"]
  node_cli["tau CLI<br/>command<br/>[cli.py]"]
  node_tui["Textual UI<br/>frontend<br/>[app.py]"]
  node_tui_adapter["TUI adapter<br/>event adapter<br/>[adapter.py]"]
  node_renderers["Print renderers<br/>[plain.py]"]
end

subgraph group_coding["Coding Application"]
  node_session_manager["Session manager<br/>workflow manager<br/>[session_manager.py]"]
  node_coding_session["Coding session<br/>application binding<br/>[session.py]"]
  node_workspace_tools["Workspace tools<br/>tool provider<br/>[tools.py]"]
  node_resource_context["Project resources<br/>context discovery<br/>[resources.py]"]
  node_system_prompt["System prompt builder<br/>prompt assembly<br/>[system_prompt.py]"]
  node_context_policy["Context policy<br/>context management<br/>[context.py]"]
  node_extensions["Extension runtime<br/>extension host<br/>[runtime.py]"]
  node_provider_runtime["Provider runtime<br/>model selection"]
  node_provider_catalog["Provider catalog<br/>model catalog"]
  node_credentials["Credentials &amp; OAuth<br/>authentication<br/>[credentials.py]"]
end

subgraph group_core["Portable Agent Core"]
  node_harness["Agent harness<br/>agent API<br/>[harness.py]"]
  node_agent_loop["Agent loop<br/>control loop<br/>[loop.py]"]
  node_agent_events["Typed agent events<br/>event contract<br/>[events.py]"]
end

subgraph group_providers["Provider Adapters"]
  node_provider_protocol["Provider protocol<br/>streaming abstraction<br/>[provider.py]"]
  node_provider_events["Provider events<br/>event contract<br/>[provider_events.py]"]
  node_vendor_adapters["Vendor adapters<br/>provider implementations<br/>[anthropic.py]"]
  node_http_retry["HTTP &amp; retry<br/>transport<br/>[http.py]"]
end

subgraph group_persistence["Session Persistence"]
  node_session_tree["Session tree<br/>transcript model<br/>[tree.py]"]
  node_jsonl_storage[("JSONL storage<br/>session storage<br/>[jsonl.py]")]
end

node_cli -->|"interactive mode"| node_tui
node_cli -->|"print mode"| node_renderers
node_cli -->|"opens session"| node_session_manager
node_tui -->|"uses"| node_tui_adapter
node_tui_adapter -->|"consumes"| node_agent_events
node_renderers -->|"renders"| node_agent_events
node_session_manager -->|"creates/resumes"| node_coding_session
node_session_manager -->|"manages history"| node_session_tree
node_session_tree -->|"persists as"| node_jsonl_storage
node_coding_session -->|"configures"| node_harness
node_coding_session -->|"provides tools"| node_workspace_tools
node_coding_session -->|"assembles prompt"| node_system_prompt
node_resource_context -->|"supplies instructions"| node_system_prompt
node_context_policy -->|"compacts context"| node_coding_session
node_extensions -->|"adds tools"| node_workspace_tools
node_harness -->|"runs"| node_agent_loop
node_agent_loop -->|"emits"| node_agent_events
node_agent_loop -->|"streams model output"| node_provider_protocol
node_agent_loop -->|"executes calls"| node_workspace_tools
node_agent_loop -->|"appends transcript"| node_session_tree
node_provider_runtime -->|"reads policy"| node_provider_catalog
node_provider_runtime -->|"obtains auth"| node_credentials
node_coding_session -->|"selects model"| node_provider_runtime
node_provider_runtime -->|"configures"| node_provider_protocol
node_provider_protocol -->|"uses"| node_provider_events
node_provider_protocol -->|"implemented by"| node_vendor_adapters
node_vendor_adapters -->|"uses transport"| node_http_retry

click node_cli "https://github.com/huggingface/tau/blob/main/src/tau_coding/cli.py"
click node_tui "https://github.com/huggingface/tau/blob/main/src/tau_coding/tui/app.py"
click node_tui_adapter "https://github.com/huggingface/tau/blob/main/src/tau_coding/tui/adapter.py"
click node_renderers "https://github.com/huggingface/tau/blob/main/src/tau_coding/rendering/plain.py"
click node_session_manager "https://github.com/huggingface/tau/blob/main/src/tau_coding/session_manager.py"
click node_coding_session "https://github.com/huggingface/tau/blob/main/src/tau_coding/session.py"
click node_workspace_tools "https://github.com/huggingface/tau/blob/main/src/tau_coding/tools.py"
click node_resource_context "https://github.com/huggingface/tau/blob/main/src/tau_coding/resources.py"
click node_system_prompt "https://github.com/huggingface/tau/blob/main/src/tau_coding/system_prompt.py"
click node_context_policy "https://github.com/huggingface/tau/blob/main/src/tau_coding/context.py"
click node_extensions "https://github.com/huggingface/tau/blob/main/src/tau_coding/extensions/runtime.py"
click node_harness "https://github.com/huggingface/tau/blob/main/src/tau_agent/harness.py"
click node_agent_loop "https://github.com/huggingface/tau/blob/main/src/tau_agent/loop.py"
click node_agent_events "https://github.com/huggingface/tau/blob/main/src/tau_agent/events.py"
click node_session_tree "https://github.com/huggingface/tau/blob/main/src/tau_agent/session/tree.py"
click node_jsonl_storage "https://github.com/huggingface/tau/blob/main/src/tau_agent/session/jsonl.py"
click node_provider_runtime "https://github.com/huggingface/tau/blob/main/src/tau_coding/provider_runtime.py"
click node_provider_catalog "https://github.com/huggingface/tau/blob/main/src/tau_coding/provider_catalog.py"
click node_credentials "https://github.com/huggingface/tau/blob/main/src/tau_coding/credentials.py"
click node_provider_protocol "https://github.com/huggingface/tau/blob/main/src/tau_ai/provider.py"
click node_provider_events "https://github.com/huggingface/tau/blob/main/src/tau_agent/provider_events.py"
click node_vendor_adapters "https://github.com/huggingface/tau/blob/main/src/tau_ai/anthropic.py"
click node_http_retry "https://github.com/huggingface/tau/blob/main/src/tau_ai/http.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_tui,node_tui_adapter,node_renderers toneBlue
class node_session_manager,node_coding_session,node_workspace_tools,node_resource_context,node_system_prompt,node_context_policy,node_extensions,node_provider_runtime,node_provider_catalog,node_credentials toneAmber
class node_harness,node_agent_loop,node_agent_events toneMint
class node_provider_protocol,node_provider_events,node_vendor_adapters,node_http_retry toneRose
class node_session_tree,node_jsonl_storage toneIndigo
```

## Components

### Entry & Frontends

- [tau CLI](https://github.com/huggingface/tau/blob/main/src/tau_coding/cli.py): command · Interactive TUI and non-interactive print entry point. · `src/tau_coding/cli.py`
- [Textual UI](https://github.com/huggingface/tau/blob/main/src/tau_coding/tui/app.py): frontend · Translates harness events into UI state. · `src/tau_coding/tui/app.py`
- [TUI adapter](https://github.com/huggingface/tau/blob/main/src/tau_coding/tui/adapter.py): event adapter · `src/tau_coding/tui/adapter.py`
- [Print renderers](https://github.com/huggingface/tau/blob/main/src/tau_coding/rendering/plain.py): renderer · Plain, JSON, and transcript event output. · `src/tau_coding/rendering/plain.py`

### Coding Application

- [Session manager](https://github.com/huggingface/tau/blob/main/src/tau_coding/session_manager.py): workflow manager · Creates, resumes, and branches persisted coding sessions. · `src/tau_coding/session_manager.py`
- [Coding session](https://github.com/huggingface/tau/blob/main/src/tau_coding/session.py): application binding · Binds the portable harness to a project workspace. · `src/tau_coding/session.py`
- [Workspace tools](https://github.com/huggingface/tau/blob/main/src/tau_coding/tools.py): tool provider · Filesystem and shell capabilities. · `src/tau_coding/tools.py`
- [Project resources](https://github.com/huggingface/tau/blob/main/src/tau_coding/resources.py): context discovery · Discovers instructions, skills, prompts, and resources. · `src/tau_coding/resources.py`
- [System prompt builder](https://github.com/huggingface/tau/blob/main/src/tau_coding/system_prompt.py): prompt assembly · `src/tau_coding/system_prompt.py`
- [Context policy](https://github.com/huggingface/tau/blob/main/src/tau_coding/context.py): context management · Measures and compacts model context. · `src/tau_coding/context.py`
- [Extension runtime](https://github.com/huggingface/tau/blob/main/src/tau_coding/extensions/runtime.py): extension host · Loads custom tools at the app boundary. · `src/tau_coding/extensions/runtime.py`
- [Provider runtime](https://github.com/huggingface/tau/blob/main/src/tau_coding/provider_runtime.py): model selection · Selects configured models and providers. · `src/tau_coding/provider_runtime.py`
- [Provider catalog](https://github.com/huggingface/tau/blob/main/src/tau_coding/provider_catalog.py): model catalog · Bundled catalog plus user overrides. · `src/tau_coding/provider_catalog.py`
- [Credentials & OAuth](https://github.com/huggingface/tau/blob/main/src/tau_coding/credentials.py): authentication · `src/tau_coding/credentials.py`

### Portable Agent Core

- [Agent harness](https://github.com/huggingface/tau/blob/main/src/tau_agent/harness.py): agent API · Provider-neutral reusable agent interface. · `src/tau_agent/harness.py`
- [Agent loop](https://github.com/huggingface/tau/blob/main/src/tau_agent/loop.py): control loop · Streams output, executes tools, appends results, and repeats. · `src/tau_agent/loop.py`
- [Typed agent events](https://github.com/huggingface/tau/blob/main/src/tau_agent/events.py): event contract · Frontend boundary for agent progress and results. · `src/tau_agent/events.py`

### Provider Adapters

- [Provider protocol](https://github.com/huggingface/tau/blob/main/src/tau_ai/provider.py): streaming abstraction · Normalizes vendor APIs into typed streaming. · `src/tau_ai/provider.py`
- [Provider events](https://github.com/huggingface/tau/blob/main/src/tau_agent/provider_events.py): event contract · `src/tau_agent/provider_events.py`
- [Vendor adapters](https://github.com/huggingface/tau/blob/main/src/tau_ai/anthropic.py): provider implementations · Anthropic, Google, Mistral, OpenAI/Codex, and compatible services. · `src/tau_ai/anthropic.py`
- [HTTP & retry](https://github.com/huggingface/tau/blob/main/src/tau_ai/http.py): transport · `src/tau_ai/http.py`

### Session Persistence

- [Session tree](https://github.com/huggingface/tau/blob/main/src/tau_agent/session/tree.py): transcript model · Append-only immutable conversation history. · `src/tau_agent/session/tree.py`
- [JSONL storage](https://github.com/huggingface/tau/blob/main/src/tau_agent/session/jsonl.py): session storage · `src/tau_agent/session/jsonl.py`

## Connections

- tau CLI → Textual UI: interactive mode
- tau CLI → Print renderers: print mode
- tau CLI → Session manager: opens session
- Textual UI → TUI adapter: uses
- TUI adapter → Typed agent events: consumes
- Print renderers → Typed agent events: renders
- Session manager → Coding session: creates/resumes
- Session manager → Session tree: manages history
- Session tree → JSONL storage: persists as
- Coding session → Agent harness: configures
- Coding session → Workspace tools: provides tools
- Coding session → System prompt builder: assembles prompt
- Project resources → System prompt builder: supplies instructions
- Context policy → Coding session: compacts context
- Extension runtime → Workspace tools: adds tools
- Agent harness → Agent loop: runs
- Agent loop → Typed agent events: emits
- Agent loop → Provider protocol: streams model output
- Agent loop → Workspace tools: executes calls
- Agent loop → Session tree: appends transcript
- Provider runtime → Provider catalog: reads policy
- Provider runtime → Credentials & OAuth: obtains auth
- Coding session → Provider runtime: selects model
- Provider runtime → Provider protocol: configures
- Provider protocol → Provider events: uses
- Provider protocol → Vendor adapters: implemented by
- Vendor adapters → HTTP & retry: uses transport
