Tools as Class
Learn how to create and use class-based tools with AI agents for enhanced functionality.
A workflow demonstrating how to create and use class-based tools that can be integrated with AI agents to extend their capabilities with custom functionality.
Quick Start
Install Package
First, install the PraisonAI Agents package:
Set API Key
Set your OpenAI API key and EXA API key as environment variables in your terminal:
Create a file
Create a new file app.py
with the basic setup:
Start Agents
Type this in your terminal to run your agents:
Requirements
- Python 3.10 or higher
- OpenAI API key. Generate OpenAI API key here
- EXA API key for search functionality
- Basic understanding of Python and Pydantic
Understanding Tools as Class
What are Class-based Tools?
Class-based tools enable:
- Custom functionality encapsulation
- Reusable tool components
- Type-safe tool interfaces
- Complex API integrations
Features
Pydantic Integration
Built-in validation and type safety with Pydantic models.
API Wrapping
Easily wrap external APIs as agent tools.
Method Flexibility
Support for multiple methods within a single tool.
Type Hints
Strong typing for better code reliability.
Configuration Options
Troubleshooting
Tool Issues
If tool execution fails:
- Check API credentials
- Verify network connectivity
- Enable verbose logging
Type Errors
If type validation fails:
- Review input types
- Check Pydantic model
- Verify method signatures
Next Steps
For optimal results, ensure your tool classes are well-documented and follow Pydantic best practices for model definition.
Was this page helpful?