Lesson 3: Creating Fred's Basic Structure 🔗 ↑ TOC

Time to bring Fred to life! In this lesson, we'll create Fred's foundation - his personality, voice, and basic configuration.

Table of Contents 🔗 ↑ TOC

  1. Creating the Agent Class
  2. Defining Fred's Personality
  3. Configuring Voice and Language
  4. Setting Conversation Parameters
  5. Adding Speech Recognition Hints

Creating the Agent Class 🔗 ↑ TOC

Let's start by creating Fred's basic structure. Create a new file called fred.py:

Step 1: Import and Class Definition 🔗 ↑ TOC

#!/usr/bin/env python3
"""
Fred - The Wikipedia Knowledge Bot

A friendly agent that can search Wikipedia for factual information.
Fred is curious, helpful, and loves sharing knowledge from Wikipedia.
"""

from signalwire_agents import AgentBase
from signalwire_agents.core.function_result import SwaigFunctionResult

class FredTheWikiBot(AgentBase):
    """Fred - Your friendly Wikipedia assistant"""

    def __init__(self):
        super().__init__(
            name="Fred",
            route="/fred"
        )

What's happening here:

Defining Fred's Personality 🔗 ↑ TOC

Now let's give Fred his friendly personality using the Prompt Object Model (POM):

Step 2: Add Personality Section 🔗 ↑ TOC

def __init__(self):
    super().__init__(
        name="Fred",
        route="/fred"
    )

    # Set up Fred's personality using POM
    self.prompt_add_section(
        "Personality", 
        "You are Fred, a friendly and knowledgeable assistant who loves learning and sharing information from Wikipedia. You're enthusiastic about facts and always eager to help people discover new things."
    )

Step 3: Add Goal and Instructions 🔗 ↑ TOC

    # Define Fred's primary goal
    self.prompt_add_section(
        "Goal",
        "Help users find reliable factual information by searching Wikipedia. Make learning fun and engaging."
    )

    # Add specific instructions for Fred's behavior
    self.prompt_add_section(
        "Instructions",
        bullets=[
            "Introduce yourself as Fred when greeting users",
            "Use the search_wiki function whenever users ask about factual topics",
            "Be enthusiastic about sharing knowledge",
            "If Wikipedia doesn't have information, suggest alternative search terms",
            "Make learning conversational and enjoyable",
            "Add interesting context or follow-up questions to engage users"
        ]
    )

POM Sections Explained:

Configuring Voice and Language 🔗 ↑ TOC

Let's give Fred a voice! SignalWire supports multiple Text-to-Speech providers:

Step 4: Add Language Configuration 🔗 ↑ TOC

    # Configure Fred's voice
    self.add_language(
        name="English",
        code="en-US",
        voice="rime.bolt",  # A friendly, energetic voice for Fred
        speech_fillers=[
            "Hmm, let me think...",
            "Oh, that's interesting...",
            "Great question!",
            "Let me see..."
        ]
    )

Voice Configuration:

Available Voice Options 🔗 ↑ TOC

# Other voice examples:
# "rime.spore" - Professional, clear
# "rime.marsh" - Deep, authoritative  
# "rime.cove" - Warm, friendly
# "elevenlabs.rachel" - Natural, conversational

Setting Conversation Parameters 🔗 ↑ TOC

Now let's configure how Fred interacts during conversations:

Step 5: Set AI Parameters 🔗 ↑ TOC

    # Set conversation parameters
    self.set_params({
        "ai_model": "gpt-4.1-nano",       # The AI model to use
        "wait_for_user": True,            # Wait for user to speak first
        "end_of_speech_timeout": 1000,    # Milliseconds of silence before assuming speech ended
        "ai_volume": 7,                   # Voice volume level (1-10)
        "local_tz": "America/New_York"    # Timezone for time-related functions
    })

Parameter Breakdown:

Step 6: Add Global Context 🔗 ↑ TOC

    # Add some context about Fred
    self.set_global_data({
        "assistant_name": "Fred",
        "specialty": "Wikipedia knowledge",
        "personality_traits": ["friendly", "curious", "enthusiastic", "helpful"]
    })

This data is available to the AI during conversations, helping maintain consistency.

Adding Speech Recognition Hints 🔗 ↑ TOC

Help the speech recognition system understand domain-specific terms:

Step 7: Add Recognition Hints 🔗 ↑ TOC

    # Add hints for better speech recognition
    self.add_hints([
        "Wikipedia",
        "Fred",
        "tell me about",
        "what is",
        "who is",
        "search for",
        "look up"
    ])

These hints improve accuracy when users say these phrases.

Complete Basic Structure 🔗 ↑ TOC

Here's Fred's complete basic structure so far:

#!/usr/bin/env python3
"""
Fred - The Wikipedia Knowledge Bot

A friendly agent that can search Wikipedia for factual information.
Fred is curious, helpful, and loves sharing knowledge from Wikipedia.
"""

from signalwire_agents import AgentBase
from signalwire_agents.core.function_result import SwaigFunctionResult

class FredTheWikiBot(AgentBase):
    """Fred - Your friendly Wikipedia assistant"""

    def __init__(self):
        super().__init__(
            name="Fred",
            route="/fred"
        )

        # Set up Fred's personality using POM
        self.prompt_add_section(
            "Personality", 
            "You are Fred, a friendly and knowledgeable assistant who loves learning and sharing information from Wikipedia. You're enthusiastic about facts and always eager to help people discover new things."
        )

        self.prompt_add_section(
            "Goal",
            "Help users find reliable factual information by searching Wikipedia. Make learning fun and engaging."
        )

        self.prompt_add_section(
            "Instructions",
            bullets=[
                "Introduce yourself as Fred when greeting users",
                "Use the search_wiki function whenever users ask about factual topics",
                "Be enthusiastic about sharing knowledge",
                "If Wikipedia doesn't have information, suggest alternative search terms",
                "Make learning conversational and enjoyable",
                "Add interesting context or follow-up questions to engage users"
            ]
        )

        # Configure Fred's voice
        self.add_language(
            name="English",
            code="en-US",
            voice="rime.bolt",  # A friendly, energetic voice for Fred
            speech_fillers=[
                "Hmm, let me think...",
                "Oh, that's interesting...",
                "Great question!",
                "Let me see..."
            ]
        )

        # Add hints for better speech recognition
        self.add_hints([
            "Wikipedia",
            "Fred",
            "tell me about",
            "what is",
            "who is",
            "search for",
            "look up"
        ])

        # Set conversation parameters
        self.set_params({
            "ai_model": "gpt-4.1-nano",
            "wait_for_user": True,
            "end_of_speech_timeout": 1000,
            "ai_volume": 7,
            "local_tz": "America/New_York"
        })

        # Add some context about Fred
        self.set_global_data({
            "assistant_name": "Fred",
            "specialty": "Wikipedia knowledge",
            "personality_traits": ["friendly", "curious", "enthusiastic", "helpful"]
        })

Testing the Basic Structure 🔗 ↑ TOC

Add a simple main function to test:

def main():
    """Test Fred's basic structure"""
    fred = FredTheWikiBot()
    print(f"✅ Fred created successfully!")
    print(f"   Name: {fred.get_name()}")
    print(f"   Route: /fred")
    print(f"   Ready to add capabilities!")

if __name__ == "__main__":
    main()

Run it:

python fred.py

Expected output:

✅ Fred created successfully!
   Name: Fred
   Route: /fred
   Ready to add capabilities!

Key Concepts Review 🔗 ↑ TOC

Prompt Object Model (POM) 🔗 ↑ TOC

POM organizes your agent's instructions into logical sections:

Voice Configuration 🔗 ↑ TOC

Global Data 🔗 ↑ TOC

Next Steps 🔗 ↑ TOC

Fred now has personality and voice, but he can't search Wikipedia yet. Let's add that capability!

➡️ Continue to Lesson 4: Adding the Wikipedia Search Skill


Progress Check:


← Previous: Environment Setup | Back to Overview | Next: Wikipedia Skill →