How Agenvoy Uses go-llm-router
Last updated
Agenvoy 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; 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 |
| Claude Code subscription | internal/app/agentRegistry.go, internal/agents/keychain | EnableClaude, StateDir, claudeCode.Is, claudeCode.CheckBinary, WithSessionID, WithCacheTTL | 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 |
| Model listing | internal/agents/probe | each provider package's Models with ModelFilter{TextOnly: true}, claudeCode.Models | Model routing |
| Decision model | internal/agents/decision | router.NewDecision, DecisionAgent.Decide, DecisionQuestion, typesafe.Models, ModelFilter{DecisionOnly: true} | TypeSafe |
| Image generation | internal/agents/image | router.New, ImageAgent.GenerateImage, ImageOptions | Providers |
| Speech to text / text to speech | internal/agents/audio | router.New, Transcribe + STTOptions, Speak | 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 |
| OpenAI-compatible API | internal/runtime/routes/handler/chatCompletions | Message, ContentPart, ImageURL, Tool, ToolCall, Usage, ParseReasoning | 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.- Regular replies use
Agent.Send; streamed output first assertsStreamAgentand returnsErrStreamUnsupportedwhen it fails, so Agenvoy falls back to the non-streaming path router.Configalways setsEnableClaude: trueand Agenvoy's sessions directory asStateDir- 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). Agenvoy adds two things on top:claudeCode.CheckBinaryconfirms the localclaudeCLI exists; without it the models are hiddenWithSessionIDpasses the Agenvoy session ID so one conversation keeps one Claude Code process; when the session has a pinned model and reasoning level it also setsWithCacheTTL(ctx, "1h")(see Sessions and Caching)
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 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.ModelsandopenRouter.Models(..., ModelFilter{DecisionOnly: true}) router.NewDecisionbuilds theDecisionAgent;Decidesends several questions at once, and only answers whoseConfidencereaches the threshold are used- It filters
search_webandfetch_pagecontent, judges file and history relevance, and watches background command output
See Decisions for the types and results.
Images and Speech
- Images: image models from
openai,codex,grok,grok-oauth,gemini, andopenrouter, built withrouter.Newand called throughGenerateImage(see Image Generation) - Speech: STT/TTS models from
openai,gemini, andopenrouter, called throughTranscribeandSpeak(see 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 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 for the types.