Lesson 2: Setting Up Your Environment 🔗 ↑ TOC

Let's get your development environment ready to build Fred! This lesson covers installing the SignalWire AI Agents SDK and verifying everything works correctly.

Table of Contents 🔗 ↑ TOC

  1. Prerequisites Check
  2. Installing the SDK
  3. Verifying Installation
  4. Understanding Dependencies
  5. Project Structure

Prerequisites Check 🔗 ↑ TOC

Before we begin, ensure you have:

Required Software 🔗 ↑ TOC

Python 3.7+

Check your Python version:

python3 --version
# or
python --version

You should see something like:

Python 3.8.10

pip (Python Package Manager)

Verify pip is installed:

pip3 --version
# or
pip --version

Virtual Environment (Recommended)

It's best practice to use a virtual environment:

# Create a virtual environment
python3 -m venv fred-env

# Activate it
# On Linux/Mac:
source fred-env/bin/activate

# On Windows:
fred-env\Scripts\activate

Installing the SDK 🔗 ↑ TOC

Now let's install the SignalWire AI Agents SDK:

Basic Installation 🔗 ↑ TOC

pip install signalwire-agents

This installs the core SDK with all required dependencies.

What Gets Installed 🔗 ↑ TOC

The installation includes:

Verifying Installation 🔗 ↑ TOC

Let's verify everything installed correctly:

Test Import 🔗 ↑ TOC

Create a test file called test_install.py:

#!/usr/bin/env python3
"""Test SignalWire SDK installation"""

try:
    from signalwire_agents import AgentBase
    print("✅ SignalWire SDK imported successfully!")

    # Check version
    import signalwire_agents
    print(f"   Version: {signalwire_agents.__version__}")

except ImportError as e:
    print(f"❌ Import failed: {e}")
    print("   Please run: pip install signalwire-agents")

Run it:

python test_install.py

Expected output:

✅ SignalWire SDK imported successfully!
   Version: 0.1.23

Test Basic Agent 🔗 ↑ TOC

Let's create a minimal agent to ensure everything works:

#!/usr/bin/env python3
"""Minimal test agent"""

from signalwire_agents import AgentBase

# Create a minimal agent
agent = AgentBase("Test Agent", route="/test")

# If this runs without errors, installation is good!
print("✅ Basic agent creation works!")
print(f"   Agent name: {agent.get_name()}")
print(f"   Agent route: /test")

Understanding Dependencies 🔗 ↑ TOC

The SDK has several dependency categories:

Core Dependencies 🔗 ↑ TOC

Always Installed:

Optional Dependencies 🔗 ↑ TOC

Search Features (we won't need these for Fred):

# If you wanted search features:
pip install signalwire-agents[search]

Development Tools (optional but helpful):

# For testing
pip install pytest

# For code formatting
pip install black

# For linting
pip install pylint

Project Structure 🔗 ↑ TOC

Let's set up a clean project structure for Fred:

Create Project Directory 🔗 ↑ TOC

# Create Fred's directory
mkdir fred-bot
cd fred-bot

# Create subdirectories
mkdir logs
mkdir config
fred-bot/
├── fred.py           # Main agent code
├── fred.sh           # Management script
├── requirements.txt  # Dependencies
├── config/          # Configuration files
├── logs/            # Log files
└── README.md        # Documentation

Create requirements.txt 🔗 ↑ TOC

Save your dependencies for easy reinstallation:

# Generate requirements file
pip freeze > requirements.txt

Or create a minimal one:

signalwire-agents>=0.1.23

Environment Variables 🔗 ↑ TOC

The SDK uses several optional environment variables:

Authentication (Optional) 🔗 ↑ TOC

# Set fixed credentials (optional)
export SWML_BASIC_AUTH_USER="fred_user"
export SWML_BASIC_AUTH_PASSWORD="fred_pass123"

# Or let the SDK generate random ones

Proxy Configuration (If Needed) 🔗 ↑ TOC

# If behind a proxy or using ngrok
export SWML_PROXY_URL_BASE="https://your-domain.com"

Testing Your Setup 🔗 ↑ TOC

Let's create a simple test to ensure everything is ready:

#!/usr/bin/env python3
"""Setup verification script"""

import sys

def check_setup():
    """Verify environment is ready for Fred"""

    print("🔍 Checking Fred's environment...\n")

    # Check Python version
    python_version = sys.version_info
    if python_version >= (3, 7):
        print(f"✅ Python {python_version.major}.{python_version.minor} - Good!")
    else:
        print(f"❌ Python {python_version.major}.{python_version.minor} - Need 3.7+")
        return False

    # Check imports
    try:
        import signalwire_agents
        print("✅ SignalWire SDK - Installed")
    except ImportError:
        print("❌ SignalWire SDK - Not installed")
        return False

    try:
        import fastapi
        print("✅ FastAPI - Installed")
    except ImportError:
        print("❌ FastAPI - Not installed")
        return False

    try:
        import uvicorn
        print("✅ Uvicorn - Installed")
    except ImportError:
        print("❌ Uvicorn - Not installed")
        return False

    print("\n🎉 Environment is ready to build Fred!")
    return True

if __name__ == "__main__":
    if not check_setup():
        print("\n⚠️  Please install missing dependencies:")
        print("   pip install signalwire-agents")
        sys.exit(1)

Common Installation Issues 🔗 ↑ TOC

Issue: Permission Denied 🔗 ↑ TOC

# Use --user flag
pip install --user signalwire-agents

# Or use sudo (less recommended)
sudo pip install signalwire-agents

Issue: pip Not Found 🔗 ↑ TOC

# Install pip
python3 -m ensurepip

# Or on Ubuntu/Debian
sudo apt-get install python3-pip

Issue: SSL Certificate Errors 🔗 ↑ TOC

# Upgrade certificates
pip install --upgrade certifi

# Or temporarily (not recommended for production)
pip install --trusted-host pypi.org signalwire-agents

Next Steps 🔗 ↑ TOC

Great! Your environment is ready. Let's start building Fred!

➡️ Continue to Lesson 3: Creating Fred's Basic Structure


Checklist:


← Previous: Introduction | Back to Overview | Next: Basic Agent →