bamboo_server/server_tools/surface.rs
1//! Tool surface selection semantics.
2//!
3//! Different session types require different tool sets. This module provides
4//! an enum-based way to select the appropriate tool surface at execution time.
5
6use std::sync::Arc;
7
8use bamboo_agent_core::tools::ToolExecutor;
9
10/// Tool surface variants for different session types.
11///
12/// | Surface | Base | +SubSession | +ScheduleTasks | +SubSessionManager | +SessionInspector |
13/// |----------|------|-------------|----------------|--------------------|--------------------|
14/// | Base | ✓ | | | | |
15/// | Child | ✓ | | | | |
16/// | WithTask | ✓ | ✓ | | | |
17/// | Root | ✓ | ✓ | ✓ | ✓ | ✓ |
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum ToolSurface {
20 /// Base tool set: builtin + MCP + memory + skills.
21 /// Used by the agent runtime as default_tools.
22 Base,
23 /// Same as Base — child sessions cannot recursively spawn.
24 Child,
25 /// Base + SubSession tool — used by schedule runs.
26 WithTask,
27 /// Full root tool set: WithTask + ScheduleTasks + SubSessionManager + SessionInspector.
28 Root,
29}
30
31/// Factory that provides pre-built tool executors for each surface variant.
32///
33/// Constructed once during `AppState` initialization. Call sites
34/// obtain the appropriate executor by calling [`ToolSurfaceFactory::get`].
35#[derive(Clone)]
36pub struct ToolSurfaceFactory {
37 base: Arc<dyn ToolExecutor>,
38 with_task: Arc<dyn ToolExecutor>,
39 root: Arc<dyn ToolExecutor>,
40}
41
42impl ToolSurfaceFactory {
43 /// Create a factory from pre-built tool executors.
44 pub fn new(
45 base: Arc<dyn ToolExecutor>,
46 with_task: Arc<dyn ToolExecutor>,
47 root: Arc<dyn ToolExecutor>,
48 ) -> Self {
49 Self {
50 base,
51 with_task,
52 root,
53 }
54 }
55
56 /// Return the tool executor for the requested surface.
57 ///
58 /// Child and Base both return the same underlying executor.
59 pub fn get(&self, surface: ToolSurface) -> Arc<dyn ToolExecutor> {
60 match surface {
61 ToolSurface::Base => self.base.clone(),
62 ToolSurface::Child => self.base.clone(),
63 ToolSurface::WithTask => self.with_task.clone(),
64 ToolSurface::Root => self.root.clone(),
65 }
66 }
67}