Skip to content

Commit 09ec01f

Browse files
authored
Merge pull request #305 from signalwire/Devon/python-sdk-update
Doc updates to sync with Python SDK
2 parents 0bff7a8 + 8d57276 commit 09ec01f

15 files changed

Lines changed: 591 additions & 4 deletions

File tree

fern/products/server-sdks/pages/reference/python/agents/agent-base/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ max-toc-depth: 3
5757
[registersipusername]: /docs/server-sdks/reference/python/agents/agent-base/register-sip-username
5858
[registerswaigfunction]: /docs/server-sdks/reference/python/agents/agent-base/register-swaig-function
5959
[removeskill]: /docs/server-sdks/reference/python/agents/agent-base/remove-skill
60+
[resetcontexts]: /docs/server-sdks/reference/python/agents/agent-base/reset-contexts
6061
[run]: /docs/server-sdks/reference/python/agents/agent-base/run
6162
[serve]: /docs/server-sdks/reference/python/agents/agent-base/serve
6263
[serverless]: /docs/server-sdks/reference/python/agents/agent-base/serverless
@@ -526,6 +527,9 @@ agent.run()
526527
<Card title="remove_skill" href="/docs/server-sdks/reference/python/agents/agent-base/remove-skill">
527528
Unload a skill from the agent.
528529
</Card>
530+
<Card title="reset_contexts" href="/docs/server-sdks/reference/python/agents/agent-base/reset-contexts">
531+
Remove all contexts from the agent, returning it to a no-contexts state.
532+
</Card>
529533
<Card title="run" href="/docs/server-sdks/reference/python/agents/agent-base/run">
530534
Smart entry point that auto-detects the runtime environment and starts the agent accordingly.
531535
</Card>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "reset_contexts"
3+
slug: /reference/python/agents/agent-base/reset-contexts
4+
description: Remove all contexts from the agent, returning it to a no-contexts state.
5+
max-toc-depth: 3
6+
---
7+
8+
[ref-agentbase]: /docs/server-sdks/reference/python/agents/agent-base
9+
[contextbuilderreset]: /docs/server-sdks/reference/python/agents/context-builder/reset
10+
[setdynamicconfig]: /docs/server-sdks/reference/python/agents/agent-base/set-dynamic-config-callback
11+
12+
Remove all contexts from the agent, returning it to a no-contexts state. This is a
13+
convenience wrapper around [`define_contexts().reset()`][contextbuilderreset].
14+
15+
Use it in a [dynamic config callback][setdynamicconfig] when you need to rebuild
16+
contexts from scratch for a specific request.
17+
18+
## **Parameters**
19+
20+
None.
21+
22+
## **Returns**
23+
24+
[`AgentBase`][ref-agentbase] -- Self for method chaining.
25+
26+
## **Example**
27+
28+
```python {5}
29+
from signalwire import AgentBase
30+
31+
def on_dynamic_config(query, body, headers, agent):
32+
if query.get("transfer"):
33+
agent.reset_contexts()
34+
ctx = agent.define_contexts().add_context("default")
35+
ctx.add_step("route").set_text("Route the caller.")
36+
37+
agent = AgentBase(name="router", route="/router")
38+
agent.set_dynamic_config_callback(on_dynamic_config)
39+
agent.serve()
40+
```

fern/products/server-sdks/pages/reference/python/agents/context-builder/context/index.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ You obtain a Context by calling `add_context()` on a ContextBuilder or by callin
9090
<Card title="set_full_reset" href="/docs/server-sdks/reference/python/agents/context-builder/context/set-full-reset">
9191
Set whether to completely replace the system prompt when entering this context.
9292
</Card>
93+
<Card title="set_initial_step" href="/docs/server-sdks/reference/python/agents/context-builder/context/set-initial-step">
94+
Set which step the context starts on when entered.
95+
</Card>
9396
<Card title="set_isolated" href="/docs/server-sdks/reference/python/agents/context-builder/context/set-isolated">
9497
Set whether to truncate conversation history when entering this context.
9598
</Card>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: "set_initial_step"
3+
slug: /reference/python/agents/context-builder/context/set-initial-step
4+
description: Set which step the context starts on when entered.
5+
max-toc-depth: 3
6+
---
7+
8+
[ref-context]: /docs/server-sdks/reference/python/agents/context-builder/context
9+
[addstep]: /docs/server-sdks/reference/python/agents/context-builder/context/add-step
10+
11+
Set which step the context starts on when entered. By default, a context starts on
12+
its first step (index `0`). When a context has a preamble step that should only run
13+
on first entry -- for example, a greeting -- later entries via `change_context` can
14+
skip it by setting `initial_step` to a different step name.
15+
16+
`initial_step` is honoured both at conversation creation (when the context is first
17+
activated) and when switching to this context via `change_context` during the
18+
conversation.
19+
20+
## **Parameters**
21+
22+
<ParamField path="step_name" type="str" required={true} toc={true}>
23+
Name of the step to start on. Must exist in this context's
24+
[step list][addstep]; validated by `ContextBuilder.validate()`.
25+
</ParamField>
26+
27+
## **Returns**
28+
29+
[`Context`][ref-context] -- Self for method chaining.
30+
31+
## **Example**
32+
33+
```python {7}
34+
from signalwire import AgentBase
35+
36+
agent = AgentBase(name="support", route="/support")
37+
contexts = agent.define_contexts()
38+
39+
ctx = contexts.add_context("support")
40+
ctx.add_step("greeting").set_text("Welcome the caller to support.")
41+
ctx.add_step("triage").set_text("Ask what they need help with.")
42+
ctx.set_initial_step("triage") # skip greeting on re-entry
43+
44+
agent.serve()
45+
```

fern/products/server-sdks/pages/reference/python/agents/context-builder/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ max-toc-depth: 3
1010
[agentbase]: /docs/server-sdks/reference/python/agents/agent-base
1111
[addcontext]: /docs/server-sdks/reference/python/agents/context-builder/add-context
1212
[getcontext]: /docs/server-sdks/reference/python/agents/context-builder/get-context
13+
[reset]: /docs/server-sdks/reference/python/agents/context-builder/reset
1314
[todict]: /docs/server-sdks/reference/python/agents/context-builder/to-dict
1415
[validate]: /docs/server-sdks/reference/python/agents/context-builder/validate
1516

@@ -45,6 +46,9 @@ automatically.
4546
<Card title="get_context" href="/docs/server-sdks/reference/python/agents/context-builder/get-context">
4647
Retrieve an existing context by name.
4748
</Card>
49+
<Card title="reset" href="/docs/server-sdks/reference/python/agents/context-builder/reset">
50+
Remove all contexts, returning the builder to its initial state.
51+
</Card>
4852
<Card title="to_dict" href="/docs/server-sdks/reference/python/agents/context-builder/to-dict">
4953
Convert all contexts to a dictionary for SWML generation.
5054
</Card>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "reset"
3+
slug: /reference/python/agents/context-builder/reset
4+
description: Remove all contexts, returning the builder to its initial state.
5+
max-toc-depth: 3
6+
---
7+
8+
[contextbuilder]: /docs/server-sdks/reference/python/agents/context-builder
9+
[resetcontexts]: /docs/server-sdks/reference/python/agents/agent-base/reset-contexts
10+
[setdynamicconfig]: /docs/server-sdks/reference/python/agents/agent-base/set-dynamic-config-callback
11+
12+
Remove all contexts from the builder, returning it to its initial empty state. Use
13+
this in a [dynamic config callback][setdynamicconfig] when you need to rebuild
14+
contexts from scratch for a specific request -- for example, skipping a greeting
15+
context on transfers.
16+
17+
For convenience at the agent level, see
18+
[`AgentBase.reset_contexts()`][resetcontexts], which wraps `define_contexts().reset()`.
19+
20+
## **Parameters**
21+
22+
None.
23+
24+
## **Returns**
25+
26+
[`ContextBuilder`][contextbuilder] -- Self for method chaining.
27+
28+
## **Example**
29+
30+
```python {6}
31+
from signalwire import AgentBase
32+
33+
def on_dynamic_config(query, body, headers, agent):
34+
if query.get("transfer"):
35+
# Wipe the default contexts and rebuild for transfer flow
36+
agent.define_contexts().reset()
37+
ctx = agent.define_contexts().add_context("default")
38+
ctx.add_step("route").set_text("Route the caller.")
39+
40+
agent = AgentBase(name="router", route="/router")
41+
agent.set_dynamic_config_callback(on_dynamic_config)
42+
agent.serve()
43+
```

fern/products/server-sdks/pages/reference/python/rest/phone-numbers/index.mdx

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Phone Numbers"
33
slug: /reference/python/rest/phone-numbers
4-
description: "Search and manage phone numbers."
4+
description: "Search and manage phone numbers, and bind inbound calls to handlers."
55
max-toc-depth: 3
66
---
77

@@ -12,10 +12,19 @@ max-toc-depth: 3
1212
[update]: /docs/server-sdks/reference/python/rest/phone-numbers/update
1313
[delete]: /docs/server-sdks/reference/python/rest/phone-numbers/delete
1414
[search]: /docs/server-sdks/reference/python/rest/phone-numbers/search
15+
[setswml]: /docs/server-sdks/reference/python/rest/phone-numbers/set-swml-webhook
16+
[setcxml]: /docs/server-sdks/reference/python/rest/phone-numbers/set-cxml-webhook
17+
[setcxmlapp]: /docs/server-sdks/reference/python/rest/phone-numbers/set-cxml-application
18+
[setai]: /docs/server-sdks/reference/python/rest/phone-numbers/set-ai-agent
19+
[setflow]: /docs/server-sdks/reference/python/rest/phone-numbers/set-call-flow
20+
[setrelayapp]: /docs/server-sdks/reference/python/rest/phone-numbers/set-relay-application
21+
[setrelaytopic]: /docs/server-sdks/reference/python/rest/phone-numbers/set-relay-topic
1522

1623
Search for available phone numbers, purchase them, and manage the numbers in your
1724
SignalWire project. This resource extends the standard CRUD pattern with a `search()`
18-
method for discovering available numbers and uses PUT for updates.
25+
method for discovering available numbers, uses PUT for updates, and provides typed
26+
helpers for binding inbound calls to a handler (SWML webhook, cXML webhook, AI agent,
27+
call flow, RELAY application/topic).
1928

2029
Access via `client.phone_numbers` on a [`RestClient`][restclient] instance.
2130

@@ -35,6 +44,8 @@ for number in available.get("data", []):
3544

3645
## **Methods**
3746

47+
### Standard CRUD
48+
3849
<CardGroup cols={3}>
3950
<Card title="list" href="/docs/server-sdks/reference/python/rest/phone-numbers/list">
4051
List phone numbers owned by the project.
@@ -55,3 +66,66 @@ for number in available.get("data", []):
5566
Search for available phone numbers to purchase.
5667
</Card>
5768
</CardGroup>
69+
70+
### Typed Binding Helpers
71+
72+
Each helper is a one-line wrapper over [`update`][update] that sets `call_handler` to
73+
the right value and populates the handler-specific companion field for you. Pass extra
74+
keyword arguments through to `update` for fields the helper doesn't name explicitly.
75+
Setting a binding auto-materializes the matching Fabric resource on the server.
76+
77+
<CardGroup cols={3}>
78+
<Card title="set_swml_webhook" href="/docs/server-sdks/reference/python/rest/phone-numbers/set-swml-webhook">
79+
Route inbound calls to an SWML webhook URL.
80+
</Card>
81+
<Card title="set_cxml_webhook" href="/docs/server-sdks/reference/python/rest/phone-numbers/set-cxml-webhook">
82+
Route inbound calls to a cXML (LAML) webhook.
83+
</Card>
84+
<Card title="set_cxml_application" href="/docs/server-sdks/reference/python/rest/phone-numbers/set-cxml-application">
85+
Route inbound calls to an existing cXML application by ID.
86+
</Card>
87+
<Card title="set_ai_agent" href="/docs/server-sdks/reference/python/rest/phone-numbers/set-ai-agent">
88+
Route inbound calls to an AI Agent Fabric resource by ID.
89+
</Card>
90+
<Card title="set_call_flow" href="/docs/server-sdks/reference/python/rest/phone-numbers/set-call-flow">
91+
Route inbound calls to a Call Flow by ID.
92+
</Card>
93+
<Card title="set_relay_application" href="/docs/server-sdks/reference/python/rest/phone-numbers/set-relay-application">
94+
Route inbound calls to a named RELAY application.
95+
</Card>
96+
<Card title="set_relay_topic" href="/docs/server-sdks/reference/python/rest/phone-numbers/set-relay-topic">
97+
Route inbound calls to a RELAY topic.
98+
</Card>
99+
</CardGroup>
100+
101+
## **PhoneCallHandler enum**
102+
103+
For callers passing `call_handler` directly to [`update`][update], the
104+
`PhoneCallHandler` enum provides typed values. Each member is a `str` subclass, so
105+
passing the enum member serializes to the wire value without `.value` indirection.
106+
107+
```python
108+
from signalwire.rest import PhoneCallHandler
109+
110+
client.phone_numbers.update(
111+
"phone-number-id",
112+
call_handler=PhoneCallHandler.AI_AGENT,
113+
call_ai_agent_id="ai-agent-id",
114+
)
115+
```
116+
117+
| Enum member | Wire value | Companion field | Auto-creates |
118+
|--------------------|----------------------|----------------------------|---------------------|
119+
| `RELAY_SCRIPT` | `relay_script` | `call_relay_script_url` | `swml_webhook` |
120+
| `LAML_WEBHOOKS` | `laml_webhooks` | `call_request_url` | `cxml_webhook` |
121+
| `LAML_APPLICATION` | `laml_application` | `call_laml_application_id` | `cxml_application` |
122+
| `AI_AGENT` | `ai_agent` | `call_ai_agent_id` | `ai_agent` |
123+
| `CALL_FLOW` | `call_flow` | `call_flow_id` | `call_flow` |
124+
| `RELAY_APPLICATION`| `relay_application` | `call_relay_application` | `relay_application` |
125+
| `RELAY_TOPIC` | `relay_topic` | `call_relay_topic` | (routes via RELAY) |
126+
127+
<Note>
128+
`LAML_WEBHOOKS` (wire value `laml_webhooks`) produces a **cXML** handler, not a
129+
generic webhook. For SWML, use `RELAY_SCRIPT` -- or, more conveniently, the
130+
[`set_swml_webhook`][setswml] helper.
131+
</Note>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: "set_ai_agent"
3+
slug: /reference/python/rest/phone-numbers/set-ai-agent
4+
description: Route inbound calls to an AI Agent Fabric resource by ID.
5+
max-toc-depth: 3
6+
---
7+
8+
[update]: /docs/server-sdks/reference/python/rest/phone-numbers/update
9+
10+
Route inbound calls on this phone number to an existing AI Agent Fabric resource by
11+
its ID.
12+
13+
This is a typed wrapper over [`update`][update] that sets `call_handler` to
14+
`ai_agent` and populates `call_ai_agent_id` for you.
15+
16+
## **Parameters**
17+
18+
<ParamField path="resource_id" type="str" required={true} toc={true}>
19+
ID of the phone number to bind.
20+
</ParamField>
21+
22+
<ParamField path="agent_id" type="str" required={true} toc={true}>
23+
ID of the AI Agent Fabric resource to route calls to.
24+
</ParamField>
25+
26+
<ParamField path="**extra" type="Any" toc={true}>
27+
Additional fields forwarded to `update`.
28+
</ParamField>
29+
30+
## **Returns**
31+
32+
`dict` -- The updated phone number resource.
33+
34+
## **Example**
35+
36+
```python {9}
37+
from signalwire.rest import RestClient
38+
39+
client = RestClient(
40+
project="your-project-id",
41+
token="your-api-token",
42+
host="your-space.signalwire.com",
43+
)
44+
45+
client.phone_numbers.set_ai_agent(
46+
"phone-number-id",
47+
"ai-agent-id",
48+
)
49+
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "set_call_flow"
3+
slug: /reference/python/rest/phone-numbers/set-call-flow
4+
description: Route inbound calls to a Call Flow by ID.
5+
max-toc-depth: 3
6+
---
7+
8+
[update]: /docs/server-sdks/reference/python/rest/phone-numbers/update
9+
10+
Route inbound calls on this phone number to an existing Call Flow by its ID.
11+
12+
This is a typed wrapper over [`update`][update] that sets `call_handler` to
13+
`call_flow` and populates `call_flow_id` for you.
14+
15+
## **Parameters**
16+
17+
<ParamField path="resource_id" type="str" required={true} toc={true}>
18+
ID of the phone number to bind.
19+
</ParamField>
20+
21+
<ParamField path="flow_id" type="str" required={true} toc={true}>
22+
ID of the Call Flow to route calls to.
23+
</ParamField>
24+
25+
<ParamField path="version" type="Optional[str]" toc={true}>
26+
Which Call Flow version to invoke. Accepts `"working_copy"` or
27+
`"current_deployed"`. Defaults to the server's current deployed version when
28+
omitted.
29+
</ParamField>
30+
31+
<ParamField path="**extra" type="Any" toc={true}>
32+
Additional fields forwarded to `update`.
33+
</ParamField>
34+
35+
## **Returns**
36+
37+
`dict` -- The updated phone number resource.
38+
39+
## **Example**
40+
41+
```python {9}
42+
from signalwire.rest import RestClient
43+
44+
client = RestClient(
45+
project="your-project-id",
46+
token="your-api-token",
47+
host="your-space.signalwire.com",
48+
)
49+
50+
client.phone_numbers.set_call_flow(
51+
"phone-number-id",
52+
"call-flow-id",
53+
version="working_copy",
54+
)
55+
```

0 commit comments

Comments
 (0)