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 Tool Function
def my_tool(query: str) -> str:
"""Process a query and return result.
Args:
query: The input query to process
Returns:
Processed result as string
"""
# Your tool logic here
return f"Processed: {query}"
Use with Agent
from praisonaiagents import Agent
agent = Agent(
name="processor",
role="Data Processor",
tools=[my_tool]
)
result = agent.start("Process this data")
print(result)
Define Multi-Parameter Tool
def search_tool(query: str, max_results: int = 10, language: str = "en") -> dict:
"""Search for information with options.
Args:
query: Search query
max_results: Maximum number of results
language: Language code
Returns:
Dictionary with search results
"""
return {
"query": query,
"results": [f"Result {i}" for i in range(max_results)],
"language": language
}
Use with Agent
from praisonaiagents import Agent
agent = Agent(
name="searcher",
role="Search Agent",
tools=[search_tool]
)
result = agent.start("Search for AI news")
print(result)
Define Tool Class
class DatabaseTool:
"""Tool for database operations."""
def __init__(self, connection_string: str):
self.connection = connection_string
def query(self, sql: str) -> list:
"""Execute SQL query.
Args:
sql: SQL query string
Returns:
List of results
"""
# Database logic here
return [{"id": 1, "data": "example"}]
def insert(self, table: str, data: dict) -> bool:
"""Insert data into table.
Args:
table: Table name
data: Data to insert
Returns:
Success status
"""
return True
Use Class Methods as Tools
from praisonaiagents import Agent
db_tool = DatabaseTool("postgresql://localhost/mydb")
agent = Agent(
name="db_agent",
role="Database Agent",
tools=[db_tool.query, db_tool.insert]
)
Define Async Tool
import asyncio
import aiohttp
async def async_fetch_tool(url: str) -> str:
"""Fetch content from URL asynchronously.
Args:
url: URL to fetch
Returns:
Response content
"""
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.text()
Use with Async Agent
from praisonaiagents import Agent
agent = Agent(
name="fetcher",
role="Web Fetcher",
tools=[async_fetch_tool]
)
# Run async
result = await agent.astart("Fetch https://example.com")
| Requirement | Description |
|---|
| Type hints | All parameters must have type hints |
| Docstring | Must include description and Args section |
| Return type | Must specify return type |
| Serializable | Return value must be JSON-serializable |