Creating Your First Agent
A step-by-step guide to building your first AI agent
Let’s build your first AI agent in 5 minutes! Follow along step by step.
Step-by-Step Guide
- Install PraisonAI
Open your terminal and run:
bash pip install praisonaiagents - Set Your API Key
Set your OpenAI API key:
bash export OPENAI_API_KEY=your_key_here - Create Your Agent File
Create a new file called
my_agent.py:python from praisonaiagents import Agent # Create your first agent agent = Agent( name="ResearchAssistant", instructions="You are a helpful research assistant. Explain things simply and clearly." ) # Ask it a question agent.start("Explain how solar panels work in simple terms") - Run Your Agent
bash python my_agent.pyYou should see the agent’s response explaining solar panels!
How It Works
| Step | What Happens |
|---|---|
| Instructions | Tell the agent who it is and how to behave |
| Question | Your message or task |
| LLM | AI model processes everything |
| Response | Agent returns the answer |
Try Different Agents
Coding Helper
from praisonaiagents import Agent
coder = Agent(
name="CodeHelper",
instructions="You are a Python expert. Explain code simply and provide working examples."
)
coder.start("How do I read a CSV file in Python?")Creative Writer
from praisonaiagents import Agent
writer = Agent(
name="StoryWriter",
instructions="You write short, engaging stories with vivid descriptions."
)
writer.start("Write a short story about a robot learning to paint")Math Tutor
from praisonaiagents import Agent
tutor = Agent(
name="MathTutor",
instructions="You explain math concepts step by step. Use simple language."
)
tutor.start("Explain how percentages work")Complete Example
from praisonaiagents import Agent
# Create a research assistant
assistant = Agent(
name="ResearchAssistant",
instructions="""You are a helpful research assistant.
When answering:
- Be concise and clear
- Use bullet points when helpful
- Explain complex topics simply
- Admit when you don't know something"""
)
# Ask multiple questions
assistant.start("What are the benefits of exercise?")
assistant.start("How does the internet work?")
assistant.start("Explain climate change in simple terms")Troubleshooting
API Key Error
Make sure OPENAI_API_KEY is set correctly
Run pip install praisonaiagents again
Check your internet connection
Slow ResponseFirst request may take a few seconds
What’s Next?
Add Tools
Give your agent superpowers like web search and calculations
Add Memory
Let your agent remember conversations
Add Knowledge
Give your agent access to your documents
Build Teams
Create multiple agents that work together
Next: Adding Tools to Agents
Learn how to give your agents superpowers with tools.