# Phone Agent

A self-hosted outbound phone-call agent. You (an LLM assistant) drive it over
HTTP: it places a real phone call via Twilio, has an AI voice agent conduct the
conversation from a brief you supply, records the transcript, and texts a
summary when the call ends.

## How to use it (3 steps)

1. **Create an API key.** `POST /v1/api-keys` with header
   `X-Invitation-Code: <your invitation code>`. The response contains your
   `api_key` — store it; it is only shown once. Send it as `X-API-Key` on all
   subsequent requests.
2. **Place a call.** `POST /v1/calls` with a JSON body like:

```json
{
  "to": "+61400000000",
  "brief": {
    "goal": "Find out the venue's opening hours this weekend",
    "context": "The venue is Example Cafe in Brisbane",
    "exit_criteria": ["Opening hours confirmed"],
    "private_notes": "Nathan only cares about Sunday",
    "constraints": [],
    "must_not": [],
    "on_behalf_of": "Nathan",
    "language": "en-AU"
  },
  "notify_sms": true,
  "max_duration_minutes": 30
}
```

   Returns `202` with a `call_id`. Optional `Idempotency-Key` header makes the
   request safe to retry — the same call is returned, not a duplicate.

   `brief.private_notes` is background for the agent's own understanding only —
   it is never spoken aloud (use `context` for shareable facts).

   IVR menus, keypad entry (send_dtmf) and hold queues are handled
   automatically. While the call is on hold, `status_detail` is `on_hold`
   (`resuming` briefly when a person comes back); long holds are fine.

3. **Poll for the result.** `GET /v1/calls/{call_id}` until `status` is
   `completed`, `no_answer`, `busy`, `failed` or `cancelled`, then read
   `outcome` and `summary`. Fetch `GET /v1/calls/{call_id}/transcript` for the
   full transcript. `POST /v1/calls/{call_id}/cancel` aborts a live call.
   `GET /v1/calls/{call_id}/recording` returns the call audio (mp3) once the
   recording is ready (see `has_recording` on the call object).
   `GET /v1/calls/{call_id}/events` returns the structured event log
   (`{at, type, data}` — phase changes, tool calls, hold probes, usage).
   The call object also carries `progress` (structured mid-call state —
   phase, confirmed facts/references, hold time, IVR path),
   `claimed_outcome` (what the agent claimed vs the verified `outcome`),
   and `cost_estimate_aud` (running AUD cost estimate).

## Safety rules

- The agent NEVER reads out payment card numbers, passwords or one-time codes.
- The agent never invents facts: it only knows what you put in the brief.
- Keep personal data in `brief.context` to the minimum the callee needs.
- Calls are hard-limited by `max_duration_minutes` (server cap applies).
