v0.10.5

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 subsystemSourcego-llm-router APIs usedAgenvoy docs
Model registry and chatinternal/app/agentRegistry.gorouter.New, router.Config, Agent.Send, StreamAgent.SendStream, ErrStreamUnsupportedProviders
Claude Code subscriptioninternal/app/agentRegistry.go, internal/agents/keychainEnableClaude, StateDir, claudeCode.Is, claudeCode.CheckBinary, WithSessionID, WithCacheTTLClaude Code
Subscription login and token refreshinternal/runtime/tui/commandModelAdd.go, internal/runtime/routes/handler/providers.go, internal/agents/keychainoauth/copilot.LoginWithCallback, oauth/codex.Login, oauth/grok.LoginWithCallback, EnsureFresh, EnsureFreshSessionProviders API
Model listinginternal/agents/probeeach provider package's Models with ModelFilter{TextOnly: true}, claudeCode.ModelsModel routing
Decision modelinternal/agents/decisionrouter.NewDecision, DecisionAgent.Decide, DecisionQuestion, typesafe.Models, ModelFilter{DecisionOnly: true}TypeSafe
Image generationinternal/agents/imagerouter.New, ImageAgent.GenerateImage, ImageOptionsProviders
Speech to text / text to speechinternal/agents/audiorouter.New, Transcribe + STTOptions, SpeakProviders
Quota displayinternal/utils/event.go, internal/runtime/tui/commandProviderUsage.goUsage and UsageRemaining (codex, grok-oauth, copilot, openrouter, deepseek, claude-code)Providers API
OpenAI-compatible APIinternal/runtime/routes/handler/chatCompletionsMessage, ContentPart, ImageURL, Tool, ToolCall, Usage, ParseReasoningREST 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 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). 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)

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.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 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)
  • Speech: STT/TTS models from openai, gemini, and openrouter, called through Transcribe and Speak (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.
中文