Lab L1.2: Hello World Agent

🎯 Assignment: Accept this lab on GitHub Classroom
You’ll get your own repository with starter code, instructions, and automatic grading.

   
Duration 45 minutes
Prerequisites Previous module completed

Objectives

  • Create a minimal working agent
  • Configure basic prompt and voice
  • Test with swaig-test CLI
  • Understand generated SWML

How to Complete This Lab

  1. Accept the Assignment — Click the GitHub Classroom link above
  2. Clone Your Repogit clone <your-repo-url>
  3. Read the README — Your repo has detailed requirements and grading criteria
  4. Write Your Code — Implement the solution in solution/agent.py
  5. Test Locally — Use swaig-test to verify your agent works
  6. Push to Submitgit push triggers auto-grading

Key Concepts

The following exercises walk through the concepts you’ll need. Your GitHub Classroom repo README has the specific requirements for grading.

Exercise 1: Minimal Agent

Create the simplest possible agent:

Create hello_agent.py:

#!/usr/bin/env python3
"""Minimal Hello World agent."""

from signalwire_agents import AgentBase

# Create agent with just a name
agent = AgentBase(name="hello-agent")

if __name__ == "__main__":
    agent.run()

Test with swaig-test:

swaig-test hello_agent.py --dump-swml

Questions to Answer:

  1. What does the SWML contain?
  2. Is there a prompt defined?
  3. What language/voice is configured?

Exercise 2: Add Prompt

Update the agent with a basic prompt:

Update hello_agent.py:

#!/usr/bin/env python3
"""Hello World agent with prompt."""

from signalwire_agents import AgentBase

agent = AgentBase(name="hello-agent")

# Add a prompt
agent.prompt_add_section(
    "Role",
    "You are a friendly assistant. When someone calls, "
    "greet them warmly and ask how you can help today."
)

if __name__ == "__main__":
    agent.run()

Test again:

swaig-test hello_agent.py --dump-swml

Questions to Answer:

  1. Where does your prompt appear in the SWML?
  2. How is the section title used?

Exercise 3: Add Voice Configuration

Add language and voice:

Update hello_agent.py:

#!/usr/bin/env python3
"""Hello World agent with prompt and voice."""

from signalwire_agents import AgentBase

agent = AgentBase(name="hello-agent")

agent.prompt_add_section(
    "Role",
    "You are a friendly assistant. When someone calls, "
    "greet them warmly and ask how you can help today."
)

# Add voice configuration
agent.add_language("English", "en-US", "rime.spore")

if __name__ == "__main__":
    agent.run()

Test:

swaig-test hello_agent.py --dump-swml

Questions to Answer:

  1. What does the languages array contain?
  2. What fields are in each language object?

Exercise 4: Examine SWML Structure

Save and analyze the SWML:

swaig-test hello_agent.py --dump-swml --raw > hello_swml.json

Open hello_swml.json in your editor.

Identify these elements:

  • version field
  • sections object
  • main array
  • ai verb
  • prompt object
  • languages array

Draw the hierarchy:

{
  version
  sections
    main
      ai
        prompt
          text
        languages
          [0]
            name
            code
            voice
}

Exercise 5: Class-Based Agent

Convert to class-based pattern:

Create hello_class_agent.py:

#!/usr/bin/env python3
"""Hello World agent using class pattern."""

from signalwire_agents import AgentBase


class HelloAgent(AgentBase):
    """A friendly greeting agent."""

    def __init__(self):
        super().__init__(name="hello-class-agent")
        self._configure_prompt()
        self._configure_voice()

    def _configure_prompt(self):
        """Set up the agent's prompt."""
        self.prompt_add_section(
            "Role",
            "You are a friendly assistant. When someone calls, "
            "greet them warmly and ask how you can help today."
        )

    def _configure_voice(self):
        """Set up voice and language."""
        self.add_language("English", "en-US", "rime.spore")


if __name__ == "__main__":
    agent = HelloAgent()
    agent.run()

Test:

swaig-test hello_class_agent.py --dump-swml

Questions to Answer:

  1. Is the output different from the functional version?
  2. What are the benefits of the class-based pattern?

Exercise 6: Run Locally

Start your agent server:

python hello_agent.py

Expected Output:

INFO:     Started server process [XXXXX]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3000

In another terminal, test with curl:

curl http://localhost:3000/

You should get the SWML JSON response.

Stop the server: Press Ctrl+C


Exercise 7: Change Port

Run on a different port:

PORT=5000 python hello_agent.py

Test:

curl http://localhost:5000/

Challenge Exercise (Optional)

Create an agent with:

  • Custom name: “greeter-bot”
  • Custom route: “/greet”
  • Prompt with multiple sections
  • Different voice (try rime.marsh)

Verify:

swaig-test your_agent.py --dump-swml

Deliverables

Submit or show instructor:

  1. hello_agent.py - functional pattern
  2. hello_class_agent.py - class pattern
  3. hello_swml.json - generated SWML

Review Questions

  1. What is the minimum required to create an agent?
  2. What does agent.run() do?
  3. Why use if __name__ == "__main__"?
  4. What’s the difference between functional and class-based patterns?
  5. Where does the prompt appear in SWML?

Summary

You have successfully:

  1. Created a minimal agent
  2. Added prompt configuration
  3. Added voice configuration
  4. Examined generated SWML
  5. Ran the agent locally

Next: Lab 1.3 - SWML Inspection


Complete Agent Code

Click to reveal complete solution
#!/usr/bin/env python3
"""Hello World agent with prompt and voice - Functional Pattern.

Lab 1.2 Deliverable: Demonstrates the functional approach to creating
a SignalWire AI agent with basic prompt and voice configuration.
"""

from signalwire_agents import AgentBase

agent = AgentBase(name="hello-agent")

# Add prompt configuration
agent.prompt_add_section(
    "Role",
    "You are a friendly assistant. When someone calls, "
    "greet them warmly and ask how you can help today."
)

# Add voice configuration
agent.add_language("English", "en-US", "rime.spore")

if __name__ == "__main__":
    agent.run()

Back to top

SignalWire AI Agents Certification Program