1use monoloop_contracts::ToolExecutionId;
4use tokio::sync::oneshot;
5
6#[derive(Clone, Debug)]
8pub struct StartToolExecution {
9 pub execution_id: ToolExecutionId,
11 pub tool_action_id: String,
13 pub tool_name: String,
15 pub request_payload: String,
17 pub request_generation: u64,
19}
20
21#[derive(Clone, Debug, thiserror::Error)]
23#[error("tool runtime: {0}")]
24pub struct ToolRuntimeError(pub String);
25
26#[derive(Clone, Debug)]
28pub struct ToolRuntimeTerminal {
29 pub outcome: monoloop_contracts::OutboundToolOutcome,
31 pub payload: String,
33}
34
35#[derive(Debug)]
37pub struct ToolExecutionHandle {
38 pub execution_id: ToolExecutionId,
40 pub completion: Option<oneshot::Receiver<ToolRuntimeTerminal>>,
42}
43
44pub trait ToolRuntime: Send + Sync {
46 fn start(&self, request: StartToolExecution) -> Result<ToolExecutionHandle, ToolRuntimeError>;
48}
49
50#[derive(Clone, Debug, Default)]
52pub struct NoToolRuntime;
53
54impl NoToolRuntime {
55 pub fn new() -> Self {
57 Self
58 }
59}
60
61impl ToolRuntime for NoToolRuntime {
62 fn start(&self, _request: StartToolExecution) -> Result<ToolExecutionHandle, ToolRuntimeError> {
63 Err(ToolRuntimeError(
64 "NoToolRuntime.start must never be called with EmptyToolRegistry".into(),
65 ))
66 }
67}