MCPcopy Create free account
hub / github.com/AI45Lab/Code / resolve_session_llm_client

Function resolve_session_llm_client

core/src/agent_api/session_config.rs:31–82  ·  view source on GitHub ↗
(
    code_config: &CodeConfig,
    opts: &SessionOptions,
    session_id: Option<&str>,
)

Source from the content-addressed store, hash-verified

29}
30
31pub(super) fn resolve_session_llm_client(
32 code_config: &CodeConfig,
33 opts: &SessionOptions,
34 session_id: Option<&str>,
35) -> Result<Arc<dyn LlmClient>> {
36 // A host-supplied client overrides the provider-string factory entirely:
37 // the host owns the full Action-layer dependency (custom provider, replay
38 // client, proxy/audit wrapper). Config-based model resolution is bypassed.
39 if let Some(ref client) = opts.llm_client {
40 return Ok(Arc::clone(client));
41 }
42
43 let model_ref = if let Some(ref model) = opts.model {
44 model.as_str()
45 } else {
46 if opts.temperature.is_some() || opts.thinking_budget.is_some() {
47 tracing::warn!(
48 "temperature/thinking_budget set without model override - these will be ignored. \
49 Use with_model() to apply LLM parameter overrides."
50 );
51 }
52 code_config
53 .default_model
54 .as_deref()
55 .context("default_model must be set in 'provider/model' format")?
56 };
57
58 let (provider_name, model_id) = model_ref
59 .split_once('/')
60 .context("model format must be 'provider/model' (e.g., 'openai/gpt-4o')")?;
61
62 let mut llm_config = code_config
63 .llm_config(provider_name, model_id)
64 .with_context(|| {
65 format!("provider '{provider_name}' or model '{model_id}' not found in config")
66 })?;
67
68 if opts.model.is_some() {
69 if let Some(temp) = opts.temperature {
70 llm_config = llm_config.with_temperature(temp);
71 }
72 if let Some(budget) = opts.thinking_budget {
73 llm_config = llm_config.with_thinking_budget(budget);
74 }
75 }
76
77 if let Some(session_id) = session_id {
78 llm_config = llm_config.with_session_id(session_id);
79 }
80
81 Ok(crate::llm::create_client_with_config(llm_config))
82}
83
84pub(super) struct ResolvedSessionMemory {
85 pub(super) memory: Option<Arc<crate::memory::AgentMemory>>,

Callers 2

create_sessionFunction · 0.85
resume_sessionFunction · 0.85

Calls 8

contextMethod · 0.80
with_contextMethod · 0.80
llm_configMethod · 0.80
as_strMethod · 0.45
with_temperatureMethod · 0.45
with_thinking_budgetMethod · 0.45
with_session_idMethod · 0.45

Tested by

no test coverage detected