Skip to content

Providers, Tool Plane & Scoping

This page covers how Hya talks to different LLM APIs (crates/hya-provider), loads and sandboxes tool paths (crates/hya-tool, crates/hya-tool-loader), and scopes bundles/plugins per Project (crates/hya-app).


1. Provider Routing & Stream Normalization (hya-provider)

Models vary wildly on the wire—OpenAI Chat Completions, OpenAI Responses (/responses), ChatGPT Codex OAuth, xAI Grok Build, Anthropic Messages, and Google Gemini each encode tool calls, reasoning blocks, prompt caching, and token counts differently.

hya-provider (R0) holds the Provider and Protocol traits, ProviderRouter, preflight, the one HTTP+SSE transport (HttpProvider), the bounded model-list discovery loop, and two providers: OpenAI-compatible Chat Completions (kind: openai) and the offline dev/fake providers. Every other wire is a provider kind a bundle registers through NativeRegistrations.providers (a ProviderKindEntry: the Protocol with its headers, compaction wire, and model-list adapter, plus an optional ProviderAuthFlow): hya/provider-anthropic, hya/provider-google, hya/provider-openai (Responses and Codex, sharing the hya-provider-openai-core wire with hya/provider-grok), and hya/provider-grok. hya_app::provider_kinds::load loads the enabled provider bundles once, before the providers resolve; the engine-time native load skips provider-only bundles. The router hides the wire differences:

  • Shared HTTP transport: The first HttpProvider request initializes the process-wide HTTP client and its TLS roots. Subsequent routes reuse the client and its connection pool.
  • One canonical event stream: Every upstream SSE stream decodes into the exact same hya_proto::Event sequence (StepStarted, ReasoningDelta, TextDelta, ToolCallRequested, UsageRecorded, MessageFinished).
  • Normalized token accounting: Across every vendor, TokenUsage.input excludes cached tokens (prompt_total = input + cache_read + cache_write) and output includes reasoning (thinking + visible + unknown == output).
  • Reasoning effort & model overrides: HttpProvider::with_model_reasoning_defaults installs per-model defaults from models.toml overrides. Provider::reasoning_default and Provider::supports_reasoning_effort resolve metadata from the first match in the router. Non-Workflow model refs accept #variant suffixes (stripped before upstream dispatch), while Workflow stage routes validate explicit reasoning: fields per candidate during admission.
  • Tool-result images: Images read by tools (png, jpeg, gif, webp) are attached only on the round immediately following the read call (up to 2 MiB per round) and replaced by a compact text note on subsequent rounds so history size doesn’t explode.

2. Native Bundle Tools & Lockstep ABI (hya-tool, hya-tool-loader)

The core keeps the five standard tools (read, write, edit, bash, grep) plus todo, rewrite, and skill. The official default profile supplies the native bundles for the other tools.

  • One load path: hya-tool-loader loads every native bundle the same way, first-party or installed (load_native_bundle): the library comes from beside the executable (load_v2) or from the installed package (load_v2_from_path), and its exported tools are registered from the bundle’s own resources.tools descriptors (schema_version: 2): visibility, default permission posture (read_only, task, tool, command, mcp), aliases, prompt hint, view, protected, file-operations rule, and overrides:. A tool registers under its own name; when two enabled bundles export one name, exactly one of them must declare overrides: (hya/hashline’s file tools declare overrides: hya/bare), or the load fails. No bundle id selects a branch.
  • Core tests load no first-party library: tests of hya-core, hya-tool, hya-tool-loader, and hya-engine use standard_registry(), in-test tools, or in-crate fixtures; a bundle’s behaviour is tested in its own crate or in Track P (see Testing).
  • Lockstep ABI guard: hya-tool-loader verifies a 32-byte ABI digest (abi_digest_v2 across all seventeen first-party native ABI v2 bundles: hya/hashline, hya/coding-extras, hya/multi-agent, hya/network, hya/agent-channels, hya/compaction, hya/plan, hya/goal, hya/loop, hya/workflow, hya/workspace-files, hya/session-title, hya/direct-shell, hya/provider-anthropic, hya/provider-google, hya/provider-openai, and hya/provider-grok) before calling registration, preventing mismatched .so/.dylib libraries from ever loading.
  • Slim single-agent ToolCtx (hya_tool::ToolCtx): Tool execution receives only core single-agent planes (workdir, roots, cancel, session, operation, permission, interaction, skills, artifacts, schemas: UriSchemaPlane, nested) plus extensions: ExtensionPlanes (a type-indexed container for optional planes such as the caller’s spawn roster Arc<[AgentDef]> and ParentSession). project_activity is a hya/coding-extras tool that reads the kernel’s HostSessionStore::project_changes; the core has no project-activity plane. Core hya-bare runs with an empty ExtensionPlanes and zero domain fields on ToolCtx.
  • LSP and formatting belong to hya/coding-extras: the bundle builds its LSP and formatter planes from its own config.toml and keeps them as private state for its lsp and apply_patch tools, its tool.execute.after post-edit hook, and its GET /lsp/symbols BundleApi; the core neither constructs nor injects them. The engine takes a tool call’s file capture (stamps and revert snapshot) after the tool.execute.after chain, so a file a hook rewrote (formatted) is recorded as that call’s own change, not as an external one.
  • Output caps: Every tool output passes through host envelope bounds (50 KiB coding text caps, 5,000-char default plugin/bundle caps with automatic spill to .hya/tool-output/ or artifact://) so one noisy command can never blow out a model’s context window.

3. Multi-Root ProjectScope & PermissionPlane

File tools (read, write, edit, ls, glob, find, grep, apply_patch, lsp) enforce workspace containment through hya_tool::ProjectScope:

  1. Every target path—and its nearest existing ancestor for not-yet-created files—is canonicalized on disk resolving all symlinks. A symlink inside your repo pointing to /etc/passwd resolves to /etc/passwd (outside!).
  2. If the canonical path sits inside any ordered root of the session’s Project, no outside-directory prompt is needed.
  3. Otherwise, ProjectScope raises an ExternalDirectory permission check for <canonical-parent-dir>/* before running the tool’s normal read/edit check. Saving Always allow scopes that grant strictly to the active project_id.

4. Lazy Per-Project CatalogScope (hya-app & hya-engine)

Because one persistent daemon serves many Projects on your machine, Hya never loads .hya/ folders from the directory hya server happened to start in.

Instead, RuntimeRegistry maintains an LRU + idle-TTL cache (catalog_scopes: { max: 32, idle_ttl_secs: 1800 }) keyed by CatalogScope:

  • Global: Built-in presets + user-installed bundles + global config.toml MCP/plugins + user skills/commands.
  • Directory(path): Adds disk skills/commands/AGENTS.md for an unregistered folder (never spawns untrusted project processes).
  • Project { id, roots }: Layers <root>/.hya/bundles and <root>/.hya/plugins across all roots of the registered Project (first root wins on ID collisions) on top of the user and built-in tiers. When a Project sits idle past idle_ttl_secs with no active turns, its project-scoped sidecar processes are cleanly stopped and reclaimed.