Expand description
LLM transports for trusty-code.
Why: trusty-code agents invoke LLMs via OpenAI-compatible endpoints
(OpenRouter / Fireworks) and AWS Bedrock. Since #2406 (epic #2400) the
OpenAI-compatible HTTP mechanics live in the shared trusty_common::inference
adapter layer rather than a bespoke tcode client, so credential resolution,
error classification, and the wire schema are shared across the ecosystem.
What: Exports OpenAiCompatClient (shared OpenRouter/Fireworks transport),
DispatchingLlmClient (slug-routed transport), BedrockChatClient, all
request/response types (ChatRequest, ChatResponse, ChatMessage,
ToolDefinition, …), and LlmError. Credentials resolve via the shared
3-tier chain (env > .env.local > secure store) at first use.
Test: cargo test -p trusty-code covers serialisation, deserialisation,
type-conversion, and error-mapping unit tests plus the offline black-box
e2e (tests/inference_shared_adapter_e2e.rs). --include-ignored adds the
live provider tests.
LLM transports for trusty-code: the shared OpenAI-compatible adapter
(OpenRouter / Fireworks) and AWS Bedrock (Converse API).
Why: trusty-code agents need to invoke LLMs via OpenAI-compatible endpoints
(OpenRouter, and — since #2406 — Fireworks) OR, for organisations running on
AWS (#1021), via Bedrock’s Converse API. Both transports speak the same
provider-neutral ChatRequest/ChatResponse shape so AgentLoop and every
other caller never branches on the backend. The OpenAI-compatible HTTP
mechanics now live in the shared trusty_common::inference adapter layer
(epic #2400) rather than a bespoke tcode client — OpenAiCompatClient
(client) is the thin consumer of that core, bridged to tcode’s wire types
by convert.
What: This module exports OpenAiCompatClient (shared OpenRouter/Fireworks
transport), BedrockChatClient (Bedrock Converse), DispatchingLlmClient
(routes each request to the right transport by model slug via
crate::provider::provider_for), all request/response types (ChatRequest,
ChatResponse, ChatMessage, ToolDefinition, …), LlmError, and (#2264)
the opt-in debug_capture module — DebugCaptureSink +
wrap_with_debug_capture — that dumps the FULL wire-level request/response
of every round-trip to JSONL when TCODE_DEBUG_TRANSCRIPT is set.
OpenRouter/Fireworks credentials are resolved via the shared 3-tier chain
(process env > .env.local > secure store); Bedrock uses the standard AWS
credential chain (no key). Library helpers never read std::env for secrets
directly — resolution is centralised in the shared resolver.
Test: cargo test -p trusty-code covers all unit tests (serialisation,
deserialisation, type conversion + error mapping, Bedrock message/tool-choice/
response conversion, debug-capture) plus the offline black-box HTTP round-trip
in tests/inference_shared_adapter_e2e.rs. cargo test -p trusty-code -- --include-ignored additionally runs the live
live_openrouter_call/live_fireworks_call/live_bedrock_call tests.
Structs§
- Assistant
Message - The assistant message within a choice.
- Bedrock
Chat Client - AWS Bedrock Converse transport, backed by the shared inference adapter.
- Cache
Control - An Anthropic-style ephemeral prompt-cache breakpoint.
- Chat
Choice - One choice in the model response.
- Chat
Message - A single message in the chat conversation.
- Chat
Request - The full request body for
POST /v1/chat/completions. - Chat
Response - The top-level response from
POST /v1/chat/completions. - Debug
Capture Sink - Shared, thread-safe sink for one run’s debug-capture output.
- Dispatching
LlmClient - Routes each chat request to the Bedrock Converse transport or the shared OpenAI-compatible transport (OpenRouter / Fireworks), by model slug.
- Extracted
Tool Call - A tool call recovered by
ToolCallExtractor::extract, normalised across every extraction strategy and already schema-validated. - Function
Call - The function name and arguments within a tool call.
- Function
Definition - JSON Schema description of a callable function.
- Open
AiCompat Client - OpenAI-compatible transport over the shared inference adapter, routing OpenRouter and Fireworks by model slug.
- Request
Usage Config - OpenRouter’s request-side “return detailed usage” directive (response-side cache-usage fix).
- Schema
Violation - One schema-validation failure, with a JSON-pointer-like
pathfor context. - Tool
Call - A tool call emitted by the model.
- Tool
Call Extractor - Recovers and validates tool calls across every supported provider convention.
- Tool
Definition - A tool definition submitted with the request.
- Usage
Block - Token usage block from the API response.
Enums§
- Extraction
Strategy - Which extraction convention recovered a tool call.
- LlmError
- Error type returned by
LlmClientoperations. - Tool
Call Extract Error - Failure modes of tool-call extraction and validation.
Constants§
- DEFAULT_
MAX_ REPAIR_ ATTEMPTS - Default cap on corrective round-trips before giving up.
Traits§
- LlmClient
Trait - Object-safe interface for issuing a single chat-completions call.
Functions§
- extract_
with_ repair - Drive the bounded extract → (on failure) corrective-retry loop.
- strategy_
order_ for - Per-model fallback strategy order, tried when no native tool call is present.
- wrap_
with_ debug_ capture - Wrap
innerin debug capture whensinkis configured; otherwise returninnerUNCHANGED.