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
- Accept the Assignment — Click the GitHub Classroom link above
- Clone Your Repo —
git clone <your-repo-url> - Read the README — Your repo has detailed requirements and grading criteria
- Write Your Code — Implement the solution in
solution/agent.py - Test Locally — Use
swaig-testto verify your agent works - Push to Submit —
git pushtriggers 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:
- What does the SWML contain?
- Is there a prompt defined?
- 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:
- Where does your prompt appear in the SWML?
- 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:
- What does the
languagesarray contain? - 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:
versionfieldsectionsobjectmainarrayaiverbpromptobjectlanguagesarray
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:
- Is the output different from the functional version?
- 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:
hello_agent.py- functional patternhello_class_agent.py- class patternhello_swml.json- generated SWML
Review Questions
- What is the minimum required to create an agent?
- What does
agent.run()do? - Why use
if __name__ == "__main__"? - What’s the difference between functional and class-based patterns?
- Where does the prompt appear in SWML?
Summary
You have successfully:
- Created a minimal agent
- Added prompt configuration
- Added voice configuration
- Examined generated SWML
- 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()