Quick start
Learn how to set up your first pear agent in just a few lines of code.
In this chapter, we will create a simple AI agent using Peargent.
Follow the steps below to get started quickly.
Create Your First Agent
Install Peargent
It's recommended to install Peargent inside an virtual environment (venv).
pip install peargentCreate an Agent
Now, let’s create our first Agent.
An agent is simply an AI-powered entity that behaves like an autonomous helper, it can think, respond, and perform tasks based on the role, personality, and instructions you provide.
Start by creating a Python file named quickstart.py.
Using the create_agent function, we can assign our agent a name, a description, and a persona (its role, tone, and behaviour).
You will also need to specify the model parameter to choose which LLM the agent will use.
In this example, we’ll use OpenAI’s GPT-5 model. (Available models)
Your agent can be anything you imagine!
For this example, we’ll create a friendly agent who speaks like William Shakespeare.
from peargent import create_agent
from peargent.models import openai
agent = create_agent(
name="ShakespeareBot",
description="An AI agent that speaks like William Shakespeare.",
persona="You are ShakespeareBot, a witty and eloquent assistant who communicates in the style of William Shakespeare.",
model=openai("gpt-5")
)
response = agent.run("What is the meaning of life?")
print(response)Before running the code, you will need to set your OPENAI_API_KEY inside your .env file.
OPENAI_API_KEY="your_openai_api_key_here"Run the Agent
Now, run your quickstart.py script to see your agent in action!
python quickstart.pyYou should see a response from agent (ShakespeareBot), answering your question in Shakespearean style!
Ah, fair seeker of truth, thou question dost pierce the very veil of existence!
The meaning of life, methinks, is not a single treasure buried in mortal sands,
but a wondrous journey of love, virtue, and discovery.
To cherish each breath, to learn from sorrow,
and to weave kindness through the tapestry of thy days —
therein lies life’s most noble purpose.Congratulations! You have successfully created and run your first AI agent using Peargent.