> ## 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.

# Create Custom Tools

> Step-by-step guide to creating custom tools for PraisonAI agents

## How to Create a Simple Tool Function

<Steps>
  <Step title="Define Tool Function">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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}"
    ```
  </Step>

  <Step title="Use with Agent">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent

    agent = Agent(
        name="processor",
        role="Data Processor",
        tools=[my_tool]
    )

    result = agent.start("Process this data")
    print(result)
    ```
  </Step>
</Steps>

## How to Create Tools with Multiple Parameters

<Steps>
  <Step title="Define Multi-Parameter Tool">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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
        }
    ```
  </Step>

  <Step title="Use with Agent">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent

    agent = Agent(
        name="searcher",
        role="Search Agent",
        tools=[search_tool]
    )

    result = agent.start("Search for AI news")
    print(result)
    ```
  </Step>
</Steps>

## How to Create Tools as Classes

<Steps>
  <Step title="Define Tool Class">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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
    ```
  </Step>

  <Step title="Use Class Methods as Tools">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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]
    )
    ```
  </Step>
</Steps>

## How to Create Async Tools

<Steps>
  <Step title="Define Async Tool">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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()
    ```
  </Step>

  <Step title="Use with Async Agent">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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")
    ```
  </Step>
</Steps>

## Tool Function Requirements

| 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    |
