Follow AiTechWorlds on LinkedIn for professional AI content!Follow Now →
14 minLesson 4 of 23
Agent Fundamentals

Setting Up Your Agent Dev Environment

Setting Up Your Agent Development Environment

A well-configured development environment makes agent development dramatically less frustrating. This lesson walks through everything you need: Python environment, API keys, essential packages, and the project structure that scales as your agents grow.

Requirements

  • Python 3.11 or 3.12 (avoid 3.13 — some packages have compatibility lag)
  • A code editor (VS Code with Python extension, or Cursor)
  • OpenAI API key (required), Anthropic API key (optional but recommended)
  • Search API key (Tavily recommended for agents)

Python Environment Setup

Use a virtual environment or conda to keep agent project dependencies isolated:

# Create a new project directory
mkdir my-agent && cd my-agent

# Create virtual environment
python -m venv .venv

# Activate (Windows)
.venv\Scripts\activate

# Activate (Mac/Linux)
source .venv/bin/activate

# Verify Python version
python --version  # Should be 3.11 or 3.12

Core Packages

Install the foundation:

# LLM SDKs
pip install openai anthropic

# LangChain ecosystem
pip install langchain langchain-openai langchain-anthropic langchain-community

# LangGraph (for multi-agent and graph-based workflows)
pip install langgraph

# Vector database clients
pip install chromadb pinecone-client

# Search and tools
pip install tavily-python  # Web search API
pip install duckduckgo-search  # Free search (lower quality)

# Utilities
pip install python-dotenv  # Load .env files
pip install pydantic  # Data validation
pip install rich  # Pretty terminal output
pip install httpx  # Async HTTP client

# Save your requirements
pip freeze > requirements.txt

Environment Variables

Create a .env file in your project root:

# .env
OPENAI_API_KEY=sk-proj-...
ANTHROPIC_API_KEY=sk-ant-...
TAVILY_API_KEY=tvly-...
LANGCHAIN_API_KEY=...           # For LangSmith tracing (optional but valuable)
LANGCHAIN_TRACING_V2=true       # Enable LangSmith tracing
LANGCHAIN_PROJECT=my-agent      # Project name in LangSmith

# For vector databases
PINECONE_API_KEY=...
PINECONE_ENVIRONMENT=us-east-1

# For later — if you deploy
REDIS_URL=redis://localhost:6379

Add .env to .gitignore immediately:

echo ".env" >> .gitignore
echo ".venv/" >> .gitignore
echo "__pycache__/" >> .gitignore
echo "*.pyc" >> .gitignore

Load environment variables in your Python code:

from dotenv import load_dotenv
import os

load_dotenv()  # Loads .env file

openai_key = os.environ["OPENAI_API_KEY"]  # Raises error if missing
anthropic_key = os.getenv("ANTHROPIC_API_KEY")  # Returns None if missing

Getting API Keys

OpenAI

  1. platform.openai.com → Sign in
  2. API Keys → Create new secret key
  3. Set a spending limit: Usage → Limits → Set a monthly budget ($20-50 for development)
  4. Copy the key to .env — you won't see it again

Minimum required for this course: OpenAI API key ($5-10 for typical development work)

Anthropic (Claude)

  1. console.anthropic.com → Sign in
  2. API Keys → Create Key
  3. Claude Sonnet is the best balance of capability and cost for agent development
  1. app.tavily.com → Sign up
  2. Free tier: 1,000 API calls/month (sufficient for development)
  3. Best quality search results for agent use cases

LangSmith provides observability for your agents — you can see exactly what prompts were sent, what tools were called, how long each step took, and what the LLM returned.

  1. smith.langchain.com → Sign up
  2. Create an API key
  3. Add to .env with the variables above
  4. Free tier is generous for development

Once configured, every LangChain/LangGraph run is automatically traced and visible in the LangSmith dashboard.

Project Structure

A clean structure that scales:

my-agent/
├── .env                    # API keys (never commit)
├── .gitignore
├── requirements.txt
├── README.md
│
├── agents/
│   ├── __init__.py
│   ├── research_agent.py   # Agent definitions
│   └── coding_agent.py
│
├── tools/
│   ├── __init__.py
│   ├── search.py           # Tool implementations
│   ├── code_execution.py
│   └── file_tools.py
│
├── memory/
│   ├── __init__.py
│   └── vector_store.py     # Vector database setup
│
├── prompts/
│   └── templates.py        # System prompts as constants
│
└── main.py                 # Entry point

Verify Your Setup

Create test_setup.py and run it:

# test_setup.py
import os
from dotenv import load_dotenv

load_dotenv()

def test_openai():
    from openai import OpenAI
    client = OpenAI()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Say 'setup successful' and nothing else"}]
    )
    print(f"OpenAI: {response.choices[0].message.content}")

def test_anthropic():
    import anthropic
    client = anthropic.Anthropic()
    message = client.messages.create(
        model="claude-haiku-4-5-20251001",
        max_tokens=50,
        messages=[{"role": "user", "content": "Say 'setup successful' and nothing else"}]
    )
    print(f"Anthropic: {message.content[0].text}")

def test_tavily():
    from tavily import TavilyClient
    client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
    result = client.search("Python agent development", max_results=1)
    print(f"Tavily: Found {len(result['results'])} results")

def test_langchain():
    from langchain_openai import ChatOpenAI
    llm = ChatOpenAI(model="gpt-4o-mini")
    response = llm.invoke("Say 'langchain works' and nothing else")
    print(f"LangChain: {response.content}")

if __name__ == "__main__":
    print("Testing setup...\n")
    test_openai()
    test_anthropic()
    test_tavily()
    test_langchain()
    print("\nAll tests passed!")

Run with python test_setup.py. Fix any failures before continuing.

Cost Management During Development

LLM APIs charge per token. Develop cheaply:

Use smaller models for testing:

# During development
model = "gpt-4o-mini"  # ~15x cheaper than gpt-4o
model = "claude-haiku-4-5-20251001"  # Cheapest Claude

# Switch to powerful models only when needed
model = "gpt-4o"
model = "claude-sonnet-4-6"

Set spending limits: OpenAI lets you set a monthly cap — set $20-30 during development to prevent unexpected charges.

Use LangSmith to see where you're spending: Token counts per run are visible in traces.

Cache where possible: LangChain and LangGraph have built-in caching — repeat calls with identical prompts return cached responses for free during development.

Editor Setup

VS Code extensions for agent development:

  • Python (Microsoft) — essential
  • Pylance — type checking and autocomplete
  • GitHub Copilot or Cursor — AI assistance
  • REST Client — test API calls inline

.vscode/settings.json:

{
    "python.defaultInterpreterPath": ".venv/bin/python",
    "python.linting.enabled": true,
    "editor.formatOnSave": true,
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter"
    }
}

With this environment set up, you're ready to start building agents. The next lesson begins with LangChain — the most widely used agent framework.

Next lesson: LangChain architecture — understanding the components that power AI agents.

📱

Get this course's notes on Telegram!

Free cheat sheets, summaries & practice exercises

Get Notes Free →
!