# How Agenvoy Uses go-llm-router

[Agenvoy](https://agenvoy.com/) is a local AI agent harness in Go that runs 24/7 on your own machine; every call it makes to a model provider goes through go-llm-router, and no vendor-specific code remains in its repository. This page maps each Agenvoy subsystem to the go-llm-router APIs it calls, based on the Agenvoy source.

## Origin

go-llm-router was extracted as a standalone package from Agenvoy commit [2741d4a](https://github.com/agenvoy/Agenvoy/commit/2741d4a3be70c5bfac1bba9e1d5d54a65db15acd); since Agenvoy v0.28.17, all of Agenvoy's LLM providers come from this package. Agenvoy currently depends on `github.com/pardnchiu/go-llm-router v0.10.5`, imported by 79 files in its source.

## Subsystem Map

| Agenvoy subsystem | Source | go-llm-router APIs used | Agenvoy docs |
| --- | --- | --- | --- |
| Model registry and chat | `internal/app/agentRegistry.go` | `router.New`, `router.Config`, `Agent.Send`, `StreamAgent.SendStream`, `ErrStreamUnsupported` | [Providers](https://agenvoy.com/providers) |
| Claude Code subscription | `internal/app/agentRegistry.go`, `internal/agents/keychain` | `EnableClaude`, `StateDir`, `claudeCode.Is`, `claudeCode.CheckBinary`, `WithSessionID`, `WithCacheTTL` | [Claude Code](https://agenvoy.com/providers-claude-code) |
| Subscription login and token refresh | `internal/runtime/tui/commandModelAdd.go`, `internal/runtime/routes/handler/providers.go`, `internal/agents/keychain` | `oauth/copilot.LoginWithCallback`, `oauth/codex.Login`, `oauth/grok.LoginWithCallback`, `EnsureFresh`, `EnsureFreshSession` | [Providers API](https://agenvoy.com/rest-api-providers) |
| Model listing | `internal/agents/probe` | each provider package's `Models` with `ModelFilter{TextOnly: true}`, `claudeCode.Models` | [Model routing](https://agenvoy.com/providers-routing) |
| Decision model | `internal/agents/decision` | `router.NewDecision`, `DecisionAgent.Decide`, `DecisionQuestion`, `typesafe.Models`, `ModelFilter{DecisionOnly: true}` | [TypeSafe](https://agenvoy.com/providers-typesafe) |
| Image generation | `internal/agents/image` | `router.New`, `ImageAgent.GenerateImage`, `ImageOptions` | [Providers](https://agenvoy.com/providers) |
| Speech to text / text to speech | `internal/agents/audio` | `router.New`, `Transcribe` + `STTOptions`, `Speak` | [Providers](https://agenvoy.com/providers) |
| Quota display | `internal/utils/event.go`, `internal/runtime/tui/commandProviderUsage.go` | `Usage` and `UsageRemaining` (`codex`, `grok-oauth`, `copilot`, `openrouter`, `deepseek`, `claude-code`) | [Providers API](https://agenvoy.com/rest-api-providers) |
| OpenAI-compatible API | `internal/runtime/routes/handler/chatCompletions` | `Message`, `ContentPart`, `ImageURL`, `Tool`, `ToolCall`, `Usage`, `ParseReasoning` | [REST API](https://agenvoy.com/rest-api) |

## Model Registry and Chat

Every Agenvoy model is a `resolvedAgent`: on each call it reads the API key, OAuth token, Cloudflare `AccountID`/`GatewayID`, or `BaseURL` for that `provider@model` from the keychain, builds a `router.Config`, and passes it to `router.New`. Adding or switching a model in Agenvoy is therefore just a different name, resolved by the same rules as [Model Routing](/core-concepts-routing).

- Regular replies use `Agent.Send`; streamed output first asserts `StreamAgent` and returns `ErrStreamUnsupported` when it fails, so Agenvoy falls back to the non-streaming path
- `router.Config` always sets `EnableClaude: true` and Agenvoy's sessions directory as `StateDir`
- At startup each model is built once with `router.New`; a model that fails to initialize is left out of the registry

## Claude Code Subscription

`claude-code@<model>` lets Agenvoy run on a Claude subscription without an API key (see [Claude Code](/core-concepts-claude-code)). Agenvoy adds two things on top:

- `claudeCode.CheckBinary` confirms the local `claude` CLI exists; without it the models are hidden
- `WithSessionID` passes the Agenvoy session ID so one conversation keeps one Claude Code process; when the session has a pinned model and reasoning level it also sets `WithCacheTTL(ctx, "1h")` (see [Sessions and Caching](/core-concepts-sessions))

## Subscription Login and Token Refresh

The TUI `/model add` picker and the REST `providers` handler share the same login functions: Copilot uses device code (`LoginWithCallback` hands a `DeviceCode` to the screen), while Codex and Grok open a browser authorization. Before each `router.Config` is built, the keychain refreshes the token with `EnsureFresh` (Codex, Grok) or `EnsureFreshSession` (Copilot). See [OAuth Tokens](/configuration-oauth) for the flow.

## Decision Model

Agenvoy hands yes/no questions such as "is this search result related to the goal" or "is this background command output worth reporting" to a decision model instead of the main chat model:

- Available models come from `typesafe.Models` and `openRouter.Models(..., ModelFilter{DecisionOnly: true})`
- `router.NewDecision` builds the `DecisionAgent`; `Decide` sends several questions at once, and only answers whose `Confidence` reaches the threshold are used
- It filters `search_web` and `fetch_page` content, judges file and history relevance, and watches background command output

See [Decisions](/core-concepts-decisions) for the types and results.

## Images and Speech

- Images: image models from `openai`, `codex`, `grok`, `grok-oauth`, `gemini`, and `openrouter`, built with `router.New` and called through `GenerateImage` (see [Image Generation](/core-concepts-images))
- Speech: STT/TTS models from `openai`, `gemini`, and `openrouter`, called through `Transcribe` and `Speak` (see [Speech](/core-concepts-speech))

## Quota Display

The remaining quota shown in the TUI and by `GET /v1/model/quota` and `GET /v1/providers/quota` comes from each provider package's `Usage`: a balance is shown as an amount, otherwise as 5-hour/week/total percentages. See [Quota](/configuration-quota) for what each value means.

## OpenAI-compatible API

Agenvoy serves `POST /v1/chat/completions`; the request body decodes straight into go-llm-router's `Message` and `Tool` types, `reasoning_effort` is validated with `ParseReasoning`, and the streamed `Usage` and `ToolCall` reuse the same types. Any OpenAI-compatible client can therefore reach every provider go-llm-router supports through Agenvoy. See [Message Types](/api-reference-messages) for the types.
