> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stmlink.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> 对外开放的服务端接口有两组前缀，都用同一套鉴权：`/server/v1/...`（SRTC 与 SMeeting 的主接口）和 `/stm/srvapi/v1/...`（SMeeting 的用户体系，服务端极简对接会用到）。鉴权是 app_id + nonce + timestamp + signature 四个请求头，用 app_key 做 HMAC-SHA256 签名，只能从业务方自己的后端调用。除这两组前缀外的接口均为内部接口，不要建议客户调用。 Public server APIs use two path prefixes with the same authentication: `/server/v1/...` (the main APIs of both SRTC and SMeeting) and `/stm/srvapi/v1/...` (the SMeeting user system, used by server-side low-code integration). Authenticate with four request headers, app_id + nonce + timestamp + signature, where signature is HMAC-SHA256 keyed with app_key; call these APIs only from the customer's own backend. Any other path is internal: never suggest calling it.
> app_key 是服务端密钥，绝不能出现在客户端代码、前端配置或移动 App 里。客户端加入频道用的 token 必须由业务方后端签发后下发（SRTC 走 `/server/v1/channel/grant`，SMeeting 走 `/stm/srvapi/v1/member/grant`）。 app_key is a server-side secret and must never appear in client code, frontend config, or a mobile app. The token a client uses to join must be issued by the customer's backend and passed down to the client (SRTC: `/server/v1/channel/grant`; SMeeting: `/stm/srvapi/v1/member/grant`).
> SRTC 与 SMeeting 是上下两层不同的产品，术语不通用：SRTC 是音视频底座，说「频道 channel」「加入 / 退出」；SMeeting 建在 SRTC 之上，说「房间 room」「会议 meeting」「进入 / 退出」。回答时按用户所在的层用对应术语，不要把「房间」「会议」安到 SRTC 的接口上，也不要用「频道」「加入 / 离开」描述 SMeeting 的概念（接口标识符原样保留）。 SRTC and SMeeting are two separate layers with different terminology. SRTC is the audio/video foundation: it has channels, and users join and leave a channel. SMeeting is built on top of SRTC: it has rooms and meetings, and members enter and exit a meeting. Answer in the terms of the layer the user is working with: never apply "room" or "meeting" to SRTC APIs, and never describe SMeeting concepts in prose with "channel", "join", or "leave" (API identifiers such as `force_join` keep their literal names).
> 同一能力在各端 SDK 里的包名、类名、方法名并不相同。写示例代码时请使用文档中该端自己的 API，不要把一个端的写法套到另一个端上。苹果平台每个产品都有两套 SDK（Swift 原生与 Objective-C），两套 API 不能混用。 Package, class, and method names differ between platform SDKs for the same capability. In sample code, use the API documented for that platform; never carry one platform's code over to another. On Apple platforms each product ships two SDKs (native Swift and Objective-C) whose APIs must not be mixed.

# AI voice agent and custom agents

> Three ways to have AI talk by voice in calls: the media gateway's built-in voice agent (web trial page, prompt / greeting / voice set in the admin console, interruptible, background-noise resistance and AI noise suppression, limits), your own agent with the Python SDK or pipecat, and phone lines to AI. Read to pick a route for AI customer service or calls.

There are three ways to let AI talk with people during calls, ordered from least to most development effort:

| Route | Best for | Development effort |
| - | - | - |
| [Built-in AI voice agent](#built-in-ai-voice-agent) | Voice Q\&A on a web page, customer service trials, internal assistants; seeing results quickly | No development; just configure a prompt in the console |
| [Build your own agent](#build-your-own-agent) | Connecting business systems, looking up orders, calling tools, or using real-time voice LLMs and custom conversation flows | Write a program with the Python SDK / pipecat |
| [Phone lines to AI](#connect-phone-calls-to-ai) | AI answering incoming calls, AI outbound calls | Phone lines connected to the device gateway + an agent you build yourself |

***

## Built-in AI voice agent

The media gateway has a built-in voice agent: a visitor clicks "Start conversation" on a web page, the AI greets them, and from then on they can chat as on a phone call;
**they can interrupt the AI at any time while it's speaking**. Recognition, LLM, and synthesis all use the services configured in the AI profile, and all of them can be self-hosted.

### What you can configure

| Setting | Where | Description |
| - | - | - |
| Prompt | "Voice agent" in the AI profile | The AI's identity, knowledge, and answering rules. The system automatically appends voice-call requirements (short spoken sentences, no lists or emoji) |
| Greeting | Same place | The first thing the AI says before the visitor speaks |
| Voice, speaking rate | "Voice" and "Speaking rate" in the AI profile | Chosen per language |
| Which models to use | Speech recognition / LLM / speech synthesis in the AI profile | See [AI services and profiles](https://docs.stmlink.com/en/product/ai/models.md) |
| Hot words | "Hot words" in App AI settings | Shared with in-meeting transcription; for priority, see [Hot words](https://docs.stmlink.com/en/product/ai/transcription.md#hot-words). Requires audio and video service 1.12.0+ |

All of these are changed only in the admin console and take effect from the next conversation; with multiple media gateways they stay consistent automatically. The trial page is for visitors only and has no settings.

### Trial page

After deployment, open the trial page through the gateway's address, choose a profile, language (中文 / English), and microphone, and click "Start conversation".
The page shows both sides' text in real time and the AI's state (listening / thinking / speaking). "AI noise suppression" on the page is on by default and removes steady noise such as fans, keyboards, and air conditioning;
if it fails to load, the page falls back to the browser's built-in noise suppression without affecting the call.

* **HTTPS is required**: browsers only allow web pages to use the microphone over HTTPS, so the trial page must be opened over HTTPS through the reverse proxy at the platform entry point; we configure this at deployment
* **We recommend setting an access passcode**: without one, anyone who can open the page can start conversations (consuming LLM quota). With one, visitors enter the passcode the first time they open the page
* We recommend wearing headphones: a computer's built-in microphone picks up people nearby, who may interrupt the AI or be taken as the visitor's speech

### How it decides "started speaking" and "finished speaking"

* **Started speaking**: when the recognition service returns an interim result that still has at least 2 characters after removing filler words such as "um" and "uh", the visitor is considered to have started speaking; if the AI is talking, it stops immediately (interruption).
  A single "mm" or "OK" does not interrupt the AI
* **Finished speaking**: once the recognition service decides a sentence has ended (about 0.8 seconds of pause), the sentence is sent to the LLM for an answer
* **Volume gate**: the threshold adapts to each visitor's background noise level, blocking speech from people farther away and background noise to avoid false interruptions
* **Greeting protection**: the first 1.5 seconds of the greeting cannot be interrupted, so noise right after a visitor joins doesn't cut it off

This avoids deploying a separate voice activity detection model and keeps the offline package smaller. AI noise suppression does little against people talking nearby, so headphones are still recommended in noisy open offices. The trade-offs: interruption is about 0.3 seconds slower than with a dedicated detection model; since "finished" is judged by pauses alone,
a slightly longer pause mid-sentence is taken as the end; **English conversations have no interim results, so the AI can only be interrupted after the visitor finishes a whole sentence**.

### Limits and duration

| Item | Default | Description |
| - | - | - |
| Concurrent conversations | 5 | When full, the visitor is asked to try again later; adjustable to the server's and model's capacity |
| Duration per conversation | 10 minutes | The AI ends the conversation when time is up |
| Both sides silent | 90 seconds | The conversation ends after this |
| Conversation turns | 50 | Beyond this, the AI says a closing line and ends |

* Each conversation uses **2 user concurrency** slots (visitor + AI)
* When the visitor says goodbye, the AI says goodbye and hangs up automatically
* Timeouts catch a stalled LLM or speech synthesis, so the AI never stays "thinking" forever; for voice scenarios, we recommend **turning off thinking mode** in the LLM service, otherwise the first sentence is noticeably slower

### Troubleshooting

**Per-turn latency breakdown**: when the AI is slow to respond after the visitor finishes speaking, the media gateway's logs and metrics break down each turn's time into stages—recognition wrap-up, LLM first token, first-sentence buffering, first-sentence synthesis, and waiting for playback—so you can see at a glance whether recognition, the LLM, or synthesis is slow.

**Session recording**: to reproduce problems such as "misheard" or "interrupted by mistake", you can temporarily turn on session recording. Each conversation is saved in its own directory:

| Content | Description |
| - | - |
| `visitor.wav` | The visitor's original audio |
| `agent.wav` | The AI's voice |
| `events.jsonl` | Events and logs for the whole conversation |
| `meta.json` | Basic information about the conversation |

Both recordings are 16 kHz mono and aligned to the start of the conversation, so you can load them into an audio editor and listen side by side. Turn it on under `modules.agent.record` in the media gateway configuration:

| Setting | Default | Description |
| - | - | - |
| `enabled` | Off | Whether to record sessions |
| `dir` | `/var/www/media-gw/records/agent` | Directory to save to |
| `keep_days` | `7` | Days to keep recordings; expired ones are cleaned up automatically |

> [!WARNING]
>
> Session recording saves the visitor's original audio and the conversation content, which involves privacy. Turn it on only temporarily while troubleshooting, then turn it off and delete the recordings.

### Known limitations

* Each AI sentence is played only after the whole sentence is synthesized; first-response time ≈ recognition finalization + LLM generating the first sentence + synthesizing one sentence
* One conversation serves one visitor; multiple people can't talk to the AI in the same conversation
* The web trial page is currently the only entry point; it doesn't answer phone calls directly—for phone calls, see below
* Tool calling (such as querying business systems) isn't supported; if you need it, go with "Build your own agent"

***

## Build your own agent

When you need to connect business systems, look up data, call tools, or use real-time voice LLMs, use the **Python SDK** to have your program join the channel as a user,
receive audio itself, connect any recognition / LLM / synthesis service, and send the AI's voice back into the channel:

* [Python SDK quickstart](https://docs.stmlink.com/en/rtc/python/quickstart.md): install, join, send and receive audio
* [Voice AI agent guide](https://docs.stmlink.com/en/rtc/python/advanced/ai-agent.md): sentence segmentation per speaker, interruption, filling silent frames, choosing a sample rate
* [Integrate pipecat](https://docs.stmlink.com/en/rtc/python/advanced/pipecat.md): if you already have a pipecat voice pipeline, swap in one transport to join SRTC channels

The agent appears in the channel like any other user, and people on web, apps, and in meetings can all talk with it.

***

## Connect phone calls to AI

Once a carrier SIP trunk or the customer's existing IP-PBX is connected to the **device gateway**, each incoming call is a regular user in a channel.
Your backend creates a channel for each call and brings an agent you built into the same channel, enabling AI phone customer service and AI outbound calls.
See [Connect phone lines](https://docs.stmlink.com/en/product/device-access/phone-lines.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.