(session: &AgentSession)
| 9 | use std::sync::Arc; |
| 10 | |
| 11 | pub(super) fn build_agent_loop(session: &AgentSession) -> AgentLoop { |
| 12 | let mut config = session.config.clone(); |
| 13 | config.hook_engine = Some(match &session.ahp_executor { |
| 14 | Some(ahp) => ahp.clone(), |
| 15 | None => Arc::clone(&session.hook_engine) as Arc<dyn crate::hooks::HookExecutor>, |
| 16 | }); |
| 17 | |
| 18 | // Dynamic MCP additions mutate the executor after session construction, so |
| 19 | // every run snapshots live definitions instead of using the stale config copy. |
| 20 | config.tools = session.tool_executor.definitions(); |
| 21 | |
| 22 | // Runtime budget-guard override (set via AgentSession::set_budget_guard) |
| 23 | // takes precedence over the value baked in at session-build time. |
| 24 | // Used by Node SDK where the JS callable cannot live inside |
| 25 | // value-typed SessionOptions. |
| 26 | if let Some(runtime_guard) = session.budget_guard() { |
| 27 | config.budget_guard = Some(runtime_guard); |
| 28 | } |
| 29 | |
| 30 | let mut agent_loop = AgentLoop::new( |
| 31 | session.llm_client.clone(), |
| 32 | session.tool_executor.clone(), |
| 33 | session.tool_context.clone(), |
| 34 | config, |
| 35 | ); |
| 36 | if let Some(queue) = &session.command_queue { |
| 37 | agent_loop = agent_loop.with_queue(Arc::clone(queue)); |
| 38 | } |
| 39 | // Wire per-tool-round checkpointing when the session has a store. |
| 40 | // The run id is bound later by the caller via |
| 41 | // `AgentLoop::set_checkpoint_run` once `start_run` returns. |
| 42 | if let Some(store) = &session.session_store { |
| 43 | let sink = std::sync::Arc::new(crate::loop_checkpoint::SessionStoreCheckpointSink::new( |
| 44 | std::sync::Arc::clone(store), |
| 45 | )); |
| 46 | agent_loop = agent_loop.with_checkpoint_sink(sink); |
| 47 | } |
| 48 | agent_loop |
| 49 | } |
no test coverage detected