Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Define Simple Function
def calculator_tool(expression: str) -> float:
"""Evaluate a mathematical expression.
Args:
expression: Math expression to evaluate
Returns:
Result of the calculation
"""
return eval(expression)
Use with Agent
from praisonaiagents import Agent
agent = Agent(
name="calculator",
tools=[calculator_tool]
)
Define Lambda Tool
# Simple lambda tool
uppercase_tool = lambda text: text.upper()
uppercase_tool.__doc__ = "Convert text to uppercase"
uppercase_tool.__annotations__ = {"text": str, "return": str}
Use with Agent
agent = Agent(
name="formatter",
tools=[uppercase_tool]
)
Wrap Library Function
import requests
def http_get_tool(url: str) -> dict:
"""Make HTTP GET request.
Args:
url: URL to fetch
Returns:
Response data as dictionary
"""
response = requests.get(url)
return {
"status": response.status_code,
"content": response.text[:1000]
}
Use Wrapped Tool
agent = Agent(
name="http_agent",
tools=[http_get_tool]
)
Create tools.py
# tools.py
def file_reader(path: str) -> str:
"""Read file contents.
Args:
path: Path to file
Returns:
File contents
"""
with open(path, 'r') as f:
return f.read()
def file_writer(path: str, content: str) -> bool:
"""Write content to file.
Args:
path: Path to file
content: Content to write
Returns:
Success status
"""
with open(path, 'w') as f:
f.write(content)
return True
Reference in Template
# agents.yaml
roles:
file_agent:
tools:
- file_reader
- file_writer
Create Package Structure
my_tools/
├── __init__.py
├── search.py
└── database.py
Define Tools in Module
# my_tools/search.py
def web_search(query: str) -> list:
"""Search the web.
Args:
query: Search query
Returns:
List of results
"""
return [{"title": "Result", "url": "https://example.com"}]
Export in __init__.py
# my_tools/__init__.py
from .search import web_search
from .database import db_query
__all__ = ["web_search", "db_query"]
Use as tools_source
# TEMPLATE.yaml
requires:
tools_sources:
- my_tools
Use Tool Decorator
from praisonaiagents import tool
@tool
def decorated_tool(query: str) -> str:
"""A decorated tool function.
Args:
query: Input query
Returns:
Processed result
"""
return f"Processed: {query}"
Use with Agent
agent = Agent(
name="decorated_agent",
tools=[decorated_tool]
)
Add Package Tools
praisonai tools add pandas
Add Local File
praisonai tools add ./my_tools.py
Add from GitHub
praisonai tools add github:user/repo/tools
| Method | Best For | Complexity |
|---|
| Function | Simple tools | Low |
| Lambda | One-liners | Low |
| Class | Stateful tools | Medium |
| Package | Reusable tools | Medium |
| Decorator | Enhanced tools | Low |
| External wrap | Library integration | Medium |
| CLI add | Quick setup | Low |