Skip to content
Naveen Raj

Building AI Agents from Scratch with Python · Building the Core Loop

Setting Up the Environment

You need three things: Python 3.10+, an LLM API client, and a place to keep the code.

mkdir agent-from-scratch && cd agent-from-scratch
python -m venv .venv
source .venv/bin/activate  # .venv\Scripts\activate on Windows
pip install anthropic python-dotenv

Create a .env file with your API key:

ANTHROPIC_API_KEY=sk-ant-...

And a minimal sanity check before building anything else:

# check_setup.py
import os
from dotenv import load_dotenv
from anthropic import Anthropic

load_dotenv()
client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

response = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=100,
    messages=[{"role": "user", "content": "Say hi in five words."}],
)
print(response.content[0].text)

If that prints a greeting, the environment is ready. Everything from here is plain Python — no framework required.