fix: agent usability improvements - unified schema casing, fixed silent handler failures, and made namespaces strictly optional
This commit is contained in:
1 parent
5dd413c397
commit
be85b58be4
3 files changed
+52
-15
No files matched your search
@@ -152,13 +152,25 @@ impl McpTool for CreateRelationsHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
||||
let req: CreateRelationsTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let mut missing_nodes = std::collections::HashSet::new();
|
||||
state.modify_graph(|g| {
|
||||
for relation in req.relations {
|
||||
if !relation.from.is_empty() && !relation.to.is_empty() {
|
||||
g.relations.push(relation);
|
||||
let from_exists = g.entities.contains_key(&relation.from);
|
||||
let to_exists = g.entities.contains_key(&relation.to);
|
||||
if from_exists && to_exists {
|
||||
g.relations.push(relation);
|
||||
} else {
|
||||
if !from_exists { missing_nodes.insert(relation.from); }
|
||||
if !to_exists { missing_nodes.insert(relation.to); }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if !missing_nodes.is_empty() {
|
||||
let missing: Vec<_> = missing_nodes.into_iter().collect();
|
||||
return Ok(format!("Warning: Relations dropped due to missing entities: {}", missing.join(", ")));
|
||||
}
|
||||
Ok("Relations created".to_string())
|
||||
}
|
||||
}
|
||||
@@ -177,13 +189,19 @@ impl McpTool for AddObservationsHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
||||
let req: AddObservationsTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let mut missing_entities = Vec::new();
|
||||
state.modify_graph(|g| {
|
||||
for o in req.observations {
|
||||
if let Some(e) = g.entities.get_mut(&o.entity_name) {
|
||||
e.observations.extend(o.contents);
|
||||
} else {
|
||||
missing_entities.push(o.entity_name);
|
||||
}
|
||||
}
|
||||
});
|
||||
if !missing_entities.is_empty() {
|
||||
return Ok(format!("Warning: Observations dropped for missing entities: {}", missing_entities.join(", ")));
|
||||
}
|
||||
Ok("Observations added".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user