Dynamically Create Tool Argument Type

According to the Tool documentation, the arguments to the tool are specified as a static struct type T, which is given to tool.call(argument: T) However, if the arguments are not known until runtime, is it possible to still create a Tool object with the proper parameters? Let's say a JSON-style dictionary is passed into the Tool init function to specify T, is this achievable?

Answered by Frameworks Engineer in 849401022

Hi @ecoarcgaming, dynamically defined tool parameters are fully supported. In your tool implementation, you just need to implement var parameters: GenerationSchema and pass GeneratedContent as the argument to the call method. Here's documentation on defining generation schemas at runtime.

struct MyDynamicTool: Tool {
    // name, description...
    var parameters: GenerationSchema {
        // Define your parameters at runtime
    }
    func call(arguments: GeneratedContent) -> ToolOutput { ... }
}
Accepted Answer

Hi @ecoarcgaming, dynamically defined tool parameters are fully supported. In your tool implementation, you just need to implement var parameters: GenerationSchema and pass GeneratedContent as the argument to the call method. Here's documentation on defining generation schemas at runtime.

struct MyDynamicTool: Tool {
    // name, description...
    var parameters: GenerationSchema {
        // Define your parameters at runtime
    }
    func call(arguments: GeneratedContent) -> ToolOutput { ... }
}
Dynamically Create Tool Argument Type
 
 
Q