Adding Skills

View as MarkdownOpen in Claude

Basic Usage

Add a skill with no configuration:

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

With Configuration

Pass parameters as a dictionary (or map/hash depending on language):

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

Method Chaining

add_skill() returns self for chaining (in languages that support it):

LanguageChaining syntax
Pythonself.add_skill("datetime").add_skill("math").add_skill("joke")
TypeScriptawait agent.addSkill(new DateTimeSkill()); await agent.addSkill(new MathSkill()); await agent.addSkill(new JokeSkill());
1from signalwire import AgentBase
2
3class MyAgent(AgentBase):
4 def __init__(self):
5 super().__init__(name="my-agent")
6 self.add_language("English", "en-US", "rime.spore")
7
8 # Chain multiple skills
9 (self
10 .add_skill("datetime")
11 .add_skill("math")
12 .add_skill("joke"))

Multiple Skills

Add as many skills as needed:

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

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. Give each instance a unique tool_name:

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

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 import AgentBase
4
5class FullFeaturedAgent(AgentBase):
6 def __init__(self):
7 super().__init__(name="full-featured")
8 self.add_language("English", "en-US", "rime.spore")
9
10 # Simple skills (no config needed)
11 self.add_skill("datetime")
12 self.add_skill("math")
13
14 self.prompt_add_section(
15 "Role",
16 "You are a versatile assistant named Alex."
17 )
18
19 self.prompt_add_section(
20 "Capabilities",
21 body="You can help with:",
22 bullets=[
23 "Current date and time",
24 "Math calculations"
25 ]
26 )
27
28if __name__ == "__main__":
29 agent = FullFeaturedAgent()
30 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