withTool
Registers a tool that the agent can use. Tools are external functions or APIs that the agent can invoke to perform actions or retrieve information. This method registers the tool’s metadata (name, description, parameters) and optionally execution logic. The Zod schema is introspected to create human-readable parameter documentation.PromptSmith Format
Tool definition containing:
name: Unique tool identifierdescription: When and how to use the toolschema: Zod schema for parametersexecute: (optional) Execution function with full type inference
The builder instance for method chaining
Mastra Format
Also accepts tools created with Mastra’screateTool() function, automatically converting them to PromptSmith’s internal format.
Tool definition in Mastra format (created with
createTool())Examples
- Basic Tool
- With Execution
- Mastra Tool
withTools
Registers multiple tools at once. This is a convenience method for adding several tools in a single call, equivalent to calling.withTool() multiple times. Useful when you have a pre-defined collection of tools to register.
An array of tool definitions
The builder instance for method chaining
Example
withToolIf
Conditionally registers a tool based on a condition. This method only adds the tool if the condition evaluates to true, making it easier to build prompts with conditional tool availability without breaking the fluent chain.Boolean condition that determines if the tool is added
Tool definition containing name, description, parameter schema, and optionally an execute function
The builder instance for method chaining