ITADN

Allow `OpenAiToolAgentBuilder` to accept a Vec rather than an Array for `tools`

#323Openhpux735 创建于 2025-06-13
H
hpux735commented
**Is your feature request related to a problem? Please describe.** I don't think it's possible to have the tools set dynamically (i.e. not at compile time) because it only accepts an array, not a Vec. If it was changed to a Vec, you can still set it in the same way it is in the example using `vec![..]`. **Describe the solution you'd like** Change the signature to a Vec rather than an array. **Describe alternatives you've considered** I tried just setting the variables directly, but they're not public. **Additional context** I've already implemented this in a private fork. It's basically a 3 line change. Let me know if you want me to open a PR. ``` diff --git a/examples/open_ai_tools_agent.rs b/examples/open_ai_tools_agent.rs index 842b615..a84aa68 100644 --- a/examples/open_ai_tools_agent.rs +++ b/examples/open_ai_tools_agent.rs @@ -35,7 +35,7 @@ async fn main() { let tool_calc = Date {}; let command_executor = CommandExecutor::default(); let agent = OpenAiToolAgentBuilder::new() - .tools(&[ + .tools(&vec![ Arc::new(serpapi_tool), Arc::new(tool_calc), Arc::new(command_executor), diff --git a/src/agent/open_ai_tools/builder.rs b/src/agent/open_ai_tools/builder.rs index a51f8d7..21793cb 100644 --- a/src/agent/open_ai_tools/builder.rs +++ b/src/agent/open_ai_tools/builder.rs @@ -25,8 +25,8 @@ impl OpenAiToolAgentBuilder { } } - pub fn tools(mut self, tools: &[Arc<dyn Tool>]) -> Self { - self.tools = Some(tools.to_vec()); + pub fn tools(mut self, tools: &Vec<Arc<dyn Tool>>) -> Self { + self.tools = Some(tools.clone()); self } ```
0 条评论