Expand description
SamplingLlmClient — LlmClient impl backed by an MCP client’s
sampling/createMessage capability.
Per the v0.9.0 design (docs/dev-log/0098-v0.9.0-implementation-plan.md
§6 “Sampling-backed LLM client” / MAJOR 1 + MAJOR 3 resolutions):
-
Steward holds an
Arc<dyn LlmClient>. WhenLlmConfig::McpSamplingis configured, the Steward’sLlmClientis aSamplingLlmClientconstructed at MCPinitializetime (when the live peer becomes available — theTenantHandle::steward_slotLATE-population path). -
SamplingLlmClient::complete()translates the workspace’sMessage→rmcp::SamplingMessage, callspeer.create_message(params).await, extracts the assistant’s text from the returnedCreateMessageResult, and emits a per-callAuditOperation::LlmSamplingCallrow through the tenant’sWriteHandle(lesson #30: sync in writer-actor tx for ACID). -
Privacy invariant: the audit
details_jsoncarries metadata only — model hint, message count, max_tokens, duration_ms, total prompt character count, output character count. The raw prompt content MUST NOT appear in the audit row. Pinned by [tests::audit_row_omits_raw_prompt_text]. -
Error paths land structured audit rows:
- Client refusal →
result = "forbidden",details_json.reason = "client_refused". - Timeout →
result = "error",details_json.reason = "timeout". - Other transport / malformed-response →
result = "error",details_json.reason = <category>.
- Client refusal →
-
Per-call rate-limit / coalescing is deferred to v0.9.0 P4 (
SamplingCoordinator). P2 wires the per-call path only.
Structs§
- Peer
Sampling Client - Production wrapper around
rmcp::Peer<RoleServer>. The Peer is cheap to clone (internallyArc-backed) and stays valid for the lifetime of the MCP session. - Sampling
LlmClient LlmClientimpl whosecomplete()calls back via the connected MCP client’s sampling capability.
Enums§
- Sampling
Error - Error surface for
SamplingClient::create_message. Combines the real rmcpServiceError(when wrapping a livePeer<RoleServer>) with [super::super::test_support::fake_mcp_client::FakeSamplingError] (when driving the fixture from tests).
Constants§
- DEFAULT_
SAMPLING_ TIMEOUT - Default per-call timeout. Drives the bounded wait around
peer.create_message; if the client refuses or stalls, the caller sees a structured timeout error instead of an indefinite hang.
Traits§
- Sampling
Client - Trait abstracting the
sampling/createMessageRPC. The production impl wrapsArc<Peer<RoleServer>>; the test impl is [super::super::test_support::fake_mcp_client::FakeMcpClient].
Functions§
- build_
sampling_ steward - v0.9.0 P2: build a sampling-backed
Arc<Steward>for a tenant that has resolvedLlmConfig::McpSamplingand just attached an MCP session.