livekit-plugins-boson-ai 1.8.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- livekit_plugins_boson_ai-1.8.13/.gitignore +180 -0
- livekit_plugins_boson_ai-1.8.13/PKG-INFO +198 -0
- livekit_plugins_boson_ai-1.8.13/README.md +176 -0
- livekit_plugins_boson_ai-1.8.13/livekit/plugins/boson_ai/__init__.py +19 -0
- livekit_plugins_boson_ai-1.8.13/livekit/plugins/boson_ai/log.py +3 -0
- livekit_plugins_boson_ai-1.8.13/livekit/plugins/boson_ai/py.typed +0 -0
- livekit_plugins_boson_ai-1.8.13/livekit/plugins/boson_ai/realtime/__init__.py +3 -0
- livekit_plugins_boson_ai-1.8.13/livekit/plugins/boson_ai/realtime/realtime_model.py +1568 -0
- livekit_plugins_boson_ai-1.8.13/livekit/plugins/boson_ai/realtime/utils.py +292 -0
- livekit_plugins_boson_ai-1.8.13/livekit/plugins/boson_ai/version.py +15 -0
- livekit_plugins_boson_ai-1.8.13/pyproject.toml +44 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
**/.vscode
|
|
2
|
+
**/.DS_Store
|
|
3
|
+
.env
|
|
4
|
+
|
|
5
|
+
# Byte-compiled / optimized / DLL files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
|
|
10
|
+
# C extensions
|
|
11
|
+
*.so
|
|
12
|
+
|
|
13
|
+
# Distribution / packaging
|
|
14
|
+
.Python
|
|
15
|
+
build/
|
|
16
|
+
develop-eggs/
|
|
17
|
+
dist/
|
|
18
|
+
downloads/
|
|
19
|
+
eggs/
|
|
20
|
+
.eggs/
|
|
21
|
+
lib/
|
|
22
|
+
lib64/
|
|
23
|
+
parts/
|
|
24
|
+
sdist/
|
|
25
|
+
var/
|
|
26
|
+
wheels/
|
|
27
|
+
share/python-wheels/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
MANIFEST
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
# Usually these files are written by a python script from a template
|
|
35
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*.cover
|
|
53
|
+
*.py,cover
|
|
54
|
+
.hypothesis/
|
|
55
|
+
.pytest_cache/
|
|
56
|
+
cover/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
db.sqlite3-journal
|
|
67
|
+
|
|
68
|
+
# Flask stuff:
|
|
69
|
+
instance/
|
|
70
|
+
.webassets-cache
|
|
71
|
+
|
|
72
|
+
# Scrapy stuff:
|
|
73
|
+
.scrapy
|
|
74
|
+
|
|
75
|
+
# Sphinx documentation
|
|
76
|
+
docs/_build/
|
|
77
|
+
|
|
78
|
+
# PyBuilder
|
|
79
|
+
.pybuilder/
|
|
80
|
+
target/
|
|
81
|
+
|
|
82
|
+
# Jupyter Notebook
|
|
83
|
+
.ipynb_checkpoints
|
|
84
|
+
|
|
85
|
+
# IPython
|
|
86
|
+
profile_default/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
|
|
89
|
+
# pyenv
|
|
90
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
91
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
92
|
+
# .python-version
|
|
93
|
+
|
|
94
|
+
# pipenv
|
|
95
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
96
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
97
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
98
|
+
# install all needed dependencies.
|
|
99
|
+
#Pipfile.lock
|
|
100
|
+
|
|
101
|
+
# poetry
|
|
102
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
103
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
104
|
+
# commonly ignored for libraries.
|
|
105
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
106
|
+
#poetry.lock
|
|
107
|
+
|
|
108
|
+
# pdm
|
|
109
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
110
|
+
#pdm.lock
|
|
111
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
112
|
+
# in version control.
|
|
113
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
114
|
+
.pdm.toml
|
|
115
|
+
|
|
116
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
117
|
+
__pypackages__/
|
|
118
|
+
|
|
119
|
+
# Celery stuff
|
|
120
|
+
celerybeat-schedule
|
|
121
|
+
celerybeat.pid
|
|
122
|
+
|
|
123
|
+
# SageMath parsed files
|
|
124
|
+
*.sage.py
|
|
125
|
+
|
|
126
|
+
# Environments
|
|
127
|
+
.env
|
|
128
|
+
.venv
|
|
129
|
+
env/
|
|
130
|
+
venv/
|
|
131
|
+
ENV/
|
|
132
|
+
env.bak/
|
|
133
|
+
venv.bak/
|
|
134
|
+
|
|
135
|
+
# Spyder project settings
|
|
136
|
+
.spyderproject
|
|
137
|
+
.spyproject
|
|
138
|
+
|
|
139
|
+
# Rope project settings
|
|
140
|
+
.ropeproject
|
|
141
|
+
|
|
142
|
+
# mkdocs documentation
|
|
143
|
+
/site
|
|
144
|
+
|
|
145
|
+
# mypy
|
|
146
|
+
.mypy_cache/
|
|
147
|
+
.dmypy.json
|
|
148
|
+
dmypy.json
|
|
149
|
+
|
|
150
|
+
# trunk
|
|
151
|
+
.trunk/
|
|
152
|
+
|
|
153
|
+
# Pyre type checker
|
|
154
|
+
.pyre/
|
|
155
|
+
|
|
156
|
+
# pytype static type analyzer
|
|
157
|
+
.pytype/
|
|
158
|
+
|
|
159
|
+
# Cython debug symbols
|
|
160
|
+
cython_debug/
|
|
161
|
+
|
|
162
|
+
# PyCharm
|
|
163
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
164
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
165
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
166
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
167
|
+
.idea/
|
|
168
|
+
|
|
169
|
+
node_modules
|
|
170
|
+
|
|
171
|
+
credentials.json
|
|
172
|
+
pyrightconfig.json
|
|
173
|
+
docs/
|
|
174
|
+
|
|
175
|
+
# Database files
|
|
176
|
+
*.db
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
# Examples for development
|
|
180
|
+
examples/dev/*
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: livekit-plugins-boson-ai
|
|
3
|
+
Version: 1.8.13
|
|
4
|
+
Summary: Agent Framework plugin for Boson realtime models
|
|
5
|
+
Project-URL: Documentation, https://docs.livekit.io
|
|
6
|
+
Project-URL: Website, https://livekit.io/
|
|
7
|
+
Project-URL: Source, https://github.com/livekit/agents
|
|
8
|
+
Author-email: LiveKit <hello@livekit.io>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
Keywords: ai,audio,boson,livekit,realtime,video,voice
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
17
|
+
Classifier: Topic :: Multimedia :: Video
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.10.0
|
|
20
|
+
Requires-Dist: livekit-agents[openai]>=1.8.13
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# Boson plugin for LiveKit Agents
|
|
24
|
+
|
|
25
|
+
This plugin lets LiveKit Agents use the Boson realtime WebSocket API as a
|
|
26
|
+
LiveKit `RealtimeModel`.
|
|
27
|
+
|
|
28
|
+
LiveKit owns the room connection, participant audio, interruption plumbing,
|
|
29
|
+
transcript IO, and worker lifecycle. This plugin adapts LiveKit Agents realtime
|
|
30
|
+
model calls to Boson's OpenAI-compatible realtime protocol subset.
|
|
31
|
+
|
|
32
|
+
See [https://docs.livekit.io/agents/models/realtime/boson/](https://docs.livekit.io/agents/models/realtime/boson/) for more information.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install livekit-plugins-boson-ai
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Set `BOSON_API_KEY` in your environment. Get a key at
|
|
43
|
+
[boson.ai/workspace/api-key](https://www.boson.ai/workspace/api-key).
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from livekit.agents import AgentSession
|
|
47
|
+
from livekit.plugins import boson_ai
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
session = AgentSession(llm=boson_ai.realtime.RealtimeModel())
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The defaults connect to the hosted API (`wss://api.boson.ai/v1/realtime`) with
|
|
54
|
+
the `higgs-realtime` model and the `default` voice. To point at another
|
|
55
|
+
deployment, pass `url=` — and `api_key=None` if it does not authenticate.
|
|
56
|
+
|
|
57
|
+
## Model options
|
|
58
|
+
|
|
59
|
+
`boson_ai.realtime.RealtimeModel` accepts these options:
|
|
60
|
+
|
|
61
|
+
| Option | Description |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `url` | Realtime WebSocket endpoint. Defaults to `wss://api.boson.ai/v1/realtime`. `http`/`https` URLs are normalized to `ws`/`wss`; the path is passed through unchanged. |
|
|
64
|
+
| `api_key` | Sent as an `Authorization: Bearer ...` header. Omit it to read `BOSON_API_KEY` from the environment; omitting both raises `ValueError`. Pass `None` explicitly to send no header, for a local dev server without auth. |
|
|
65
|
+
| `model` | Sent as `session.model`. Defaults to `"higgs-realtime"`. |
|
|
66
|
+
| `voice` | Sent as `session.audio.output.voice`. |
|
|
67
|
+
| `output_modalities` | `["audio"]` by default. `["text"]` is also supported for text-only responses. |
|
|
68
|
+
| `temperature` | Optional. Sent as `session.temperature` when set; otherwise the server default is used. |
|
|
69
|
+
| `max_output_tokens` | Sent as `session.max_output_tokens`. |
|
|
70
|
+
| `tool_choice` | Sent as `session.tool_choice`. |
|
|
71
|
+
| `speed` | Playback rate for synthesized audio; `1.0` is unmodified. Sent as `session.audio.output.speed`. |
|
|
72
|
+
| `turn_detection` | Sent as `session.audio.input.turn_detection`. |
|
|
73
|
+
| `input_audio_transcription` | Sent as `session.audio.input.transcription`. |
|
|
74
|
+
| `input_audio_noise_reduction` | Sent as `session.audio.input.noise_reduction`. |
|
|
75
|
+
| `truncation` | `"auto"` (default) or `"disabled"`. Sent as `session.truncation`. `"auto"` enables background context summarization where the model supports it. Do not pass `None` — it is rejected and ends the session. |
|
|
76
|
+
| `query_params` | Extra query parameters added to the WebSocket URL. |
|
|
77
|
+
| `max_session_duration` | Seconds before the connection is recycled: the session reconnects and replays the conversation as text, after any reply in progress finishes. A user turn replays only if it has a transcript. Defaults to 1200 (20 minutes), as in the OpenAI plugin, when user transcription is on (`input_audio_transcription_model` set), and to `None` when it is off, since every recycle would then drop all of the user's turns. The default is chosen at construction; changing transcription later does not revisit it. `None` keeps one connection until the server's own limit, which is recycled the same way. Must be positive. |
|
|
78
|
+
|
|
79
|
+
If `turn_detection` is omitted, the plugin sends a default server VAD config:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
{
|
|
83
|
+
"type": "server_vad",
|
|
84
|
+
"create_response": True,
|
|
85
|
+
"interrupt_response": True,
|
|
86
|
+
"prefix_padding_ms": 300,
|
|
87
|
+
"silence_duration_ms": 500,
|
|
88
|
+
"threshold": 0.55,
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`create_response` and `interrupt_response` are accepted for OpenAI wire
|
|
93
|
+
compatibility but are not configurable here: with server VAD enabled, a
|
|
94
|
+
response is always created after user speech and the active response is always
|
|
95
|
+
cancelled when new speech is detected. The plugin's own duplicate
|
|
96
|
+
`response.cancel` suppression follows that behavior (keyed on whether server
|
|
97
|
+
VAD is enabled at all), not on what these fields are set to.
|
|
98
|
+
|
|
99
|
+
The dict is sent to the server as given, so `{"type": "semantic_vad", ...}` works
|
|
100
|
+
too; the plugin does not filter or rewrite its keys.
|
|
101
|
+
|
|
102
|
+
Passing `turn_detection=None`/`False` disables server-side turn detection and
|
|
103
|
+
switches to client-driven `input_audio_buffer.commit`. This is exposed for
|
|
104
|
+
interface completeness but isn't a heavily-exercised path yet — treat it as
|
|
105
|
+
experimental rather than a recommended default.
|
|
106
|
+
|
|
107
|
+
`input_audio_transcription` can be passed as a full dict, or built with:
|
|
108
|
+
|
|
109
|
+
- `input_audio_transcription_model` (e.g. `"higgs-stt-3.1"`)
|
|
110
|
+
- `input_audio_transcription_language`
|
|
111
|
+
|
|
112
|
+
User transcription is enabled only when the transcription config contains a
|
|
113
|
+
non-empty `model`. A transcription `prompt` is not supported; the plugin drops
|
|
114
|
+
it even if present in a raw `input_audio_transcription` dict.
|
|
115
|
+
|
|
116
|
+
### `generate_reply()` overrides
|
|
117
|
+
|
|
118
|
+
`generate_reply(instructions=...)` works as it does with the OpenAI plugin. The
|
|
119
|
+
instructions go in `response.create`, which the server uses in place of the
|
|
120
|
+
session instructions for that reply, so the event carries the session
|
|
121
|
+
instructions followed by the per-response ones.
|
|
122
|
+
|
|
123
|
+
`tools` and `tool_choice` are **not** applied per response — the server accepts
|
|
124
|
+
and ignores them. `generate_reply()` therefore ignores them too (with a warning)
|
|
125
|
+
rather than sending values that would appear to take effect. The framework
|
|
126
|
+
scopes them at the session level around the call instead, since the plugin
|
|
127
|
+
reports `per_response_tool_choice = False`; to scope them from your own code,
|
|
128
|
+
use `update_tools()` and `update_options(tool_choice=...)` directly.
|
|
129
|
+
|
|
130
|
+
## Protocol compatibility
|
|
131
|
+
|
|
132
|
+
The plugin translates LiveKit realtime model operations to the following client
|
|
133
|
+
events:
|
|
134
|
+
|
|
135
|
+
- `session.update`
|
|
136
|
+
- `input_audio_buffer.append`
|
|
137
|
+
- `input_audio_buffer.commit`
|
|
138
|
+
- `input_audio_buffer.clear`
|
|
139
|
+
- `conversation.item.create`
|
|
140
|
+
- `conversation.item.delete`
|
|
141
|
+
- `conversation.item.truncate`
|
|
142
|
+
- `response.create`
|
|
143
|
+
- `response.cancel`
|
|
144
|
+
|
|
145
|
+
The plugin handles Boson response audio, response text, audio transcript, input
|
|
146
|
+
transcription, function call, interruption, and error events and maps them back
|
|
147
|
+
to LiveKit realtime model streams.
|
|
148
|
+
|
|
149
|
+
Function tools registered on the LiveKit `Agent` are sent in `session.update`.
|
|
150
|
+
When Boson returns a `function_call` item, LiveKit Agents executes the Python
|
|
151
|
+
tool locally and the plugin sends the result back as a
|
|
152
|
+
`function_call_output` conversation item.
|
|
153
|
+
|
|
154
|
+
Only function tools have a shape on the wire. A tool of any other kind is left
|
|
155
|
+
out of `session.update` — the model never sees it — and the plugin logs a
|
|
156
|
+
warning once per session saying how many were dropped.
|
|
157
|
+
|
|
158
|
+
The plugin does not retry a WebSocket close that a reconnect cannot fix: an
|
|
159
|
+
invalid API key (close code 3000) or a billing entitlement refusal (close code
|
|
160
|
+
4429, e.g. `insufficient_quota`/`monthly_cap_reached`) both end the session
|
|
161
|
+
instead of retrying. Server errors that reflect an expected client/server race
|
|
162
|
+
rather than a real failure (`response_not_active`, `response_id_mismatch`,
|
|
163
|
+
`voice_output_task_ongoing`, `invalid_previous_item_id`) are logged but not
|
|
164
|
+
surfaced as recoverable `error` events.
|
|
165
|
+
|
|
166
|
+
The server has no insert-at-head primitive for conversation items
|
|
167
|
+
(`previous_item_id: null` always means append-at-tail). If `update_chat_ctx()`
|
|
168
|
+
needs to insert a new item ahead of turns the server already has (e.g.
|
|
169
|
+
prepending a context summary), the plugin deletes and recreates the entire
|
|
170
|
+
remote conversation in the target order instead of silently misordering it by
|
|
171
|
+
appending the new item at the tail.
|
|
172
|
+
|
|
173
|
+
That rebuild can only put back what it can express as text. A user turn whose
|
|
174
|
+
transcript has not arrived yet has none, and no audio is kept client-side, so it
|
|
175
|
+
is deleted along with the rest and not recreated — the server answers without it
|
|
176
|
+
until a later `update_chat_ctx()` recreates it (at the tail) once its transcript
|
|
177
|
+
exists. The plugin logs a warning naming the affected item ids whenever this
|
|
178
|
+
happens.
|
|
179
|
+
|
|
180
|
+
The same limit applies without a rebuild. A change to a turn's text goes out as
|
|
181
|
+
a delete plus a create under one id, so clearing that text leaves a create with
|
|
182
|
+
nothing to send: the turn is deleted rather than emptied. The delete is kept —
|
|
183
|
+
the caller asked for that text to leave the context — and the same warning names
|
|
184
|
+
the item, which returns on a later sync once it has text again.
|
|
185
|
+
|
|
186
|
+
## Limitations
|
|
187
|
+
|
|
188
|
+
- The plugin expects the current realtime event names, such as
|
|
189
|
+
`response.output_audio.delta` and `response.output_text.delta`.
|
|
190
|
+
- Video input is not supported yet.
|
|
191
|
+
- Mixed `["text", "audio"]` output modalities are not supported; choose either
|
|
192
|
+
`["audio"]` or `["text"]`.
|
|
193
|
+
- This plugin sends and receives 24 kHz PCM audio. That's the format this
|
|
194
|
+
integration uses, not the full range the Higgs Realtime API supports.
|
|
195
|
+
- `system`/`developer`-role chat items are not supported (the server's
|
|
196
|
+
conversation store only accepts `assistant`/`user` items); they're silently
|
|
197
|
+
dropped when syncing `update_chat_ctx()`. Use the `Agent`'s `instructions` for
|
|
198
|
+
persistent directives instead.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Boson plugin for LiveKit Agents
|
|
2
|
+
|
|
3
|
+
This plugin lets LiveKit Agents use the Boson realtime WebSocket API as a
|
|
4
|
+
LiveKit `RealtimeModel`.
|
|
5
|
+
|
|
6
|
+
LiveKit owns the room connection, participant audio, interruption plumbing,
|
|
7
|
+
transcript IO, and worker lifecycle. This plugin adapts LiveKit Agents realtime
|
|
8
|
+
model calls to Boson's OpenAI-compatible realtime protocol subset.
|
|
9
|
+
|
|
10
|
+
See [https://docs.livekit.io/agents/models/realtime/boson/](https://docs.livekit.io/agents/models/realtime/boson/) for more information.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install livekit-plugins-boson-ai
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Set `BOSON_API_KEY` in your environment. Get a key at
|
|
21
|
+
[boson.ai/workspace/api-key](https://www.boson.ai/workspace/api-key).
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from livekit.agents import AgentSession
|
|
25
|
+
from livekit.plugins import boson_ai
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
session = AgentSession(llm=boson_ai.realtime.RealtimeModel())
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The defaults connect to the hosted API (`wss://api.boson.ai/v1/realtime`) with
|
|
32
|
+
the `higgs-realtime` model and the `default` voice. To point at another
|
|
33
|
+
deployment, pass `url=` — and `api_key=None` if it does not authenticate.
|
|
34
|
+
|
|
35
|
+
## Model options
|
|
36
|
+
|
|
37
|
+
`boson_ai.realtime.RealtimeModel` accepts these options:
|
|
38
|
+
|
|
39
|
+
| Option | Description |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `url` | Realtime WebSocket endpoint. Defaults to `wss://api.boson.ai/v1/realtime`. `http`/`https` URLs are normalized to `ws`/`wss`; the path is passed through unchanged. |
|
|
42
|
+
| `api_key` | Sent as an `Authorization: Bearer ...` header. Omit it to read `BOSON_API_KEY` from the environment; omitting both raises `ValueError`. Pass `None` explicitly to send no header, for a local dev server without auth. |
|
|
43
|
+
| `model` | Sent as `session.model`. Defaults to `"higgs-realtime"`. |
|
|
44
|
+
| `voice` | Sent as `session.audio.output.voice`. |
|
|
45
|
+
| `output_modalities` | `["audio"]` by default. `["text"]` is also supported for text-only responses. |
|
|
46
|
+
| `temperature` | Optional. Sent as `session.temperature` when set; otherwise the server default is used. |
|
|
47
|
+
| `max_output_tokens` | Sent as `session.max_output_tokens`. |
|
|
48
|
+
| `tool_choice` | Sent as `session.tool_choice`. |
|
|
49
|
+
| `speed` | Playback rate for synthesized audio; `1.0` is unmodified. Sent as `session.audio.output.speed`. |
|
|
50
|
+
| `turn_detection` | Sent as `session.audio.input.turn_detection`. |
|
|
51
|
+
| `input_audio_transcription` | Sent as `session.audio.input.transcription`. |
|
|
52
|
+
| `input_audio_noise_reduction` | Sent as `session.audio.input.noise_reduction`. |
|
|
53
|
+
| `truncation` | `"auto"` (default) or `"disabled"`. Sent as `session.truncation`. `"auto"` enables background context summarization where the model supports it. Do not pass `None` — it is rejected and ends the session. |
|
|
54
|
+
| `query_params` | Extra query parameters added to the WebSocket URL. |
|
|
55
|
+
| `max_session_duration` | Seconds before the connection is recycled: the session reconnects and replays the conversation as text, after any reply in progress finishes. A user turn replays only if it has a transcript. Defaults to 1200 (20 minutes), as in the OpenAI plugin, when user transcription is on (`input_audio_transcription_model` set), and to `None` when it is off, since every recycle would then drop all of the user's turns. The default is chosen at construction; changing transcription later does not revisit it. `None` keeps one connection until the server's own limit, which is recycled the same way. Must be positive. |
|
|
56
|
+
|
|
57
|
+
If `turn_detection` is omitted, the plugin sends a default server VAD config:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
{
|
|
61
|
+
"type": "server_vad",
|
|
62
|
+
"create_response": True,
|
|
63
|
+
"interrupt_response": True,
|
|
64
|
+
"prefix_padding_ms": 300,
|
|
65
|
+
"silence_duration_ms": 500,
|
|
66
|
+
"threshold": 0.55,
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`create_response` and `interrupt_response` are accepted for OpenAI wire
|
|
71
|
+
compatibility but are not configurable here: with server VAD enabled, a
|
|
72
|
+
response is always created after user speech and the active response is always
|
|
73
|
+
cancelled when new speech is detected. The plugin's own duplicate
|
|
74
|
+
`response.cancel` suppression follows that behavior (keyed on whether server
|
|
75
|
+
VAD is enabled at all), not on what these fields are set to.
|
|
76
|
+
|
|
77
|
+
The dict is sent to the server as given, so `{"type": "semantic_vad", ...}` works
|
|
78
|
+
too; the plugin does not filter or rewrite its keys.
|
|
79
|
+
|
|
80
|
+
Passing `turn_detection=None`/`False` disables server-side turn detection and
|
|
81
|
+
switches to client-driven `input_audio_buffer.commit`. This is exposed for
|
|
82
|
+
interface completeness but isn't a heavily-exercised path yet — treat it as
|
|
83
|
+
experimental rather than a recommended default.
|
|
84
|
+
|
|
85
|
+
`input_audio_transcription` can be passed as a full dict, or built with:
|
|
86
|
+
|
|
87
|
+
- `input_audio_transcription_model` (e.g. `"higgs-stt-3.1"`)
|
|
88
|
+
- `input_audio_transcription_language`
|
|
89
|
+
|
|
90
|
+
User transcription is enabled only when the transcription config contains a
|
|
91
|
+
non-empty `model`. A transcription `prompt` is not supported; the plugin drops
|
|
92
|
+
it even if present in a raw `input_audio_transcription` dict.
|
|
93
|
+
|
|
94
|
+
### `generate_reply()` overrides
|
|
95
|
+
|
|
96
|
+
`generate_reply(instructions=...)` works as it does with the OpenAI plugin. The
|
|
97
|
+
instructions go in `response.create`, which the server uses in place of the
|
|
98
|
+
session instructions for that reply, so the event carries the session
|
|
99
|
+
instructions followed by the per-response ones.
|
|
100
|
+
|
|
101
|
+
`tools` and `tool_choice` are **not** applied per response — the server accepts
|
|
102
|
+
and ignores them. `generate_reply()` therefore ignores them too (with a warning)
|
|
103
|
+
rather than sending values that would appear to take effect. The framework
|
|
104
|
+
scopes them at the session level around the call instead, since the plugin
|
|
105
|
+
reports `per_response_tool_choice = False`; to scope them from your own code,
|
|
106
|
+
use `update_tools()` and `update_options(tool_choice=...)` directly.
|
|
107
|
+
|
|
108
|
+
## Protocol compatibility
|
|
109
|
+
|
|
110
|
+
The plugin translates LiveKit realtime model operations to the following client
|
|
111
|
+
events:
|
|
112
|
+
|
|
113
|
+
- `session.update`
|
|
114
|
+
- `input_audio_buffer.append`
|
|
115
|
+
- `input_audio_buffer.commit`
|
|
116
|
+
- `input_audio_buffer.clear`
|
|
117
|
+
- `conversation.item.create`
|
|
118
|
+
- `conversation.item.delete`
|
|
119
|
+
- `conversation.item.truncate`
|
|
120
|
+
- `response.create`
|
|
121
|
+
- `response.cancel`
|
|
122
|
+
|
|
123
|
+
The plugin handles Boson response audio, response text, audio transcript, input
|
|
124
|
+
transcription, function call, interruption, and error events and maps them back
|
|
125
|
+
to LiveKit realtime model streams.
|
|
126
|
+
|
|
127
|
+
Function tools registered on the LiveKit `Agent` are sent in `session.update`.
|
|
128
|
+
When Boson returns a `function_call` item, LiveKit Agents executes the Python
|
|
129
|
+
tool locally and the plugin sends the result back as a
|
|
130
|
+
`function_call_output` conversation item.
|
|
131
|
+
|
|
132
|
+
Only function tools have a shape on the wire. A tool of any other kind is left
|
|
133
|
+
out of `session.update` — the model never sees it — and the plugin logs a
|
|
134
|
+
warning once per session saying how many were dropped.
|
|
135
|
+
|
|
136
|
+
The plugin does not retry a WebSocket close that a reconnect cannot fix: an
|
|
137
|
+
invalid API key (close code 3000) or a billing entitlement refusal (close code
|
|
138
|
+
4429, e.g. `insufficient_quota`/`monthly_cap_reached`) both end the session
|
|
139
|
+
instead of retrying. Server errors that reflect an expected client/server race
|
|
140
|
+
rather than a real failure (`response_not_active`, `response_id_mismatch`,
|
|
141
|
+
`voice_output_task_ongoing`, `invalid_previous_item_id`) are logged but not
|
|
142
|
+
surfaced as recoverable `error` events.
|
|
143
|
+
|
|
144
|
+
The server has no insert-at-head primitive for conversation items
|
|
145
|
+
(`previous_item_id: null` always means append-at-tail). If `update_chat_ctx()`
|
|
146
|
+
needs to insert a new item ahead of turns the server already has (e.g.
|
|
147
|
+
prepending a context summary), the plugin deletes and recreates the entire
|
|
148
|
+
remote conversation in the target order instead of silently misordering it by
|
|
149
|
+
appending the new item at the tail.
|
|
150
|
+
|
|
151
|
+
That rebuild can only put back what it can express as text. A user turn whose
|
|
152
|
+
transcript has not arrived yet has none, and no audio is kept client-side, so it
|
|
153
|
+
is deleted along with the rest and not recreated — the server answers without it
|
|
154
|
+
until a later `update_chat_ctx()` recreates it (at the tail) once its transcript
|
|
155
|
+
exists. The plugin logs a warning naming the affected item ids whenever this
|
|
156
|
+
happens.
|
|
157
|
+
|
|
158
|
+
The same limit applies without a rebuild. A change to a turn's text goes out as
|
|
159
|
+
a delete plus a create under one id, so clearing that text leaves a create with
|
|
160
|
+
nothing to send: the turn is deleted rather than emptied. The delete is kept —
|
|
161
|
+
the caller asked for that text to leave the context — and the same warning names
|
|
162
|
+
the item, which returns on a later sync once it has text again.
|
|
163
|
+
|
|
164
|
+
## Limitations
|
|
165
|
+
|
|
166
|
+
- The plugin expects the current realtime event names, such as
|
|
167
|
+
`response.output_audio.delta` and `response.output_text.delta`.
|
|
168
|
+
- Video input is not supported yet.
|
|
169
|
+
- Mixed `["text", "audio"]` output modalities are not supported; choose either
|
|
170
|
+
`["audio"]` or `["text"]`.
|
|
171
|
+
- This plugin sends and receives 24 kHz PCM audio. That's the format this
|
|
172
|
+
integration uses, not the full range the Higgs Realtime API supports.
|
|
173
|
+
- `system`/`developer`-role chat items are not supported (the server's
|
|
174
|
+
conversation store only accepts `assistant`/`user` items); they're silently
|
|
175
|
+
dropped when syncing `update_chat_ctx()`. Use the `Agent`'s `instructions` for
|
|
176
|
+
persistent directives instead.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Boson plugin for LiveKit Agents."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from livekit.agents import Plugin
|
|
6
|
+
|
|
7
|
+
from . import realtime
|
|
8
|
+
from .log import logger
|
|
9
|
+
from .version import __version__
|
|
10
|
+
|
|
11
|
+
__all__ = ["realtime", "__version__"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BosonPlugin(Plugin):
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
super().__init__(__name__, __version__, __package__, logger)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
Plugin.register_plugin(BosonPlugin())
|
|
File without changes
|