feat: 重命名工具名称,简化工具调用接口

This commit is contained in:
oudecheng 2026-05-19 15:18:04 +08:00
parent e62424d130
commit 8f82009c32
9 changed files with 27 additions and 21 deletions

View File

@ -573,7 +573,7 @@ mod tests {
},
ToolCall {
id: "call-2".to_string(),
name: "file_read".to_string(),
name: "read".to_string(),
arguments: json!({"path": "README.md"}),
},
],
@ -599,10 +599,10 @@ mod tests {
outbound[0].content,
"calculator\nargs: {\"expression\":\"1 + 1\"}"
);
assert_eq!(outbound[1].tool_name.as_deref(), Some("file_read"));
assert_eq!(outbound[1].tool_name.as_deref(), Some("read"));
assert_eq!(
outbound[1].content,
"file_read\nargs: {\"path\":\"README.md\"}"
"read\nargs: {\"path\":\"README.md\"}"
);
}

View File

@ -140,9 +140,9 @@ fn default_task_ttl_hours() -> u64 {
fn default_task_allowed_tools() -> Vec<String> {
vec![
"file_read".to_string(),
"file_edit".to_string(),
"file_write".to_string(),
"read".to_string(),
"edit".to_string(),
"write".to_string(),
"bash".to_string(),
"http_request".to_string(),
"web_fetch".to_string(),

View File

@ -697,6 +697,7 @@ mod tests {
HashSet::new(),
"Asia/Shanghai".to_string(),
HashSet::new(),
Default::default(),
)
.build(),
);
@ -744,6 +745,7 @@ mod tests {
HashSet::new(),
"Asia/Shanghai".to_string(),
HashSet::new(),
Default::default(),
)
.build(),
);
@ -1693,6 +1695,7 @@ mod tests {
HashSet::new(),
"Asia/Shanghai".to_string(),
HashSet::new(),
Default::default(),
)
.build(),
);
@ -1732,6 +1735,7 @@ mod tests {
HashSet::new(),
"Asia/Shanghai".to_string(),
HashSet::new(),
Default::default(),
)
.build(),
);
@ -1804,6 +1808,7 @@ mod tests {
HashSet::new(),
"Asia/Shanghai".to_string(),
HashSet::new(),
Default::default(),
)
.build(),
);
@ -1855,6 +1860,7 @@ mod tests {
HashSet::new(),
"Asia/Shanghai".to_string(),
HashSet::new(),
Default::default(),
)
.build();

View File

@ -72,13 +72,13 @@ impl ToolRegistryFactory {
if self.is_enabled("get_time") {
registry.register(TimeTool::new(self.default_timezone.clone()));
}
if self.is_enabled("file_read") {
if self.is_enabled("read") {
registry.register(FileReadTool::new());
}
if self.is_enabled("file_write") {
if self.is_enabled("write") {
registry.register(FileWriteTool::new());
}
if self.is_enabled("file_edit") {
if self.is_enabled("edit") {
registry.register(FileEditTool::new());
}
if self.is_enabled("memory_search") {
@ -144,13 +144,13 @@ impl ToolRegistryFactory {
if self.is_enabled("get_time") {
registry.register(TimeTool::new(self.default_timezone.clone()));
}
if self.is_enabled("file_read") {
if self.is_enabled("read") {
registry.register(FileReadTool::new());
}
if self.is_enabled("file_write") {
if self.is_enabled("write") {
registry.register(FileWriteTool::new());
}
if self.is_enabled("file_edit") {
if self.is_enabled("edit") {
registry.register(FileEditTool::new());
}
if self.is_enabled("bash") {

View File

@ -2228,7 +2228,7 @@ mod tests {
let store = SessionStore::in_memory().unwrap();
let session = store.create_cli_session(Some("tool-result")).unwrap();
let tool_message = ChatMessage::tool("call_9", "file_write", "saved to /tmp/output.txt");
let tool_message = ChatMessage::tool("call_9", "write", "saved to /tmp/output.txt");
store.append_message(&session.id, &tool_message).unwrap();
let messages = store.load_messages(&session.id).unwrap();
@ -2236,7 +2236,7 @@ mod tests {
assert_eq!(messages[0].role, "tool");
assert_eq!(messages[0].content, "saved to /tmp/output.txt");
assert_eq!(messages[0].tool_call_id.as_deref(), Some("call_9"));
assert_eq!(messages[0].tool_name.as_deref(), Some("file_write"));
assert_eq!(messages[0].tool_name.as_deref(), Some("write"));
assert!(messages[0].tool_calls.is_none());
}

View File

@ -83,7 +83,7 @@ impl Default for FileEditTool {
#[async_trait]
impl Tool for FileEditTool {
fn name(&self) -> &str {
"file_edit"
"edit"
}
fn description(&self) -> &str {

View File

@ -57,7 +57,7 @@ impl Default for FileReadTool {
#[async_trait]
impl Tool for FileReadTool {
fn name(&self) -> &str {
"file_read"
"read"
}
fn description(&self) -> &str {

View File

@ -54,7 +54,7 @@ impl Default for FileWriteTool {
#[async_trait]
impl Tool for FileWriteTool {
fn name(&self) -> &str {
"file_write"
"write"
}
fn description(&self) -> &str {

View File

@ -34,9 +34,9 @@ impl Default for SubAgentRuntimeConfig {
fn default() -> Self {
Self {
allowed_tools: HashSet::from([
"file_read".to_string(),
"file_edit".to_string(),
"file_write".to_string(),
"read".to_string(),
"edit".to_string(),
"write".to_string(),
"bash".to_string(),
"http_request".to_string(),
"web_fetch".to_string(),