Basic

1

Install Package

Install the PraisonAI Agents package:

pip install praisonaiagents
2

Set API Key

export OPENAI_API_KEY=your_openai_key

Generate your OpenAI API key from OpenAI. Use other LLM providers like Ollama, Anthropic, Groq, Google, etc. Please refer to the Models for more information.

3

Create Agents

Create app.py:

4

Run Agents

Execute your script:

python app.py

You’ll see:

  • Agent initialization
  • Task execution progress
  • Final results

You have successfully CreatedAI Agents and made them work for you!

Prerequisites

  • Python 3.10 or higher
  • OpenAI API key (get it here)
  • For other LLM providers, see Models

Advanced

Providing Detailed Tasks to Agents (Optional)

1

Install PraisonAI

Install the core package:

Terminal
pip install praisonaiagents
2

Configure Environment

Terminal
export OPENAI_API_KEY=your_openai_key

Generate your OpenAI API key from OpenAI Use other LLM providers like Ollama, Anthropic, Groq, Google, etc. Please refer to the Models for more information.

3

Create Agent

Create app.py:

4

Start Agents

Execute your script:

Terminal
python app.py

You should see:

  • Agent initialization
  • Agents progress
  • Final results
  • Generated report

Creating Custom Tool for Agents (Optional)

Tools makes the Agent powerful.

More information about tools can be found in the Tools section.

1

Install PraisonAI

Install the core package and duckduckgo_search package:

Terminal
pip install praisonai duckduckgo_search
2

Create Tools and Agents

from praisonaiagents import Agent, Task, PraisonAIAgents
from duckduckgo_search import DDGS
from typing import List, Dict

# 1. Tool
def internet_search_tool(query: str) -> List[Dict]:
    """
    Perform Internet Search
    """
    results = []
    ddgs = DDGS()
    for result in ddgs.text(keywords=query, max_results=5):
        results.append({
            "title": result.get("title", ""),
            "url": result.get("href", ""),
            "snippet": result.get("body", "")
        })
    return results

# 2. Agent
data_agent = Agent(
    name="DataCollector",
    role="Search Specialist",
    goal="Perform internet searches to collect relevant information.",
    backstory="Expert in finding and organising internet data.",
    tools=[internet_search_tool],
    self_reflect=False
)

# 3. Tasks
collect_task = Task(
    description="Perform an internet search using the query: 'AI job trends in 2024'. Return results as a list of title, URL, and snippet.",
    expected_output="List of search results with titles, URLs, and snippets.",
    agent=data_agent,
    name="collect_data",
)

# 4. Start Agents
agents = PraisonAIAgents(
    agents=[data_agent],
    tasks=[collect_task],
    process="sequential"
)

agents.start()
3

Start Agents

Run your script:

Terminal
python app.py

Next Steps

Was this page helpful?