Skip to main content

bamboo_agent/agent/skill/
mod.rs

1//! Agent skill management crate.
2
3pub mod context;
4pub mod store;
5pub mod types;
6
7pub use store::{SkillStore, SkillUpdate};
8pub use types::*;
9
10use std::collections::HashSet;
11use std::sync::Arc;
12
13/// Skill manager instance (convenience wrapper around SkillStore).
14#[derive(Clone)]
15pub struct SkillManager {
16    store: Arc<SkillStore>,
17}
18
19impl SkillManager {
20    /// Create a new skill manager with default configuration.
21    pub fn new() -> Self {
22        Self {
23            store: Arc::new(SkillStore::default()),
24        }
25    }
26
27    /// Create a new skill manager with custom configuration.
28    pub fn with_config(config: SkillStoreConfig) -> Self {
29        Self {
30            store: Arc::new(SkillStore::new(config)),
31        }
32    }
33
34    /// Initialize the manager.
35    pub async fn initialize(&self) -> SkillResult<()> {
36        self.store.initialize().await
37    }
38
39    /// Get the underlying store.
40    pub fn store(&self) -> &SkillStore {
41        &self.store
42    }
43
44    /// Build system prompt context from all skills.
45    pub async fn build_skill_context(&self, _chat_id: Option<&str>) -> String {
46        // Reload to get latest skills
47        let skills = self.store.list_skills(None, true).await;
48        log::info!("Building skill context with {} skill(s)", skills.len());
49        context::build_skill_context(&skills)
50    }
51
52    /// Get allowed tool refs from all skills.
53    pub async fn get_allowed_tools(&self, _chat_id: Option<&str>) -> Vec<String> {
54        // Reload to get latest skills
55        let skills = self.store.list_skills(None, true).await;
56
57        let mut tools: Vec<String> = skills
58            .into_iter()
59            .flat_map(|skill| skill.tool_refs)
60            .collect::<HashSet<_>>()
61            .into_iter()
62            .collect();
63
64        tools.sort();
65        tools
66    }
67}
68
69impl Default for SkillManager {
70    fn default() -> Self {
71        Self::new()
72    }
73}