Agents

Create AI agents that understand instructions, use tools, and complete tasks

An Agent is an AI that follows your instructions, uses tools, and completes tasks through conversation.

python
from praisonaiagents import Agent

agent = Agent(
    name="Assistant",
    instructions="You are a helpful research assistant. Answer questions accurately and concisely.",
)

agent.start("What are the main benefits of solar energy?")

The user asks a question; the agent runs a single turn and returns the answer.

Diagram

Agent Flow

๐Ÿ’ฌ User Input

๐Ÿค– Agent

๐Ÿ”ง Tools

โœ… Response

Quick Start

  1. Simple Agent
    python
    from praisonaiagents import Agent
    
    agent = Agent(instructions="You are a helpful assistant.")
    response = agent.start("Explain machine learning in one paragraph.")
    print(response)
  2. Agent with Tools
    python
    from praisonaiagents import Agent
    from praisonaiagents.tools import duckduckgo
    
    agent = Agent(
        name="Researcher",
        instructions="You are a research agent. Use web search for current information.",
        tools=[duckduckgo],
    )
    agent.start("What are the latest developments in quantum computing?")
  3. Agent with Features
    python
    from praisonaiagents import Agent
    
    agent = Agent(
        name="SmartAssistant",
        instructions="You are a smart assistant that remembers and plans.",
        memory=True,
        planning=True,
        reflection=True,
    )
    agent.start("Help me plan a comprehensive study schedule for learning Python.")

How It Works

Diagram
ToolsLLMAgentUserToolsLLMAgentUseropt[Tool call needed]MessageFormat + send promptResponse or tool callExecute toolTool resultContinue with resultFinal responseResponse
PhaseWhat happens
1. ReceiveAgent receives user input
2. ThinkLLM decides whether to respond or call a tool
3. ActIf tool needed, executes it and feeds result back
4. RespondFinal answer returned to user

Key Parameters

ParameterTypeDescription
namestrAgent name (shown in logs and multi-agent setups)
instructionsstrSystem prompt โ€” what the agent does and how
llmstrModel name (e.g., "gpt-4o", "claude-3-5-sonnet")
toolslistList of tools the agent can use
memory`bool \MemoryConfig`Enable conversation memory
planning`bool \PlanningConfig`Enable pre-execution planning
reflection`bool \ReflectionConfig`Enable self-review of responses
caching`bool \CachingConfig`Enable response caching
output`str \OutputConfig`Control response verbosity
execution`str \ExecutionConfig`Control iteration and budget limits

Common Patterns

Pattern 1 โ€” Simple Q&A agent

python
from praisonaiagents import Agent

agent = Agent(instructions="Answer questions clearly and accurately.")
response = agent.start("What is the difference between RAM and storage?")
print(response)

Pattern 2 โ€” Specialized domain agent

python
from praisonaiagents import Agent

agent = Agent(
    name="LegalAnalyst",
    instructions="""You are a legal document analyst.
    Identify key clauses, risks, and obligations.
    Always recommend consulting a qualified attorney.""",
    llm="gpt-4o",
)
agent.start("Analyze this software license agreement for unusual terms.")

Pattern 3 โ€” Fully-featured production agent

python
from praisonaiagents import Agent, MemoryConfig, ExecutionConfig

agent = Agent(
    name="ProductionAgent",
    instructions="You are a reliable production assistant.",
    memory=MemoryConfig(backend="sqlite", user_id="user_123"),
    execution=ExecutionConfig(max_iter=30, max_budget=0.25),
    caching=True,
)
response = agent.start("Summarize our Q3 performance metrics.")
print(response)

Best Practices

Write clear instructions

The instructions parameter is your agent’s personality and purpose. Be specific: “You are a customer support agent for Acme Corp. Answer questions about orders, returns, and products. Escalate billing disputes to a human.” Clear instructions outperform vague ones every time.

Add features progressively

Start with just Agent(instructions="...") and add features (memory, planning, reflection) one at a time. Each feature has a cost โ€” only add what your use case actually needs.

Use the right model

gpt-4o-mini handles simple Q&A and extraction cheaply and fast. Use gpt-4o or claude-3-5-sonnet for complex reasoning, code generation, and nuanced writing tasks.

Name agents in multi-agent setups

Always set name when using multiple agents. Names appear in logs, hooks callbacks, and help diagnose which agent produced which output in complex workflows.


Related