Outbound AI agent call
Goal: create a hosted AI agent and have it call someone, then read the transcript and summary.
1. Create the agent
ts
import { Kolwire } from "@kolwire/sdk";
const vi = new Kolwire();
const agent = await vi.agents.create({
name: "Appointment confirmer",
system_prompt:
"You call patients of Bright Dental to confirm tomorrow's appointment at {{time}}. " +
"If they can't make it, offer to reschedule and hand off to a human.",
first_message: "Hi {{name}}, this is Bright Dental calling about your appointment tomorrow.",
voice: "default",
language: "en",
handoff_number: "+15550009999",
tools: [{ name: "end_call", description: "Hang up politely when done", type: "end_call" }],
});python
from kolwire import Kolwire
client = Kolwire()
agent = client.agents.create(
name="Appointment confirmer",
system_prompt=(
"You call patients of Bright Dental to confirm tomorrow's appointment at {{time}}. "
"If they can't make it, offer to reschedule and hand off to a human."
),
first_message="Hi {{name}}, this is Bright Dental calling about your appointment tomorrow.",
handoff_number="+15550009999",
tools=[{"name": "end_call", "description": "Hang up politely when done", "type": "end_call"}],
)Test the prompt in text before you spend a call:
ts
const { reply } = await vi.agents.testChat(agent.id, {
messages: [{ role: "user", content: "Actually I can't come tomorrow." }],
variables: { name: "Sam", time: "3pm" },
});python
reply = client.agents.test_chat(
agent.id,
messages=[{"role": "user", "content": "Actually I can't come tomorrow."}],
variables={"name": "Sam", "time": "3pm"},
).reply2. Place the call
ts
const call = await vi.calls.create({
from: "+15550001111", // one of your numbers
to: "+15550002222",
agent_id: agent.id,
variables: { name: "Sam", time: "3pm" },
machine_detection: { enabled: true, wait_for_beep: true },
client_state: "patient_42", // echoed on every event of this call
webhook_url: "https://example.com/call-events",
});python
call = client.calls.create(
from_="+15550001111",
to="+15550002222",
agent_id=agent.id,
variables={"name": "Sam", "time": "3pm"},
machine_detection={"enabled": True, "wait_for_beep": True},
client_state="patient_42",
webhook_url="https://example.com/call-events",
)from in Python
from is a Python keyword, so pass from_=. The SDK strips one trailing underscore from every parameter name.
3. Follow along and get results
Your webhook receives call.ringing, call.answered, call.agent.turn (each utterance), call.agent.tool_call, call.ended and finally call.intelligence.ready. Or fetch the results:
ts
const transcript = await vi.calls.transcript(call.id);
for (const s of transcript.segments) console.log(`${s.speaker}: ${s.text}`);
const insights = await vi.calls.insights(call.id);
console.log(insights.summary, insights.action_items, insights.sentiment);python
transcript = client.calls.transcript(call.id)
for s in transcript.segments:
print(f"{s.speaker}: {s.text}")
insights = client.calls.insights(call.id)
print(insights.summary, insights.action_items, insights.sentiment)Variations
- Watch it live: stream the transcript.
- Thousands of calls: create a campaign with
agent_idinstead of looping overcalls.create. - Your own LLM or agent stack: create the agent with
mode: "byo_llm"(OpenAI-compatible endpoint inllm_config) or stream the audio to your own agent.