feat: 重命名工具名称,简化工具调用接口
This commit is contained in:
parent
e62424d130
commit
8f82009c32
@ -573,7 +573,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
ToolCall {
|
ToolCall {
|
||||||
id: "call-2".to_string(),
|
id: "call-2".to_string(),
|
||||||
name: "file_read".to_string(),
|
name: "read".to_string(),
|
||||||
arguments: json!({"path": "README.md"}),
|
arguments: json!({"path": "README.md"}),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -599,10 +599,10 @@ mod tests {
|
|||||||
outbound[0].content,
|
outbound[0].content,
|
||||||
"calculator\nargs: {\"expression\":\"1 + 1\"}"
|
"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!(
|
assert_eq!(
|
||||||
outbound[1].content,
|
outbound[1].content,
|
||||||
"file_read\nargs: {\"path\":\"README.md\"}"
|
"read\nargs: {\"path\":\"README.md\"}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -140,9 +140,9 @@ fn default_task_ttl_hours() -> u64 {
|
|||||||
|
|
||||||
fn default_task_allowed_tools() -> Vec<String> {
|
fn default_task_allowed_tools() -> Vec<String> {
|
||||||
vec![
|
vec![
|
||||||
"file_read".to_string(),
|
"read".to_string(),
|
||||||
"file_edit".to_string(),
|
"edit".to_string(),
|
||||||
"file_write".to_string(),
|
"write".to_string(),
|
||||||
"bash".to_string(),
|
"bash".to_string(),
|
||||||
"http_request".to_string(),
|
"http_request".to_string(),
|
||||||
"web_fetch".to_string(),
|
"web_fetch".to_string(),
|
||||||
|
|||||||
@ -697,6 +697,7 @@ mod tests {
|
|||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
"Asia/Shanghai".to_string(),
|
"Asia/Shanghai".to_string(),
|
||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
|
Default::default(),
|
||||||
)
|
)
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
@ -744,6 +745,7 @@ mod tests {
|
|||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
"Asia/Shanghai".to_string(),
|
"Asia/Shanghai".to_string(),
|
||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
|
Default::default(),
|
||||||
)
|
)
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
@ -1693,6 +1695,7 @@ mod tests {
|
|||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
"Asia/Shanghai".to_string(),
|
"Asia/Shanghai".to_string(),
|
||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
|
Default::default(),
|
||||||
)
|
)
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
@ -1732,6 +1735,7 @@ mod tests {
|
|||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
"Asia/Shanghai".to_string(),
|
"Asia/Shanghai".to_string(),
|
||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
|
Default::default(),
|
||||||
)
|
)
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
@ -1804,6 +1808,7 @@ mod tests {
|
|||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
"Asia/Shanghai".to_string(),
|
"Asia/Shanghai".to_string(),
|
||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
|
Default::default(),
|
||||||
)
|
)
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
@ -1854,7 +1859,8 @@ mod tests {
|
|||||||
Arc::new(NoopSessionMessageSender),
|
Arc::new(NoopSessionMessageSender),
|
||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
"Asia/Shanghai".to_string(),
|
"Asia/Shanghai".to_string(),
|
||||||
HashSet::new(),
|
HashSet::new(),
|
||||||
|
Default::default(),
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|||||||
@ -72,13 +72,13 @@ impl ToolRegistryFactory {
|
|||||||
if self.is_enabled("get_time") {
|
if self.is_enabled("get_time") {
|
||||||
registry.register(TimeTool::new(self.default_timezone.clone()));
|
registry.register(TimeTool::new(self.default_timezone.clone()));
|
||||||
}
|
}
|
||||||
if self.is_enabled("file_read") {
|
if self.is_enabled("read") {
|
||||||
registry.register(FileReadTool::new());
|
registry.register(FileReadTool::new());
|
||||||
}
|
}
|
||||||
if self.is_enabled("file_write") {
|
if self.is_enabled("write") {
|
||||||
registry.register(FileWriteTool::new());
|
registry.register(FileWriteTool::new());
|
||||||
}
|
}
|
||||||
if self.is_enabled("file_edit") {
|
if self.is_enabled("edit") {
|
||||||
registry.register(FileEditTool::new());
|
registry.register(FileEditTool::new());
|
||||||
}
|
}
|
||||||
if self.is_enabled("memory_search") {
|
if self.is_enabled("memory_search") {
|
||||||
@ -144,13 +144,13 @@ impl ToolRegistryFactory {
|
|||||||
if self.is_enabled("get_time") {
|
if self.is_enabled("get_time") {
|
||||||
registry.register(TimeTool::new(self.default_timezone.clone()));
|
registry.register(TimeTool::new(self.default_timezone.clone()));
|
||||||
}
|
}
|
||||||
if self.is_enabled("file_read") {
|
if self.is_enabled("read") {
|
||||||
registry.register(FileReadTool::new());
|
registry.register(FileReadTool::new());
|
||||||
}
|
}
|
||||||
if self.is_enabled("file_write") {
|
if self.is_enabled("write") {
|
||||||
registry.register(FileWriteTool::new());
|
registry.register(FileWriteTool::new());
|
||||||
}
|
}
|
||||||
if self.is_enabled("file_edit") {
|
if self.is_enabled("edit") {
|
||||||
registry.register(FileEditTool::new());
|
registry.register(FileEditTool::new());
|
||||||
}
|
}
|
||||||
if self.is_enabled("bash") {
|
if self.is_enabled("bash") {
|
||||||
|
|||||||
@ -2228,7 +2228,7 @@ mod tests {
|
|||||||
let store = SessionStore::in_memory().unwrap();
|
let store = SessionStore::in_memory().unwrap();
|
||||||
let session = store.create_cli_session(Some("tool-result")).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();
|
store.append_message(&session.id, &tool_message).unwrap();
|
||||||
|
|
||||||
let messages = store.load_messages(&session.id).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].role, "tool");
|
||||||
assert_eq!(messages[0].content, "saved to /tmp/output.txt");
|
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_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());
|
assert!(messages[0].tool_calls.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ impl Default for FileEditTool {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Tool for FileEditTool {
|
impl Tool for FileEditTool {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"file_edit"
|
"edit"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
|
|||||||
@ -57,7 +57,7 @@ impl Default for FileReadTool {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Tool for FileReadTool {
|
impl Tool for FileReadTool {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"file_read"
|
"read"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
|
|||||||
@ -54,7 +54,7 @@ impl Default for FileWriteTool {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Tool for FileWriteTool {
|
impl Tool for FileWriteTool {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"file_write"
|
"write"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
|
|||||||
@ -34,9 +34,9 @@ impl Default for SubAgentRuntimeConfig {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
allowed_tools: HashSet::from([
|
allowed_tools: HashSet::from([
|
||||||
"file_read".to_string(),
|
"read".to_string(),
|
||||||
"file_edit".to_string(),
|
"edit".to_string(),
|
||||||
"file_write".to_string(),
|
"write".to_string(),
|
||||||
"bash".to_string(),
|
"bash".to_string(),
|
||||||
"http_request".to_string(),
|
"http_request".to_string(),
|
||||||
"web_fetch".to_string(),
|
"web_fetch".to_string(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user