AGENTS.md
packages/opencode/src/session/llm/AGENTS.mdAGENTS.md
Quality
61/100
Scores the file, not the repository.Length
571 words
3 headings · 2 code blocksRepository
193k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# Session LLM Runtime Boundaries23`../llm.ts` is the opencode session LLM service. It owns opencode concerns: auth, config, model/provider resolution, plugins, permissions, telemetry headers, and runtime selection. It is the only file in this area that should know about the full session request shape.45This folder contains adapters behind that service boundary:67- `ai-sdk.ts` converts AI SDK `fullStream` parts into `@opencode-ai/llm` `LLMEvent`s. This is the default runtime path.8- `native-request.ts` converts opencode's normalized session input into a native `@opencode-ai/llm` `LLMRequest`. It does not execute requests.9- `native-runtime.ts` is the opt-in native runtime adapter. It decides whether a selected model is supported, builds the native request, bridges opencode tools into native executable tools, and delegates transport to `LLMClient` / `RequestExecutor`.1011## File Structure1213```txt14src/session/15 llm.ts session-owned orchestration and runtime selection16 llm/17 AGENTS.md boundary notes for the adapter layer18 ai-sdk.ts AI SDK fullStream -> @opencode-ai/llm LLMEvent adapter19 native-request.ts opencode/AI SDK-shaped input -> @opencode-ai/llm LLMRequest20 native-runtime.ts native runtime gate, tool bridge, and LLMClient handoff21```2223Integration points:2425- `../llm.ts` imports `LLMClient` from `@opencode-ai/llm/route`; native execution is the only path that calls it directly.26- `../llm.ts` imports `LLMAISDK` from `./llm/ai-sdk`; the AI SDK path still calls `streamText(...)` locally, then adapts `result.fullStream` into shared `LLMEvent`s.27- `../llm.ts` imports `LLMNativeRuntime` from `./llm/native-runtime`; this is the runtime-selection seam. Unsupported native requests return a reason and fall back to AI SDK.28- `native-runtime.ts` imports `LLMNative` from `./native-request`; this keeps request lowering separate from transport and tool execution.29- `native-request.ts` is the only adapter file that should construct `LLM.request(...)`, `LLM.model(...)`, `Message.*`, `SystemPart`, `ToolCallPart`, `ToolResultPart`, or `ToolDefinition` values from `@opencode-ai/llm`.30- `ai-sdk.ts` and `native-runtime.ts` both emit `@opencode-ai/llm` `LLMEvent`s so downstream session processing does not care which runtime handled the request.3132Keep new integration code on one of these seams. Avoid importing session services into `native-request.ts`; pass normalized data through `RequestInput` instead.3334## Runtime selection3536Both runtimes converge on the same `LLMEvent` stream consumed by the session processor. The gate is per-request: a single session can route some calls through native and fall back for others.3738```txt39 ╭───────────────────╮40╭───────────────────────────▶│ session processor │41│ ╰─────────┬─────────╯42│ │43│ │44│ │45│ ▼46│ ╭─────────────────────────╮47│ │ LLM.Service (../llm.ts) │48│ ╰────────────┬────────────╯49│ │50│ │51│ │52│ ▼53│ ╭───────────╮54│ ╭─╯ ╰─╮55│ │ native gate │56│ ╰─╮ ╭─╯57│ ╰─────┬─────╯58│ │59│ ╭────── no ──────┴─────── yes ────────╮60│ │ │61│ ▼ ▼62│ ╭───────────────────────────╮ ╭───────────────────╮63│ │ AI SDK │ │ native-runtime.ts │64│ │ streamText / generateText │ ╰────────┬──────────╯65│ ╰─────────────┬─────────────╯ │66│ │ │67│ ╭───╯ │68│ │ │69│ ▼ ▼70│ ╭───────────────────────╮ ╭────────────────────────────╮71│ │ ai-sdk.ts │ │ native-request.ts │72│ │ fullStream → LLMEvent │ │ session input → LLMRequest │73│ ╰──────────┬────────────╯ ╰──────────────┬─────────────╯74│ │ │75│ │ ╭───╯76│ │ │77│ ▼ ▼78│ ╭─────────────────╮ ╭─────────────────────────────╮79╰───────┤ LLMEvent stream │◀────────────┤ LLMClient · RequestExecutor │80 ╰─────────────────╯ ╰─────────────────────────────╯81```8283`native-runtime.ts` evaluates the gate and either bridges into `@opencode-ai/llm` or returns control so `llm.ts` can take the AI SDK path. Tool execution stays opencode-owned in both branches; only request lowering and transport differ.8485Safety boundary:8687- AI SDK remains the default.88- `OPENCODE_EXPERIMENTAL_NATIVE_LLM=true` or the umbrella `OPENCODE_EXPERIMENTAL=true` opts in. Native is not a global replacement.89- Native execution currently supports OpenAI, opencode-managed OpenAI-compatible, and Anthropic API-key paths backed by `@ai-sdk/openai`, `@ai-sdk/openai-compatible`, or `@ai-sdk/anthropic` catalog entries.90- Unsupported providers, OpenAI OAuth, and missing API-key cases fall back to AI SDK.91
Also in anomalyco/opencode
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| anomalyco/opencodepackages/core/src/tool/AGENTS.md · 193k | AGENTS.md | stylesecurity | 58/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/test/server/AGENTS.md · 193k | AGENTS.md | teststyleapi | 38/100 | 3 days ago | |
| anomalyco/opencodepackages/schema/AGENTS.md · 193k | AGENTS.md | styletypesdatabaseapi+1 | 65/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/AGENTS.md · 193k | AGENTS.md | styledatabaseapido-not | 81/100 | 3 days ago | |
| anomalyco/opencodeAGENTS.md · 193k | AGENTS.md | testlint-formatstyletypes+3 | 80/100 | 3 days ago | |
| anomalyco/opencodepackages/app/AGENTS.md · 193k | AGENTS.md | style | 56/100 | today | |
| anomalyco/opencodepackages/app/e2e/performance/AGENTS.md · 193k | AGENTS.md | no sections | 16/100 | 3 days ago | |
| anomalyco/opencodepackages/codemode/AGENTS.md · 193k | AGENTS.md | api | 43/100 | 3 days ago | |
| anomalyco/opencodepackages/desktop/AGENTS.md · 193k | AGENTS.md | no sections | 30/100 | today | |
| anomalyco/opencodepackages/effect-drizzle-sqlite/AGENTS.md · 193k | AGENTS.md | database | 38/100 | 3 days ago | |
| anomalyco/opencodepackages/llm/AGENTS.md · 193k | AGENTS.md | stylearchtesting-strategygit+1 | 57/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/src/server/routes/instance/httpapi/AGENTS.md · 193k | AGENTS.md | styleapi | 40/100 | 3 days ago | |
| anomalyco/opencodepackages/opencode/test/AGENTS.md · 193k | AGENTS.md | teststylearchtesting-strategy+1 | 81/100 | 3 days ago | |
| anomalyco/opencodepackages/session-ui/AGENTS.md · 193k | AGENTS.md | no sections | 30/100 | today | |
| anomalyco/opencodepackages/ui/AGENTS.md · 193k | AGENTS.md | no sections | 30/100 | today |
Diff against packages/core/src/tool/AGENTS.md Diff against packages/opencode/test/server/AGENTS.md Diff against packages/schema/AGENTS.md Diff against packages/opencode/AGENTS.md Diff against AGENTS.md Diff against packages/app/AGENTS.md Diff against packages/app/e2e/performance/AGENTS.md Diff against packages/codemode/AGENTS.md Diff against packages/desktop/AGENTS.md Diff against packages/effect-drizzle-sqlite/AGENTS.md Diff against packages/llm/AGENTS.md Diff against packages/opencode/src/server/routes/instance/httpapi/AGENTS.md Diff against packages/opencode/test/AGENTS.md Diff against packages/session-ui/AGENTS.md Diff against packages/ui/AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago |
