Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
62 changes: 31 additions & 31 deletions fern/products/sdks/pages/guides/build-ai-agents/adding-skills.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ Add a skill with no configuration:
| Java | `agent.addSkill("datetime", Map.of())` |
| Perl | `$agent->add_skill('datetime')` |
| C++ | `agent.add_skill("datetime")` |
| PHP | `$agent->addSkill('datetime')` |
| C# | `agent.AddSkill("datetime")` |
*/}
| PHP | `$agent->addSkill('datetime')` |

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

class MyAgent(AgentBase):
def __init__(self):
Expand All @@ -51,12 +51,12 @@ Pass parameters as a dictionary (or map/hash depending on language):
| Java | `agent.addSkill("web_search", Map.of("api_key", "KEY", "num_results", 5))` |
| Perl | `$agent->add_skill('web_search', { api_key => 'KEY', num_results => 5 })` |
| C++ | `agent.add_skill("web_search", {{"api_key", "KEY"}, {"num_results", "5"}})` |
| PHP | `$agent->addSkill('web_search', ['api_key' => 'KEY', 'num_results' => 5])` |
| C# | `agent.AddSkill("web_search", new Dictionary<string, object> { ["api_key"] = "KEY", ["num_results"] = 5 })` |
*/}
| PHP | `$agent->addSkill('web_search', ['api_key' => 'KEY', 'num_results' => 5])` |

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

class MyAgent(AgentBase):
def __init__(self):
Expand Down Expand Up @@ -85,12 +85,12 @@ class MyAgent(AgentBase):
| Java | `agent.addSkill("datetime", Map.of()).addSkill("math", Map.of())` |
| Perl | `$agent->add_skill('datetime')->add_skill('math')->add_skill('joke')` |
| C++ | `agent.add_skill("datetime").add_skill("math").add_skill("joke")` |
| PHP | `$agent->addSkill('datetime')->addSkill('math')->addSkill('joke')` |
| C# | `agent.AddSkill("datetime").AddSkill("math").AddSkill("joke")` |
*/}
| PHP | `$agent->addSkill('datetime')->addSkill('math')->addSkill('joke')` |

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

class MyAgent(AgentBase):
def __init__(self):
Expand All @@ -109,7 +109,7 @@ class MyAgent(AgentBase):
Add as many skills as needed:

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

class AssistantAgent(AgentBase):
def __init__(self):
Expand Down Expand Up @@ -170,12 +170,12 @@ Some skills support multiple instances. Give each instance a unique `tool_name`:
| Java | `agent.addSkill("web_search", Map.of("tool_name", "search_news", ...))` |
| Perl | `$agent->add_skill('web_search', { tool_name => 'search_news', ... })` |
| C++ | `agent.add_skill("web_search", {{"tool_name", "search_news"}, ...})` |
| PHP | `$agent->addSkill('web_search', ['tool_name' => 'search_news', ...])` |
| C# | `agent.AddSkill("web_search", new Dictionary<string, object> { ["tool_name"] = "search_news", ... })` |
*/}
| PHP | `$agent->addSkill('web_search', ['tool_name' => 'search_news', ...])` |

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

class MultiSearchAgent(AgentBase):
def __init__(self):
Expand Down Expand Up @@ -261,7 +261,7 @@ self.add_skill("web_search", {
```python
#!/usr/bin/env python3
## full_featured_agent.py - Agent with multiple configured skills
from signalwire import AgentBase
from signalwire_agents import AgentBase

class FullFeaturedAgent(AgentBase):
def __init__(self):
Expand Down Expand Up @@ -336,7 +336,7 @@ func main() {
</Tab>
<Tab title="Ruby">
```ruby
require 'signalwire'
require 'signalwire_agents'

agent = SignalWireAgents::AgentBase.new(name: 'full-featured')
agent.add_language('English', 'en-US', 'rime.spore')
Expand Down Expand Up @@ -419,26 +419,6 @@ int main() {
}
```
</Tab>
<Tab title="PHP">
```php
use SignalWire\Agent\AgentBase;

$agent = new AgentBase(name: 'full-featured');
$agent->addLanguage('English', 'en-US', 'rime.spore');

// Simple skills (no config needed)
$agent->addSkill('datetime');
$agent->addSkill('math');

$agent->promptAddSection('Role', 'You are a versatile assistant named Alex.');
$agent->promptAddSection('Capabilities', [
'body' => 'You can help with:',
'bullets' => ['Current date and time', 'Math calculations'],
]);

$agent->run();
```
</Tab>
<Tab title="C#">
```csharp
using SignalWire.Agent;
Expand All @@ -462,6 +442,26 @@ agent.Run();
```
</Tab>
*/}
<Tab title="PHP">
```php
use SignalWire\Agent\AgentBase;

$agent = new AgentBase(name: 'full-featured');
$agent->addLanguage('English', 'en-US', 'rime.spore');

// Simple skills (no config needed)
$agent->addSkill('datetime');
$agent->addSkill('math');

$agent->promptAddSection('Role', 'You are a versatile assistant named Alex.');
$agent->promptAddSection('Capabilities', [
'body' => 'You can help with:',
'bullets' => ['Current date and time', 'Math calculations'],
]);

$agent->run();
```
</Tab>

<Note>
Skills like `web_search` and `joke` require additional configuration or API keys. See the [Built-in Skills][built-in-skills] section for details on each skill's requirements.
Expand Down
68 changes: 34 additions & 34 deletions fern/products/sdks/pages/guides/build-ai-agents/agent-base.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Here's what a production agent looks like across all supported languages:


```python
from signalwire import AgentBase, FunctionResult
from signalwire_agents import AgentBase, SwaigFunctionResult

class CustomerSupportAgent(AgentBase):
"""Production customer support agent."""
Expand Down Expand Up @@ -119,7 +119,7 @@ class CustomerSupportAgent(AgentBase):

def check_order(self, args, raw_data):
order_number = args.get("order_number")
return FunctionResult(
return SwaigFunctionResult(
f"Order {order_number}: Shipped on Monday, arriving Thursday"
)

Expand All @@ -131,7 +131,7 @@ if __name__ == "__main__":
{/*
<Tab title="TypeScript">
```typescript
import { AgentBase, FunctionResult } from 'signalwire-agents';
import { AgentBase, SwaigFunctionResult } from 'signalwire-agents';

const agent = new AgentBase({
name: "customer-support",
Expand All @@ -143,7 +143,7 @@ agent.setParams({ end_of_speech_timeout: 500, attention_timeout: 15000, inactivi
agent.promptAddSection('Role', 'You are Alex, a friendly customer support agent for Acme Inc.');
agent.promptAddSection('Guidelines', { body: 'Follow these guidelines:', bullets: ['Be helpful and professional', 'Ask clarifying questions when needed', 'Keep responses concise for voice', 'Offer to transfer if you cannot help'] });
agent.addHints(['Acme', 'account number', 'order status', 'refund', 'billing', 'representative']);
agent.defineTool({ name: 'check_order', description: 'Look up an order by order number', parameters: { type: 'object', properties: { order_number: { type: 'string', description: 'The order number to look up' } }, required: ['order_number'] }, handler: async (args) => new FunctionResult(`Order ${args.order_number}: Shipped on Monday, arriving Thursday`) });
agent.defineTool({ name: 'check_order', description: 'Look up an order by order number', parameters: { type: 'object', properties: { order_number: { type: 'string', description: 'The order number to look up' } }, required: ['order_number'] }, handler: async (args) => new SwaigFunctionResult(`Order ${args.order_number}: Shipped on Monday, arriving Thursday`) });
agent.addSkill('datetime');
agent.setPostPrompt('Summarize: issue type, resolution, customer satisfaction');
agent.run({ host: '0.0.0.0', port: 3000 });
Expand Down Expand Up @@ -177,7 +177,7 @@ func main() {
</Tab>
<Tab title="Ruby">
```ruby
require 'signalwire'
require 'signalwire_agents'
class CustomerSupportAgent < AgentBase
def initialize
super(name: "customer-support", route: "/support")
Expand Down Expand Up @@ -253,23 +253,6 @@ int main() {
}
```
</Tab>
<Tab title="PHP">
```php
<?php
use SignalWire\Agent\AgentBase;
use SignalWire\Agent\FunctionResult;
$agent = new AgentBase(name: 'customer-support', route: '/support');
$agent->addLanguage(name: 'English', code: 'en-US', voice: 'rime.spore');
$agent->setParams(['end_of_speech_timeout' => 500, 'attention_timeout' => 15000, 'inactivity_timeout' => 30000]);
$agent->promptAddSection('Role', 'You are Alex, a friendly customer support agent for Acme Inc.');
$agent->promptAddSection('Guidelines', body: 'Follow these guidelines:', bullets: ['Be helpful and professional', 'Ask clarifying questions when needed', 'Keep responses concise for voice', 'Offer to transfer if you cannot help']);
$agent->addHints('Acme', 'account number', 'order status', 'refund', 'billing', 'representative');
$agent->defineTool('check_order', 'Look up an order by order number', ['type' => 'object', 'properties' => ['order_number' => ['type' => 'string', 'description' => 'The order number to look up']], 'required' => ['order_number']], function ($args, $raw) { return new FunctionResult("Order {$args['order_number']}: Shipped on Monday, arriving Thursday"); });
$agent->addSkill('datetime');
$agent->setPostPrompt('Summarize: issue type, resolution, customer satisfaction');
$agent->run('0.0.0.0', 3000);
```
</Tab>
<Tab title="C#">
```csharp
using SignalWire.Agent;
Expand All @@ -287,6 +270,23 @@ agent.Run();
```
</Tab>
*/}
<Tab title="PHP">
```php
<?php
use SignalWire\Agent\AgentBase;
use SignalWire\Agent\SwaigFunctionResult;
$agent = new AgentBase(name: 'customer-support', route: '/support');
$agent->addLanguage(name: 'English', code: 'en-US', voice: 'rime.spore');
$agent->setParams(['end_of_speech_timeout' => 500, 'attention_timeout' => 15000, 'inactivity_timeout' => 30000]);
$agent->promptAddSection('Role', 'You are Alex, a friendly customer support agent for Acme Inc.');
$agent->promptAddSection('Guidelines', body: 'Follow these guidelines:', bullets: ['Be helpful and professional', 'Ask clarifying questions when needed', 'Keep responses concise for voice', 'Offer to transfer if you cannot help']);
$agent->addHints('Acme', 'account number', 'order status', 'refund', 'billing', 'representative');
$agent->defineTool('check_order', 'Look up an order by order number', ['type' => 'object', 'properties' => ['order_number' => ['type' => 'string', 'description' => 'The order number to look up']], 'required' => ['order_number']], function ($args, $raw) { return new SwaigFunctionResult("Order {$args['order_number']}: Shipped on Monday, arriving Thursday"); });
$agent->addSkill('datetime');
$agent->setPostPrompt('Summarize: issue type, resolution, customer satisfaction');
$agent->run('0.0.0.0', 3000);
```
</Tab>

## Chapter Contents

Expand Down Expand Up @@ -331,12 +331,12 @@ Quick agents for simple use cases:
| Java | `AgentBase agent = AgentBase.builder().name("simple-agent").build()` |
| Perl | `my $agent = AgentBase->new(name => "simple-agent")` |
| C++ | `agent::AgentBase agent("simple-agent")` |
| PHP | `$agent = new AgentBase(name: 'simple-agent')` |
| C# | `var agent = new AgentBase(new AgentOptions { Name = "simple-agent" })` |
*/}
| PHP | `$agent = new AgentBase(name: 'simple-agent')` |

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

agent = AgentBase(name="simple-agent")
agent.add_language("English", "en-US", "rime.spore")
Expand All @@ -349,7 +349,7 @@ agent.run()
Multiple agents on one server:

```python
from signalwire import AgentServer
from signalwire_agents import AgentServer

server = AgentServer()
server.register(SupportAgent(), "/support")
Expand Down Expand Up @@ -393,14 +393,14 @@ The constructor accepts the agent name plus optional configuration:
| Java | `AgentBase.builder().name("my-agent").route("/").port(3000).build()` |
| Perl | `AgentBase->new(name => "my-agent", route => "/", port => 3000)` |
| C++ | `agent::AgentBase agent("my-agent"); agent.set_route("/"); agent.set_port(3000);` |
| PHP | `new AgentBase(name: 'my-agent', route: '/', port: 3000)` |
| C# | `new AgentBase(new AgentOptions { Name = "my-agent", Route = "/", Port = 3000 })` |
*/}
| PHP | `new AgentBase(name: 'my-agent', route: '/', port: 3000)` |

Full Python constructor with all options:

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

agent = AgentBase(
# Required
Expand Down Expand Up @@ -459,7 +459,7 @@ agent = AgentBase(
### Method 1: Class-Based (Recommended)

```python
from signalwire import AgentBase, FunctionResult
from signalwire_agents import AgentBase, SwaigFunctionResult

class MyAgent(AgentBase):
def __init__(self):
Expand All @@ -472,7 +472,7 @@ class MyAgent(AgentBase):
self.define_tool(name="greet", description="Greet the user", parameters={}, handler=self.greet)

def greet(self, args, raw_data):
return FunctionResult("Hello! How can I help you today?")
return SwaigFunctionResult("Hello! How can I help you today?")

if __name__ == "__main__":
agent = MyAgent()
Expand All @@ -482,7 +482,7 @@ if __name__ == "__main__":
### Method 2: Instance-Based

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

agent = AgentBase(name="quick-agent")
agent.add_language("English", "en-US", "rime.spore")
Expand All @@ -493,7 +493,7 @@ agent.run()
### Method 3: Declarative (PROMPT_SECTIONS)

```python
from signalwire import AgentBase
from signalwire_agents import AgentBase

class DeclarativeAgent(AgentBase):
PROMPT_SECTIONS = {
Expand Down Expand Up @@ -531,12 +531,12 @@ class DeclarativeAgent(AgentBase):
| Post-prompt | `set_post_prompt(text)` |

{/*
| Method | Ruby | Java | Perl | C++ | PHP | C# |
|--------|------|------|------|-----|-----|-----|
| Add language | `add_language(name:, code:, voice:)` | `addLanguage(name, code, voice)` | `$a->add_language(...)` | `add_language({...})` | `$a->addLanguage(name:, code:, voice:)` | `agent.AddLanguage(name, code, voice)` |
| Add prompt | `prompt_add_section(title, body, bullets:)` | `promptAddSection(title, body, List.of(...))` | `$a->prompt_add_section(...)` | `prompt_add_section(title, body, {...})` | `$a->promptAddSection(title, body, bullets:)` | `agent.PromptAddSection(title, body, bullets)` |
| Set params | `set_params(hash)` | `setParams(Map.of(...))` | `$a->set_params({...})` | `set_params({...})` | `$a->setParams([...])` | `agent.SetParams(new Dictionary<string, object>{...})` |
*/}
| Method | Ruby | Java | Perl | C++ | PHP | C# |

```python
# Voice and Language
Expand Down Expand Up @@ -622,7 +622,7 @@ AgentBase respects these environment variables:
Run multiple agents on one server:

```python
from signalwire import AgentServer
from signalwire_agents import AgentServer

class SupportAgent(AgentBase):
def __init__(self):
Expand Down Expand Up @@ -674,5 +674,5 @@ class WellOrganizedAgent(AgentBase):
self.add_skill("datetime")

def get_help(self, args, raw_data):
return FunctionResult("I can help you with...")
return SwaigFunctionResult("I can help you with...")
```
Loading
Loading