How huggingface/tau works
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: session.py Coding session · loop.py Agent loop · provider_runtime.py Provider runtime · provider.py Provider protocol
Components 23
Entry & Frontends
- tau CLI · Interactive TUI and non-interactive print entry point.
src/tau_coding/cli.py - Textual UI · Translates harness events into UI state.
src/tau_coding/tui/app.py - TUI adapter
src/tau_coding/tui/adapter.py - Print renderers · Plain, JSON, and transcript event output.
src/tau_coding/rendering/plain.py
Coding Application
- Session manager · Creates, resumes, and branches persisted coding sessions.
src/tau_coding/session_manager.py - Coding session · Binds the portable harness to a project workspace.
src/tau_coding/session.py - Workspace tools · Filesystem and shell capabilities.
src/tau_coding/tools.py - Project resources · Discovers instructions, skills, prompts, and resources.
src/tau_coding/resources.py - System prompt builder
src/tau_coding/system_prompt.py - Context policy · Measures and compacts model context.
src/tau_coding/context.py - Extension runtime · Loads custom tools at the app boundary.
src/tau_coding/extensions/runtime.py - Provider runtime · Selects configured models and providers.
src/tau_coding/provider_runtime.py - Provider catalog · Bundled catalog plus user overrides.
src/tau_coding/provider_catalog.py - Credentials & OAuth
src/tau_coding/credentials.py
Portable Agent Core
- Agent harness · Provider-neutral reusable agent interface.
src/tau_agent/harness.py - Agent loop · Streams output, executes tools, appends results, and repeats.
src/tau_agent/loop.py - Typed agent events · Frontend boundary for agent progress and results.
src/tau_agent/events.py
Provider Adapters
- Provider protocol · Normalizes vendor APIs into typed streaming.
src/tau_ai/provider.py - Provider events
src/tau_agent/provider_events.py - Vendor adapters · Anthropic, Google, Mistral, OpenAI/Codex, and compatible services.
src/tau_ai/anthropic.py - HTTP & retry
src/tau_ai/http.py
Session Persistence
- Session tree · Append-only immutable conversation history.
src/tau_agent/session/tree.py - JSONL storage
src/tau_agent/session/jsonl.py
Connections 27
- 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