Skip to content

Commit e29e027

Browse files
committed
fix agent pipeline
1 parent 93dbcc9 commit e29e027

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
TWILIO_ACCOUNT_SID=
22
TWILIO_AUTH_TOKEN=
33
TWILIO_PHONE_NUMBER="+000000000000"
4-
LIVEKIT_SIP_URI="sip:XXXXX.sip.livekit.cloud;transport=tcp"
4+
LIVEKIT_SIP_URI="sip:XXXXX.sip.livekit.cloud;transport=tcp"
5+
TRUNK_NAME="LiveKit Trunk"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"trunk": {
3+
"name": "Inbound LiveKit Trunk",
4+
"numbers": [
5+
"+12096194281"
6+
]
7+
}
8+
}

agent_telephony/twilio/livekit-trunk-setup/twilio_trunk.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ def get_env_var(var_name):
1616
return value
1717

1818

19-
def create_livekit_trunk(client, sip_uri):
19+
def create_livekit_trunk(client, sip_uri, trunk_name):
2020
domain_name = f"livekit-trunk-{os.urandom(4).hex()}.pstn.twilio.com"
2121
trunk = client.trunking.v1.trunks.create(
22-
friendly_name="LiveKit Trunk",
22+
friendly_name=trunk_name,
2323
domain_name=domain_name,
2424
)
2525
trunk.origination_urls.create(
2626
sip_url=sip_uri,
2727
weight=1,
2828
priority=1,
2929
enabled=True,
30-
friendly_name="LiveKit SIP URI",
30+
friendly_name=f"{trunk_name} SIP URI",
3131
)
32-
logging.info("Created new LiveKit Trunk.")
32+
logging.info(f"Created new {trunk_name} trunk.")
3333
return trunk
3434

3535

36-
def create_inbound_trunk(phone_number):
37-
trunk_data = {"trunk": {"name": "Inbound LiveKit Trunk", "numbers": [phone_number]}}
36+
def create_inbound_trunk(phone_number, trunk_name):
37+
trunk_data = {"trunk": {"name": f"Inbound {trunk_name}", "numbers": [phone_number]}}
3838
with open("inbound_trunk.json", "w") as f:
3939
json.dump(trunk_data, f, indent=4)
4040

@@ -58,9 +58,9 @@ def create_inbound_trunk(phone_number):
5858
return None
5959

6060

61-
def create_dispatch_rule(trunk_sid):
61+
def create_dispatch_rule(trunk_sid, trunk_name):
6262
dispatch_rule_data = {
63-
"name": "Inbound Dispatch Rule",
63+
"name": f"Inbound {trunk_name} Dispatch Rule",
6464
"trunk_ids": [trunk_sid],
6565
"rule": {"dispatchRuleIndividual": {"roomPrefix": "call-"}},
6666
}
@@ -89,23 +89,25 @@ def main():
8989
auth_token = get_env_var("TWILIO_AUTH_TOKEN")
9090
phone_number = get_env_var("TWILIO_PHONE_NUMBER")
9191
sip_uri = get_env_var("LIVEKIT_SIP_URI")
92+
trunk_name = get_env_var("TRUNK_NAME")
9293

9394
client = Client(account_sid, auth_token)
9495

9596
existing_trunks = client.trunking.v1.trunks.list()
9697
livekit_trunk = next(
97-
(trunk for trunk in existing_trunks if trunk.friendly_name == "LiveKit Trunk"),
98+
(trunk for trunk in existing_trunks if trunk.friendly_name == trunk_name),
9899
None,
99100
)
100101

101102
if not livekit_trunk:
102-
livekit_trunk = create_livekit_trunk(client, sip_uri)
103+
livekit_trunk = create_livekit_trunk(client, sip_uri, trunk_name)
103104
else:
104-
logging.info("LiveKit Trunk already exists. Using the existing trunk.")
105+
logging.info(f"{trunk_name} already exists. Using the existing trunk.")
105106

106-
inbound_trunk_sid = create_inbound_trunk(phone_number)
107+
108+
inbound_trunk_sid = create_inbound_trunk(phone_number, trunk_name)
107109
if inbound_trunk_sid:
108-
create_dispatch_rule(inbound_trunk_sid)
110+
create_dispatch_rule(inbound_trunk_sid, trunk_name)
109111

110112

111113
if __name__ == "__main__":

agent_telephony/twilio/livekit_pipeline/src/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def on_metrics_collected(agent_metrics: metrics.AgentMetrics) -> None:
124124
cli.run_app(
125125
WorkerOptions(
126126
entrypoint_fnc=entrypoint,
127-
agent_name="AgentStream",
127+
agent_name="AgentTwilio",
128128
prewarm_fnc=prewarm,
129129
)
130130
)

agent_telephony/twilio/readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ Build an AI agent that do an outbound call with Twilio and can interact with in
77

88
- Docker (for running Restack)
99
- Python 3.10 or higher
10-
- Vapi account (for outbound calls)
10+
- Twilio account (for outbound calls)
11+
- Livekit account (for WebRTC pipeline)
12+
- Deepgram account (for transcription)
13+
- ElevenLabs account (for TTS)
1114

1215
### Trunk setup for outbound calls with Twilio
1316

agent_voice/livekit/livekit_pipeline/src/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def on_metrics_collected(agent_metrics: metrics.AgentMetrics) -> None:
124124
cli.run_app(
125125
WorkerOptions(
126126
entrypoint_fnc=entrypoint,
127-
agent_name="AgentStream",
127+
agent_name="AgentVoice",
128128
prewarm_fnc=prewarm,
129129
)
130130
)

0 commit comments

Comments
 (0)