Adding Skills

View as Markdown

Adding Skills

Add skills to your agents with add_skill(). Pass configuration parameters to customize behavior.

Basic Usage

Add a skill with no configuration:

1from signalwire_agents import AgentBase
2
3
4class MyAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="my-agent")
7 self.add_language("English", "en-US", "rime.spore")
8
9 # Add skill with default settings
10 self.add_skill("datetime")

With Configuration

Pass parameters as a dictionary:

1from signalwire_agents import AgentBase
2
3
4class MyAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="my-agent")
7 self.add_language("English", "en-US", "rime.spore")
8
9 # Add skill with configuration
10 self.add_skill("web_search", {
11 "api_key": "YOUR_API_KEY",
12 "search_engine_id": "YOUR_ENGINE_ID",
13 "num_results": 5
14 })

Method Chaining

add_skill() returns self for chaining:

1from signalwire_agents import AgentBase
2
3
4class MyAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="my-agent")
7 self.add_language("English", "en-US", "rime.spore")
8
9 # Chain multiple skills
10 (self
11 .add_skill("datetime")
12 .add_skill("math")
13 .add_skill("joke"))

Multiple Skills

Add as many skills as needed:

1from signalwire_agents import AgentBase
2
3
4class AssistantAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="assistant")
7 self.add_language("English", "en-US", "rime.spore")
8
9 # Add multiple capabilities
10 self.add_skill("datetime")
11 self.add_skill("math")
12 self.add_skill("wikipedia_search")
13
14 self.prompt_add_section(
15 "Role",
16 "You are a helpful assistant."
17 )
18
19 self.prompt_add_section(
20 "Capabilities",
21 body="You can help with:",
22 bullets=[
23 "Date and time information",
24 "Math calculations",
25 "Wikipedia lookups"
26 ]
27 )

Checking Loaded Skills

1## Check if skill is loaded
2if agent.has_skill("datetime"):
3 print("Datetime skill is active")
4
5## List all loaded skills
6skills = agent.list_skills()
7print(f"Loaded skills: {skills}")

Removing Skills

1## Remove a skill
2agent.remove_skill("datetime")

Multi-Instance Skills

Some skills support multiple instances:

1from signalwire_agents import AgentBase
2
3
4class MultiSearchAgent(AgentBase):
5 def __init__(self):
6 super().__init__(name="multi-search")
7 self.add_language("English", "en-US", "rime.spore")
8
9 # First search instance for news
10 self.add_skill("web_search", {
11 "tool_name": "search_news",
12 "api_key": "YOUR_API_KEY",
13 "search_engine_id": "NEWS_ENGINE_ID"
14 })
15
16 # Second search instance for documentation
17 self.add_skill("web_search", {
18 "tool_name": "search_docs",
19 "api_key": "YOUR_API_KEY",
20 "search_engine_id": "DOCS_ENGINE_ID"
21 })
22
23 self.prompt_add_section(
24 "Role",
25 "You can search news and documentation separately."
26 )

SWAIG Fields

Add extra SWAIG metadata to skill functions:

1self.add_skill("datetime", {
2 "swaig_fields": {
3 "fillers": {
4 "en-US": ["Let me check the time..."]
5 }
6 }
7})

Error Handling

Skills may fail to load:

1try:
2 agent.add_skill("web_search", {
3 "api_key": "invalid"
4 })
5except ValueError as e:
6 print(f"Skill failed to load: {e}")

Common errors:

ErrorCauseSolution
Skill not foundInvalid skill nameCheck spelling
Missing parametersRequired config not providedAdd required params
Package not installedMissing Python dependencyInstall with pip
Env var missingRequired environment variableSet the variable

Skills with Environment Variables

Some skills read from environment variables:

1import os
2
3## Set API key via environment
4os.environ["GOOGLE_SEARCH_API_KEY"] = "your-key"
5
6## Skill can read from env
7self.add_skill("web_search", {
8 "api_key": os.environ["GOOGLE_SEARCH_API_KEY"],
9 "search_engine_id": "your-engine-id"
10})

Complete Example

1#!/usr/bin/env python3
2## full_featured_agent.py - Agent with multiple configured skills
3from signalwire_agents import AgentBase
4
5
6class FullFeaturedAgent(AgentBase):
7 def __init__(self):
8 super().__init__(name="full-featured")
9 self.add_language("English", "en-US", "rime.spore")
10
11 # Simple skills (no config needed)
12 self.add_skill("datetime")
13 self.add_skill("math")
14
15 self.prompt_add_section(
16 "Role",
17 "You are a versatile assistant named Alex."
18 )
19
20 self.prompt_add_section(
21 "Capabilities",
22 body="You can help with:",
23 bullets=[
24 "Current date and time",
25 "Math calculations"
26 ]
27 )
28
29
30if __name__ == "__main__":
31 agent = FullFeaturedAgent()
32 agent.run()

Skills like web_search and joke require additional configuration or API keys. See the Built-in Skills section for details on each skill’s requirements.

Best Practices

DO:

  • Add skills in init before prompt configuration
  • Use environment variables for API keys
  • Check skill availability with has_skill() if conditional
  • Update prompts to mention skill capabilities

DON’T:

  • Hardcode API keys in source code
  • Add duplicate skills (unless multi-instance)
  • Assume skills are available without checking
  • Forget to handle skill loading errors