Skip to content

Latest commit

 

History

History

pythonAgent

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Python agent (FastAPI)

A transient VAPI voice-agent server in Python. On each inbound call it builds a personalized assistant from a (fake) CRM lookup, executes the agent's tools mid-call, and on hang-up forwards the call — with VAPI call-log enrichment — to Tuner.

This is the line-for-line counterpart of ../nodeAgent. Same webhook, same tools, same flow — pick whichever language you prefer.

Files

File Description
vapi_server.py The webhook server (transient agent + tools + Tuner forwarding)
send_to_tuner.py Tuner client + VAPI call-log enrichment (no third-party deps beyond requests)
requirements.txt fastapi, uvicorn, requests

Prerequisites

  • Python 3.10+
  • A VAPI account with a phone number or SIP trunk
  • A Tuner workspace (for end-of-call forwarding)
  • A public HTTPS URL for local dev (e.g. ngrok)

1. Install dependencies

cd pythonAgent
python -m venv .venv && source .venv/bin/activate   # optional but recommended
pip install -r requirements.txt

2. Configure Tuner

Edit the config block at the top of send_to_tuner.py:

Variable Where to find it
TUNER_BASE_URL Your Tuner API base URL (default: https://api.usetuner.ai)
TUNER_API_KEY Tuner → Workspace Settings → API Keys (tr_api_…)
TUNER_WORKSPACE Tuner → Workspace → General Settings (numeric ID)
TUNER_AGENT_ID Create a Custom API agent in Tuner, then Agent Settings → Agent Connection

The server still runs without valid Tuner credentials — it just logs a Tuner: warning and never breaks call handling.

3. Start the server

python vapi_server.py            # listens on port 8000
PORT=3000 python vapi_server.py  # or override the port

Verify:

curl http://localhost:8000/health

4. Expose it and point VAPI at it

ngrok http 8000

In the VAPI dashboard, set your Phone Number's Server URL to:

https://<your-public-url>/vapi/webhook

Then place a test call.

Available tools

Tool Purpose
lookupOrder Fake order-status lookup
bookAppointment Fake appointment booking
checkBalance Returns the CRM balance and loyalty points
transferToHuman Simulated transfer to billing / support / sales
endCall Built-in VAPI tool to hang up (executed by VAPI, not this server)

Local output files

After calls complete the server writes (in the working directory, both gitignored):

  • vapi_return.json — array of end-of-call-report payloads (with callLog attached)
  • vapi_log_return.json — per-call VAPI logs (JSONL parsed to an array)

Notes

  • The Tuner client is synchronous; the server runs fetch_vapi_log and send_call_to_tuner in a thread (asyncio.to_thread) so the event loop stays responsive.
  • Swap fake_crm_lookup for a real HTTP/DB call to make this production-shaped.