Intermediate 25 min

Setting Up Your Environment

Let’s get your development environment ready. This is straightforward—we’ll create a virtual environment, install one package, and set your API key.

Step 1: Create Project Directory

First, create a directory for your agent project:

mkdir plan-execute-agent
cd plan-execute-agent

Create a simple structure:

mkdir notes output
  • notes/ - Sample markdown files for the agent to read
  • output/ - Where the agent will write results

Step 2: Create Virtual Environment

Create and activate a Python virtual environment:


              ```bash
# Create virtual environment
python3 -m venv venv

# Activate it
source venv/bin/activate
```
            

You should see (venv) in your terminal prompt when activated.

Step 3: Install OpenAI SDK

Install the OpenAI Python SDK:

pip install openai

That’s it. One dependency. The SDK handles all the API communication for you.

Verify installation:

python -c "import openai; print(openai.__version__)"

You should see a version number like 1.12.0 or higher.

Step 4: Get Your API Key

You need an OpenAI API key to use the models.

Get your key:

  1. Go to platform.openai.com
  2. Sign up or log in
  3. Navigate to API Keys section
  4. Create a new secret key
  5. Copy it (you won’t see it again!)

Set the environment variable:


              ```bash
# Set for current session
export OPENAI_API_KEY="sk-your-key-here"

# Or add to ~/.bashrc or ~/.zshrc for persistence
echo 'export OPENAI_API_KEY="sk-your-key-here"' >> ~/.bashrc
source ~/.bashrc
```
            

Verify it’s set:

python -c "import os; print('Key set!' if os.getenv('OPENAI_API_KEY') else 'Key not found')"

Step 5: Create Sample Notes

Create a few sample markdown files in the notes/ directory. The agent will read these:

notes/2026-01-20.md:

# Monday, January 20, 2026

## Completed
- Finished RAG tutorial
- Started agent project
- Read 3 research papers on tool calling

## Notes
- RAG is powerful for grounding LLM responses
- Agents need approval gates for safety
- Tool calling is the foundation of agentic systems

## Tomorrow
- Build the agent loop
- Add tool definitions

notes/2026-01-21.md:

# Tuesday, January 21, 2026

## Completed
- Implemented basic agent loop
- Added list_files and read_file tools
- Tested with sample data

## Challenges
- Managing conversation state is tricky
- Need to cap iterations to avoid infinite loops

## Tomorrow
- Add approval gates
- Implement write_file tool

notes/2026-01-22.md:

# Wednesday, January 22, 2026

## Completed
- Added approval gate for write_file
- Implemented send_message tool (mocked)
- Tested full agent flow

## Insights
- Approval gates are simple but effective
- Plan-and-execute pattern works well
- Tool schemas need to be precise

## Next Steps
- Add debugging features
- Write tutorial

Step 6: Test Your Setup

Create a simple test file to verify everything works:

test_setup.py:

🐍 Python Test Your Setup
📟 Console Output
Run code to see output...

Run it:

python test_setup.py

You should see:

✅ API key found
✅ API connection works: Setup complete!

🎉 Setup complete! Ready to build your agent.

Project Structure

Your project should now look like this:

plan-execute-agent/
├── venv/                 # Virtual environment
├── notes/                # Sample markdown files
│   ├── 2026-01-20.md
│   ├── 2026-01-21.md
│   └── 2026-01-22.md
├── output/               # Agent output directory (empty for now)
└── test_setup.py         # Setup verification script

Troubleshooting

Problem: ModuleNotFoundError: No module named 'openai'

Solution: Make sure your virtual environment is activated. You should see (venv) in your prompt.

source venv/bin/activate  # macOS/Linux
venv\Scripts\activate     # Windows

Problem: AuthenticationError: Invalid API key

Solution: Check that your API key is set correctly:

echo $OPENAI_API_KEY  # macOS/Linux
echo %OPENAI_API_KEY%  # Windows

Make sure it starts with sk- and has no extra spaces or quotes.

Problem: RateLimitError or InsufficientQuotaError

Solution: Check your OpenAI account:

  • Verify you have credits available
  • Check your usage limits at platform.openai.com
  • You may need to add payment information

Problem: Python version too old

Solution: This tutorial requires Python 3.9+. Check your version:

python --version

If it’s older than 3.9, install a newer version from python.org.

Quick Reference

Activate environment:

source venv/bin/activate  # macOS/Linux
venv\Scripts\activate     # Windows

Deactivate environment:

deactivate

Install packages:

pip install openai

Set API key:

export OPENAI_API_KEY="sk-..."  # macOS/Linux
set OPENAI_API_KEY=sk-...       # Windows

Key Takeaways

Setup is done! You now have:

  1. Virtual environment - Isolated Python environment
  2. OpenAI SDK - Installed and ready
  3. API key - Configured and tested
  4. Sample data - Notes for the agent to process
  5. Project structure - Organized directories

What’s Next?

In the next page, we’ll define the tools your agent will use. You’ll learn how to create tool schemas and distinguish between safe and risky operations.