Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(ai): make ai toolset composition panic on fail (#2212)

Eric Hayes6e2ec00ebf85
diff --git a/rust/cloud-storage/ai_tools/src/lib.rs b/rust/cloud-storage/ai_tools/src/lib.rs
index 048f4f9ff5..b582eefeea 100644
--- a/rust/cloud-storage/ai_tools/src/lib.rs
+++ b/rust/cloud-storage/ai_tools/src/lib.rs
@@ -41,17 +41,10 @@ impl ToolSchemaGenerator for ToolSetWithPrompt {
pub fn all_tools() -> ToolSetWithPrompt {
let toolset = AsyncToolSet::new()
.add_toolset(search_toolset())
- .expect("failed to add search toolset")
- // .add_toolset(list_toolset())
- // .expect("failed to add list toolset")
.add_tool::<ListEntities, SoupToolContext<ToolSoupService>>()
- .expect("failed to add list entities tool")
.add_tool::<read::ReadThread, Arc<ToolScribe>>()
- .expect("read thread tool")
.add_subtoolset::<ToolDocumentToolContext>(document_toolset())
- .expect("failed to add document toolset")
- .add_subtoolset::<ToolPropertiesToolContext>(properties_toolset())
- .expect("failed to add properties toolset");
+ .add_subtoolset::<ToolPropertiesToolContext>(properties_toolset());
let prompt = prompts::TOOLS_PROMPT;
let toolset = Arc::new(toolset);
ToolSetWithPrompt { toolset, prompt }
diff --git a/rust/cloud-storage/ai_tools/src/search/mod.rs b/rust/cloud-storage/ai_tools/src/search/mod.rs
index 8107285486..48fbf2e7ed 100644
--- a/rust/cloud-storage/ai_tools/src/search/mod.rs
+++ b/rust/cloud-storage/ai_tools/src/search/mod.rs
@@ -7,7 +7,5 @@ pub mod web;
pub fn search_toolset() -> AiToolSet {
AsyncToolSet::new()
.add_tool::<search_service::name::NameSearch, _>()
- .expect("failed to add name search tool")
.add_tool::<search_service::content::ContentSearch, _>()
- .expect("failed to add content search tool")
}
diff --git a/rust/cloud-storage/ai_toolset/src/lib.rs b/rust/cloud-storage/ai_toolset/src/lib.rs
index bc5f3d5be2..3e2daea5c4 100644
--- a/rust/cloud-storage/ai_toolset/src/lib.rs
+++ b/rust/cloud-storage/ai_toolset/src/lib.rs
@@ -73,8 +73,8 @@
//!
//! // Build toolset with tools using different contexts
//! let toolset = AsyncToolSet::<AppContext>::new()
-//! .add_tool::<ReadDocumentTool, Arc<dyn DocumentApi>>().unwrap()
-//! .add_tool::<UpdatePropertyTool, Arc<dyn PropertyApi>>().unwrap();
+//! .add_tool::<ReadDocumentTool, Arc<dyn DocumentApi>>()
+//! .add_tool::<UpdatePropertyTool, Arc<dyn PropertyApi>>();
//! ```
//!
//! # Nested Toolsets
@@ -118,11 +118,11 @@
//!
//! // Build a subtoolset with the narrower context
//! let sub_toolset = AsyncToolSet::<SubContext>::new()
-//! .add_tool::<SubTool, SubContext>().unwrap();
+//! .add_tool::<SubTool, SubContext>();
//!
//! // Merge into parent toolset - tools are automatically widened
//! let parent_toolset = AsyncToolSet::<ParentContext>::new()
-//! .add_subtoolset::<SubContext>(sub_toolset).unwrap();
+//! .add_subtoolset::<SubContext>(sub_toolset);
//!
//! assert!(parent_toolset.tools.contains_key("SubTool"));
//! ```
diff --git a/rust/cloud-storage/ai_toolset/src/toolset/types.rs b/rust/cloud-storage/ai_toolset/src/toolset/types.rs
index dc482ecdf3..fb717290a8 100644
--- a/rust/cloud-storage/ai_toolset/src/toolset/types.rs
+++ b/rust/cloud-storage/ai_toolset/src/toolset/types.rs
@@ -82,14 +82,14 @@ impl<T> ToolSet<T> {
/// Merges another toolset into this one.
///
/// Returns an error if any tool names conflict between the two toolsets.
- pub fn add_toolset(mut self, toolset: ToolSet<T>) -> Result<Self, ToolSetCreationError> {
+ pub fn add_toolset(mut self, toolset: ToolSet<T>) -> Self {
for (name, _) in toolset.tools.iter() {
if self.tools.contains_key(name) {
- return Err(ToolSetCreationError::NameConflict(name.clone()));
+ panic!("{}", ToolSetCreationError::NameConflict(name.clone()));
}
}
self.tools.extend(toolset.tools);
- Ok(self)
+ self
}
}
@@ -105,34 +105,40 @@ where
/// can be narrowed to the specific context required by each tool.
///
/// Returns an error if schema validation fails or a tool with the same name exists.
- pub fn add_tool<T, ToolContext>(mut self) -> Result<Self, ToolSetCreationError>
+ pub fn add_tool<T, ToolContext>(mut self) -> Self
where
ToolContext: Sync + Send + FromRef<ToolSetContext> + 'static,
T: JsonSchema + AsyncTool<ToolContext> + for<'de> Deserialize<'de> + 'static + Send + Sync,
T::Output: Serialize + JsonSchema + 'static,
{
let tool_object = AsyncToolObject::try_from_tool::<T, ToolContext, T::Output>()
- .map_err(ToolSetCreationError::Validation)?;
+ .expect("expect conversion to AsyncToolObject");
if self.tools.contains_key(&tool_object.name) {
- Err(ToolSetCreationError::NameConflict(tool_object.name.clone()))
+ panic!(
+ "{}",
+ ToolSetCreationError::NameConflict(tool_object.name.clone())
+ );
} else {
self.tools.insert(tool_object.name.clone(), tool_object);
- Ok(self)
+ self
}
}
/// Adds a user tool to the toolset
/// A user tool isn't executed automatically by default
- pub fn add_user_tool<T, ToolContext>(mut self) -> Result<Self, ToolSetCreationError>
+ pub fn add_user_tool<T, ToolContext>(mut self) -> Self
where
ToolContext: Sync + Send + FromRef<ToolSetContext> + 'static,
T: JsonSchema + AsyncTool<ToolContext> + for<'de> Deserialize<'de> + 'static + Send + Sync,
T::Output: Serialize + JsonSchema + 'static,
{
let tool_object = AsyncToolObject::try_from_tool::<T, ToolContext, T::Output>()
- .map_err(ToolSetCreationError::Validation)?;
+ .expect("conversion to AsyncToolObject");
if self.user_tools.contains_key(&tool_object.name) {
- return Err(ToolSetCreationError::NameConflict(tool_object.name.clone()));
+ panic!(
+ "{}",
+ ToolSetCreationError::NameConflict(tool_object.name.clone())
+ );
} else {
self.user_tools
.insert(tool_object.name.clone(), tool_object);
@@ -231,28 +237,26 @@ where
///
/// // Build a subtoolset with the narrower context
/// let sub_toolset = AsyncToolSet::<SubContext>::new()
- /// .add_tool::<SubTool, SubContext>().unwrap();
+ /// .add_tool::<SubTool, SubContext>();
///
/// // Merge into parent toolset - tools are automatically widened
/// let parent_toolset = AsyncToolSet::<ParentContext>::new()
- /// .add_subtoolset::<SubContext>(sub_toolset).unwrap();
+ /// .add_subtoolset::<SubContext>(sub_toolset);
///
/// assert!(parent_toolset.tools.contains_key("SubTool"));
/// ```
- pub fn add_subtoolset<SubContext>(
- mut self,
- subtoolset: AsyncToolSet<SubContext>,
- ) -> Result<Self, ToolSetCreationError>
+ #[tracing::instrument(skip_all)]
+ pub fn add_subtoolset<SubContext>(mut self, subtoolset: AsyncToolSet<SubContext>) -> Self
where
SubContext: FromRef<ToolSetContext> + Send + Sync + 'static,
{
for (name, tool) in subtoolset.tools {
if self.tools.contains_key(&name) {
- return Err(ToolSetCreationError::NameConflict(name));
+ panic!("{}", ToolSetCreationError::NameConflict(name));
}
let widened = tool.widen::<ToolSetContext>();
self.tools.insert(name, widened);
}
- Ok(self)
+ self
}
}
diff --git a/rust/cloud-storage/documents/src/inbound/toolset/mod.rs b/rust/cloud-storage/documents/src/inbound/toolset/mod.rs
index 0233f75a78..4949458e2d 100644
--- a/rust/cloud-storage/documents/src/inbound/toolset/mod.rs
+++ b/rust/cloud-storage/documents/src/inbound/toolset/mod.rs
@@ -58,9 +58,6 @@ where
{
AsyncToolSet::new()
.add_tool::<ReadMetadata, DocumentToolContext<DSvc, ESvc>>()
- .expect("failed to add ReadMetadata tool")
.add_tool::<ReadContent, DocumentToolContext<DSvc, ESvc>>()
- .expect("failed to add ReadContent tool")
.add_tool::<CreateDocument, DocumentToolContext<DSvc, ESvc>>()
- .expect("failed to add CreateDocument tool")
}
diff --git a/rust/cloud-storage/email/src/inbound/toolset/mod.rs b/rust/cloud-storage/email/src/inbound/toolset/mod.rs
index 117f91f4a8..64b011de79 100644
--- a/rust/cloud-storage/email/src/inbound/toolset/mod.rs
+++ b/rust/cloud-storage/email/src/inbound/toolset/mod.rs
@@ -98,11 +98,7 @@ where
{
AsyncToolSet::new()
.add_tool::<ListLabels, EmailToolContext<T, G, E>>()
- .expect("failed to add ListLabels tool")
.add_tool::<UpdateThreadLabels, EmailToolContext<T, G, E>>()
- .expect("failed to add UpdateThreadLabels tool")
.add_tool::<CreateDraft, EmailToolContext<T, G, E>>()
- .expect("failed to add CreateDraft tool")
.add_tool::<GetThread, EmailToolContext<T, G, E>>()
- .expect("failed to add GetThread tool")
}
diff --git a/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs b/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs
index 9b2fc6370d..bdd8ca50a1 100644
--- a/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs
+++ b/rust/cloud-storage/notification/src/inbound/ai_tool/mod.rs
@@ -53,11 +53,8 @@ where
{
AsyncToolSet::new()
.add_tool::<ListNotifications, NotificationToolContext<T>>()
- .expect("failed to add ListNotifications tool")
.add_tool::<MarkNotificationsSeen, NotificationToolContext<T>>()
- .expect("failed to add MarkNotificationsSeen tool")
.add_tool::<MarkNotificationsDone, NotificationToolContext<T>>()
- .expect("failed to add MarkNotificationsDone tool")
}
/// List the current user's active notifications.
diff --git a/rust/cloud-storage/properties/src/inbound/toolset/mod.rs b/rust/cloud-storage/properties/src/inbound/toolset/mod.rs
index de999bd2f1..1619a9975f 100644
--- a/rust/cloud-storage/properties/src/inbound/toolset/mod.rs
+++ b/rust/cloud-storage/properties/src/inbound/toolset/mod.rs
@@ -43,7 +43,5 @@ where
{
AsyncToolSet::new()
.add_tool::<GetEntityProperties, PropertiesToolContext<T>>()
- .expect("failed to add GetEntityProperties tool")
.add_tool::<SetEntityProperty, PropertiesToolContext<T>>()
- .expect("failed to add SetEntityProperty tool")
}
diff --git a/rust/cloud-storage/soup/src/inbound/toolset/mod.rs b/rust/cloud-storage/soup/src/inbound/toolset/mod.rs
index f880c72bdb..c30d7a62d1 100644
--- a/rust/cloud-storage/soup/src/inbound/toolset/mod.rs
+++ b/rust/cloud-storage/soup/src/inbound/toolset/mod.rs
@@ -39,7 +39,5 @@ pub fn soup_toolset<T>() -> AsyncToolSet<SoupToolContext<T>>
where
T: SoupService,
{
- AsyncToolSet::new()
- .add_tool::<ListEntities, SoupToolContext<T>>()
- .expect("failed to add ListEntities tool")
+ AsyncToolSet::new().add_tool::<ListEntities, SoupToolContext<T>>()
}