Skip to main content
The user wraps behaviour in a class-based tool; the agent invokes it like any other capability. 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

1

Install Package

First, install the PraisonAI Agents package:
2

Set API Key

Set your OpenAI API key and EXA API key as environment variables in your terminal:
3

Create a file

Create a new file app.py with the basic setup:
4

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

Function Tools

Learn about function-based tools

API Tools

Explore API integration tools
For optimal results, ensure your tool classes are well-documented and follow Pydantic best practices for model definition.

Best Practices

Each tool should do one thing well - this makes agent behavior more predictable.
Return human-readable strings from tools so the agent can understand and relay results.
On failure, return a descriptive error string rather than raising an exception.
The agent uses tool docstrings to decide when to call a tool - write clear, specific descriptions.

Custom Tools

Build your own agent tools

Tools Overview

Browse PraisonAI tool documentation