MCPcopy Index your code
hub / github.com/AI45Lab/Code / LlmClient

Interface LlmClient

core/src/llm/mod.rs:32–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30/// LLM client trait
31#[async_trait]
32pub trait LlmClient: Send + Sync {
33 /// Complete a conversation (non-streaming)
34 async fn complete(
35 &self,
36 messages: &[Message],
37 system: Option<&str>,
38 tools: &[ToolDefinition],
39 ) -> Result<LlmResponse>;
40
41 /// Complete a conversation with streaming
42 /// Returns a receiver for streaming events.
43 /// The cancel_token is checked during the HTTP request; if cancelled, the request is aborted.
44 async fn complete_streaming(
45 &self,
46 messages: &[Message],
47 system: Option<&str>,
48 tools: &[ToolDefinition],
49 cancel_token: CancellationToken,
50 ) -> Result<mpsc::Receiver<StreamEvent>>;
51
52 /// Report the strongest provider-native structured-output enforcement this
53 /// client supports. Used by [`structured`] to decide whether to force a
54 /// tool call, request a native `response_format`, or fall back to
55 /// prompt-and-parse. Defaults to no native support.
56 fn native_structured_support(&self) -> structured::NativeStructuredSupport {
57 structured::NativeStructuredSupport::None
58 }
59
60 /// Complete a conversation while honoring a structured-output directive
61 /// (forced `tool_choice` and/or native `response_format`).
62 ///
63 /// The default implementation ignores the directive and behaves exactly
64 /// like [`LlmClient::complete`], so existing clients keep working unchanged;
65 /// providers that support native structured output override this.
66 async fn complete_structured(
67 &self,
68 messages: &[Message],
69 system: Option<&str>,
70 tools: &[ToolDefinition],
71 _directive: &structured::StructuredDirective,
72 ) -> Result<LlmResponse> {
73 self.complete(messages, system, tools).await
74 }
75
76 /// Streaming counterpart of [`LlmClient::complete_structured`]. Defaults to
77 /// [`LlmClient::complete_streaming`], ignoring the directive.
78 async fn complete_streaming_structured(
79 &self,
80 messages: &[Message],
81 system: Option<&str>,
82 tools: &[ToolDefinition],
83 _directive: &structured::StructuredDirective,
84 cancel_token: CancellationToken,
85 ) -> Result<mpsc::Receiver<StreamEvent>> {
86 self.complete_streaming(messages, system, tools, cancel_token)
87 .await
88 }
89}

Callers

nothing calls this directly

Implementers 11

skill.rscore/src/tools/skill.rs
task.rscore/src/tools/task.rs
anthropic.rscore/src/llm/anthropic.rs
structured_tests.rscore/src/llm/structured_tests.rs
openai.rscore/src/llm/openai.rs
zhipu.rscore/src/llm/zhipu.rs
session_config.rscore/src/agent_api/session_config.rs
tests.rscore/src/agent_api/tests.rs
llm_planner.rscore/src/planning/llm_planner.rs
tests.rscore/src/agent/tests.rs
test_circuit_breaker_succeeds_if_llm_recoverscore/src/agent/extra_agent_tests.rs

Calls

no outgoing calls

Tested by

no test coverage detected