Open History to see the last commit
1# Provider architecture
2
3> For maintainers. Using T3 Code? See [docs/user](../user/).
4
5A provider is the agent runtime that does the actual work. T3 Code supports several, and the
6orchestration layer does not know which one is behind a thread.
7
8## Built-in drivers
9
10[`builtInDrivers.ts`][drivers] exports `BUILT_IN_DRIVERS` with five entries:
11
12| Driver kind | Driver source |
13| ------------- | --------------------------------------- |
14| `codex` | [`Drivers/CodexDriver.ts`][codex] |
15| `claudeAgent` | [`Drivers/ClaudeDriver.ts`][claude] |
16| `cursor` | [`Drivers/CursorDriver.ts`][cursor] |
17| `grok` | [`Drivers/GrokDriver.ts`][grok] |
18| `opencode` | [`Drivers/OpenCodeDriver.ts`][opencode] |
19
20Each driver declares its `driverKind`, a `configSchema`, and a `create` function that builds an
21adapter in a child scope. Adapter implementations live beside them in
22`apps/server/src/provider/Layers/` (`CodexAdapter.ts`, `ClaudeAdapter.ts`, and so on) and conform to
23[`ProviderAdapter.ts`][adapter]. Read the driver plus its adapter to see how a specific agent's
24transport, config, and event shapes are mapped.
25
26## Registry and routing
27
28Two registries separate configuration from live processes:
29
30- [`ProviderInstanceRegistry`][instances] keys configured instances by `ProviderInstanceId`. Creating
31 one looks up the driver by `driverKind`, decodes `entry.config` with that driver's schema, opens a
32 child scope, and calls `driver.create`.
33- [`ProviderAdapterRegistry`][registry] resolves an instance ID to its live adapter via
34 `getByInstance`.
35
36[`ProviderService`][service] sits on top. It combines the adapter registry with the provider session
37directory to route session and turn operations for a thread, so callers name a thread, not an agent.
38
39Adding a driver means writing the driver plus adapter and adding it to `BUILT_IN_DRIVERS`. No
40orchestration, contract, or client change is required for the common case.
41
42## Model manifest
43
44The model picker's legacy section is driven by `apps/server/src/provider/model-manifest.json`, which
45lists the current (non-legacy) model slugs per driver kind. The `ModelManifest` service
46(`apps/server/src/provider/ModelManifest.ts`) refreshes that data from the same file on `main` via
47raw.githubusercontent.com, so moving a model in or out of the legacy section is a commit, not a
48release. Preference order is remote fetch, then the on-disk copy of the last successful fetch (in
49the state directory), then the bundled copy. Fetches are TTL-gated, run concurrently with provider
50probes, respect the `enableProviderUpdateChecks` setting, and never fail a provider check. The
51Codex and Claude drivers apply the classification to every snapshot with `applyModelManifest`;
52driver kinds absent from the manifest have no legacy concept.
53
54## Attachment access
55
56The server stores uploaded attachments in its attachment directory, outside the project workspace.
57`ProviderService` adds the absolute path of each attachment to the turn text, then passes every
58attachment to the provider adapter. Each adapter decides what its provider ingests natively:
59
60- Codex, Claude, Cursor, and Grok send images as native image inputs and skip generic files. For
61 these providers, generic files reach the agent only as file paths in the turn text.
62- OpenCode sends PNG/JPEG/GIF/WebP images, text files, and PDFs up to 20 MB as native file parts
63 with their real mime type. Everything else (ZIP and other binaries, image formats model APIs
64 reject, oversized files) falls back to the file path in the turn text, like the other providers.
65
66Claude receives the attachment directory as an allowed additional directory. Codex keeps its
67configured sandbox policy, so access depends on that policy and the selected runtime mode. OpenCode
68allows all paths in full-access mode and requests approval for directories outside the workspace in
69restricted modes. Cursor and Grok use their own provider permission rules.
70
71The server does not copy attachments into a project or bypass provider approval rules. If an agent
72cannot read an attachment, the user must approve the access or select a runtime mode that permits it.
73
74Updated attachment schemas tolerate unknown attachment members, but old image-only clients still
75cannot decode messages that contain file attachments. Client file-picking rollouts must account for
76this limit.
77
78Do not run an old image-only server against state that contains file attachments. Replay decodes
79each persisted event before projection. A file-bearing event can make `ProjectionPipeline` bootstrap
80and `OrchestrationEngine` startup fail for the entire environment, not only the affected thread.
81
82## How provider work is requested
83
84Clients never call a provider directly. They dispatch orchestration commands over the RPC method
85`orchestration.dispatchCommand`, defined with the rest of the orchestration surface in
86[`orchestration.ts`][contracts]. The client-dispatchable provider-facing commands are
87`thread.turn.start`, `thread.turn.interrupt`, `thread.approval.respond`,
88`thread.user-input.respond`, `thread.checkpoint.revert`, and `thread.session.stop`, plus the mode
89setters `thread.runtime-mode.set` and `thread.interaction-mode.set`.
90
91The engine persists an event for the command, and a server-side reactor performs the provider call.
92Provider output comes back as internal commands such as `thread.message.assistant.delta` and
93`thread.session.set`, which clients observe through `orchestration.subscribeThread`. See
94[overview.md](./overview.md) for the command/event loop.
95
96## Server-side workers
97
98Provider work flows through three queue-backed workers. All three are built with
99`makeDrainableWorker` from [`DrainableWorker.ts`][worker] and expose `drain` for deterministic test
100synchronization.
101
1021. [`ProviderRuntimeIngestion`][ingest] consumes provider runtime streams and emits orchestration
103 commands.
1042. [`ProviderCommandReactor`][cmd] reacts to orchestration intent events and dispatches provider
105 calls.
1063. [`CheckpointReactor`][checkpoint] captures workspace checkpoints on turn start and completion, and
107 performs reverts.
108
109### Buffered assistant delivery
110
111A thread in `buffered` assistant delivery mode accumulates assistant text instead of streaming each
112delta. The buffer is not held until turn completion. In [`ProviderRuntimeIngestion`][ingest],
113`MAX_BUFFERED_ASSISTANT_CHARS` is 24,000: the append that would exceed it invalidates the buffer and
114spills the whole accumulated text as one delta. The buffer also flushes at interaction boundaries,
115when a request opens (approval) or user input is requested, via
116`flushBufferedAssistantMessagesForTurn`.
117
118[drivers]: ../../apps/server/src/provider/builtInDrivers.ts
119[codex]: ../../apps/server/src/provider/Drivers/CodexDriver.ts
120[claude]: ../../apps/server/src/provider/Drivers/ClaudeDriver.ts
121[cursor]: ../../apps/server/src/provider/Drivers/CursorDriver.ts
122[grok]: ../../apps/server/src/provider/Drivers/GrokDriver.ts
123[opencode]: ../../apps/server/src/provider/Drivers/OpenCodeDriver.ts
124[adapter]: ../../apps/server/src/provider/Services/ProviderAdapter.ts
125[instances]: ../../apps/server/src/provider/Services/ProviderInstanceRegistry.ts
126[registry]: ../../apps/server/src/provider/Services/ProviderAdapterRegistry.ts
127[service]: ../../apps/server/src/provider/Layers/ProviderService.ts
128[contracts]: ../../packages/contracts/src/orchestration.ts
129[worker]: ../../packages/shared/src/DrainableWorker.ts
130[ingest]: ../../apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts
131[cmd]: ../../apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
132[checkpoint]: ../../apps/server/src/orchestration/Layers/CheckpointReactor.ts