causa_runtime/driver/
runner.rs1use super::TurnOutcome;
4use crate::{ToolExecutor, TurnRunOptions};
5use causa_kernel::{CallControl, Context, ModelGateway, TurnId};
6use std::sync::Arc;
7
8pub struct TurnRunner {
15 pub(super) gateway: Arc<dyn ModelGateway>,
16 pub(super) executor: Arc<ToolExecutor>,
17}
18impl TurnRunner {
19 pub fn new(gateway: Arc<dyn ModelGateway>, executor: Arc<ToolExecutor>) -> Self {
21 Self { gateway, executor }
22 }
23
24 pub async fn run(
26 &self,
27 turn_id: TurnId,
28 context: Context,
29 options: TurnRunOptions,
30 control: CallControl,
31 ) -> TurnOutcome {
32 self.execute(turn_id, context, options, control, false)
33 .await
34 }
35 pub async fn run_streaming(
37 &self,
38 turn_id: TurnId,
39 context: Context,
40 options: TurnRunOptions,
41 control: CallControl,
42 ) -> TurnOutcome {
43 self.execute(turn_id, context, options, control, true).await
44 }
45 #[tracing::instrument(name = "agent.turn", skip_all, fields(turn_id = %turn_id.0, model = %options.model.0))]
46 async fn execute(
47 &self,
48 turn_id: TurnId,
49 mut context: Context,
50 options: TurnRunOptions,
51 control: CallControl,
52 streaming: bool,
53 ) -> TurnOutcome {
54 let (result, uncommitted_tool_batch) = self
55 .run_loop(&turn_id, &mut context, &options, &control, streaming)
56 .await;
57 TurnOutcome {
58 turn_id,
59 context,
60 result,
61 uncommitted_tool_batch,
62 }
63 }
64}