Before you can bring your first LLM agent to life, a bit of setup is required. A well-organized development environment is the foundation upon which all your agent-building efforts will rest. It ensures that your projects are manageable, repeatable, and that you have the right tools at your fingertips. This section will guide you through the essential steps to prepare your computer for agent development.
Python is the dominant programming language for machine learning and AI development, including LLM agents, due to its simplicity, extensive libraries, and large community. We'll be using Python for all examples in this course.
Python's clear syntax makes it relatively easy to learn, even if you're new to programming. More importantly for us, there's a rich ecosystem of libraries designed for interacting with LLMs and building AI applications. This means we can focus on agent logic rather than writing low-level code for common tasks.
Most modern operating systems (macOS and Linux) come with Python pre-installed. Windows users might need to install it manually. We recommend using Python version 3.8 or newer.
To check if Python is installed and its version, open your terminal (Command Prompt or PowerShell on Windows, Terminal on macOS and Linux) and type:
python --version
Or, on some systems, you might need to use python3
:
python3 --version
If Python is installed, you'll see output like Python 3.10.4
. If you get an error, or if your version is older than 3.8, you'll need to install or update Python. Visit the official Python website (python.org) for download instructions.
pip
is Python's package installer. You'll use it to install the libraries your agent needs. pip
is usually included with Python installations (version 3.4 and later).
To check if pip
is available, run:
pip --version
Or, if you used python3
above:
pip3 --version
If it's not found, you might need to install it separately or ensure your Python installation's scripts directory is in your system's PATH. Refer to Python's official documentation for guidance on installing pip
.
You'll need a place to write your Python code. While a simple text editor can work, an Integrated Development Environment (IDE) or a good code editor can make your life much easier with features like syntax highlighting, code completion, and debugging tools.
For beginners, here are a few popular and free options:
Choose one that feels comfortable for you. Many online tutorials and videos can help you get started with any of these.
When you work on different Python projects, they might require different versions of the same library. Installing everything system-wide can lead to conflicts. Virtual environments solve this by creating isolated spaces for each project, each with its own Python interpreter and set of installed libraries.
Imagine Project A needs version 1.0 of a library, but Project B needs version 2.0. If you install these system-wide, one project might break. A virtual environment keeps each project's dependencies separate, preventing such issues. It's a standard best practice in Python development.
A virtual environment creates an isolated space for each Python project, preventing library version conflicts.
venv
Python comes with a built-in module called venv
for creating virtual environments.
Navigate to your project directory: Open your terminal and go to the folder where you want to create your agent project. If the folder doesn't exist, create it first (e.g., mkdir my_first_agent
and then cd my_first_agent
).
Create the virtual environment: Run the following command. We'll name our virtual environment myagent_env
, but you can choose another name (common convention is venv
or .venv
).
python -m venv myagent_env
(Use python3
if that's how you invoke Python 3). This command creates a new directory (e.g., myagent_env
) containing a copy of the Python interpreter and a place to install libraries.
Once created, you need to "activate" the environment. Activation modifies your terminal prompt to indicate the active environment and ensures that python
and pip
commands use the environment's isolated setup.
On Windows (Command Prompt):
myagent_env\Scripts\activate.bat
On Windows (PowerShell):
myagent_env\Scripts\Activate.ps1
(You might need to adjust your execution policy: Set-ExecutionPolicy Unrestricted -Scope Process
)
On macOS and Linux (bash/zsh):
source myagent_env/bin/activate
After activation, your terminal prompt should change, often prepended with (myagent_env)
. To deactivate, simply type deactivate
in the terminal. Always remember to activate your virtual environment before working on your project.
With your virtual environment active, you can now install the Python libraries your agent will need. We'll start with two:
openai
: This library provides convenient access to OpenAI's LLMs, like GPT-3.5 and GPT-4. We'll use this as our starting point for interacting with a powerful LLM. Even if you later explore agents with other LLMs, the principles of using an SDK (Software Development Kit) like this will be similar.python-dotenv
: LLM agents often require API keys to access services. It's crucial not to hardcode these keys directly into your scripts. python-dotenv
helps you manage sensitive information like API keys by loading them from a special .env
file.Ensure your virtual environment is active. Then, use pip
to install these libraries:
pip install openai python-dotenv
This command tells pip
to download and install the latest versions of the openai
and python-dotenv
packages and their dependencies into your active virtual environment (myagent_env
). You should see output indicating successful installation.
A little organization goes a long way. For your first agent, a simple structure will suffice. Inside the main folder where you created your virtual environment (e.g., my_first_agent
), you might have:
myagent_env/
: The virtual environment directory (created by venv
).agent.py
: This will be your main Python file where you'll write the code for your agent..env
: A file where you'll store your API key (we'll cover this more in the next section). Important: This file should not be shared publicly.A recommended simple directory structure for your LLM agent project.
Let's do a quick check to ensure everything is working as expected.
Make sure your virtual environment (myagent_env
) is still active.
Create a new Python file named verify_setup.py
in your project directory (e.g., my_first_agent/verify_setup.py
).
Open verify_setup.py
in your code editor and add the following lines:
try:
import openai
import dotenv
print("Successfully imported 'openai' and 'dotenv' libraries.")
print(f"OpenAI library version: {openai.__version__}")
print("Your development environment seems ready!")
except ImportError as e:
print(f"Error importing libraries: {e}")
print("Please ensure you have activated your virtual environment and installed the required packages ('pip install openai python-dotenv').")
Save the file.
In your terminal (still in your project directory with the virtual environment active), run the script:
python verify_setup.py
If everything is set up correctly, you should see a success message and the version of the openai
library. If you see an ImportError
, double-check that your virtual environment is active and that you've successfully installed the libraries using pip
.
With your workspace prepared, you're now ready to move on to the next step: selecting an LLM for your first agent and learning how to interact with it. This foundational setup will serve you well as you begin to build and experiment.
Was this section helpful?
© 2025 ApX Machine Learning