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

Method execute_llm_turn

core/src/agent/llm_turn.rs:18–73  ·  view source on GitHub ↗
(
        &self,
        state: &mut ExecutionLoopState,
        augmented_system: &Option<String>,
        effective_prompt: &str,
        session_id: Option<&str>,
        event_tx: &Option<mpsc::Se

Source from the content-addressed store, hash-verified

16
17impl AgentLoop {
18 pub(super) async fn execute_llm_turn(
19 &self,
20 state: &mut ExecutionLoopState,
21 augmented_system: &Option<String>,
22 effective_prompt: &str,
23 session_id: Option<&str>,
24 event_tx: &Option<mpsc::Sender<AgentEvent>>,
25 cancel_token: &tokio_util::sync::CancellationToken,
26 ) -> anyhow::Result<LlmTurnOutput> {
27 let turn = state.next_turn();
28 self.ensure_turn_can_start(turn, state, event_tx).await?;
29 self.emit_turn_start(turn, event_tx).await;
30
31 tracing::info!(
32 a3s.llm.streaming = event_tx.is_some(),
33 "LLM completion started"
34 );
35
36 self.fire_generate_start(session_id.unwrap_or(""), effective_prompt, augmented_system)
37 .await;
38
39 let llm_start = std::time::Instant::now();
40 let response = self
41 .call_llm_with_circuit_breaker(
42 turn,
43 &state.messages,
44 augmented_system.as_deref(),
45 session_id,
46 event_tx,
47 cancel_token,
48 )
49 .await?;
50
51 state.record_usage(&response.usage);
52 self.complete_llm_turn(
53 turn,
54 effective_prompt,
55 &response,
56 llm_start,
57 event_tx,
58 session_id,
59 )
60 .await;
61
62 state.messages.push(response.message.clone());
63 let tool_calls = response.tool_calls();
64 self.emit_turn_end(turn, &response, event_tx).await;
65 self.maybe_auto_compact(state, &response, session_id, event_tx)
66 .await;
67
68 Ok(LlmTurnOutput {
69 turn,
70 response,
71 tool_calls,
72 })
73 }
74
75 async fn ensure_turn_can_start(

Callers 1

execute_loop_innerMethod · 0.80

Calls 12

nowFunction · 0.85
next_turnMethod · 0.80
ensure_turn_can_startMethod · 0.80
emit_turn_startMethod · 0.80
fire_generate_startMethod · 0.80
record_usageMethod · 0.80
complete_llm_turnMethod · 0.80
tool_callsMethod · 0.80
emit_turn_endMethod · 0.80
maybe_auto_compactMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected