Skip to main content
Think of the ToolInterface as your agent’s superhero training academy. Every tool you build expands what your agents can do - from simple calculations to complex integrations.

The Simple Yet Powerful Interface

The beauty of Vizra tools lies in their simplicity. Just two methods to implement, and your agent gains a whole new superpower. Here’s the elegant contract:
The ToolInterface Contract

The Two Magical Methods

Just two methods stand between you and tool mastery. Each serves a crucial purpose in making your agent interactions seamless and powerful.

definition()

The blueprint method. Tell the AI exactly how to use your tool with a JSON Schema definition. It’s like writing a user manual that AI can understand perfectly.

execute()

The action hero. This is where the magic happens - take the AI’s parameters and make something amazing occur. Database queries, API calls, calculations - you name it.

definition() - Teaching AI How to Use Your Tool

This method returns a JSON Schema that’s like a detailed instruction manual for AI. Here’s how to write one that makes your tool shine:
Perfect Tool Definition

execute()

Execute the tool with provided arguments, context, and agent memory. Must return a JSON-encoded string.

Parameter Schema Examples

Basic Parameter Types

Complex Parameter Types

Return Value Format

Tools must return a JSON-encoded string. Common patterns include:

Working with AgentContext

The AgentContext parameter provides access to session state and conversation history:

Advanced Features

Tool with User Context

Tool with Session Context

Tool with File Handling

Complete Example

RefundProcessorTool.php
Tool Best Practices:
  • Keep tools focused on a single action
  • Implement the ToolInterface, not extend a base class
  • Use descriptive names and descriptions
  • Return JSON-encoded strings from execute()
  • Use AgentContext for session state management
  • Validate parameters thoroughly
  • Handle errors gracefully
  • Return clear success/error messages

Next Steps

Workflow Class

Workflow class reference

Tool Concepts

Learn more about tools