-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(inworld): Inworld Realtime Plugin Support #6573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SuomiKP31
wants to merge
4
commits into
livekit:main
Choose a base branch
from
SuomiKP31:shin/feat/inworldrealtime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
111c462
Inworld RT v1
SuomiKP31 59b96b1
Add coverage. Fix tool calling issues like xAI.
SuomiKP31 256d2dd
Python realtime plugin ready - fixed function call
SuomiKP31 14773ec
Per review comments, added dependencies for OAI plugin which was lost…
SuomiKP31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from dotenv import load_dotenv | ||
|
|
||
| from livekit.agents import ( | ||
| Agent, | ||
| AgentServer, | ||
| AgentSession, | ||
| JobContext, | ||
| cli, | ||
| function_tool, | ||
| llm, | ||
| room_io, | ||
| ) | ||
| from livekit.plugins.inworld.realtime import RealtimeModel | ||
|
|
||
| load_dotenv() | ||
|
|
||
|
|
||
| class MyAgent(Agent): | ||
| def __init__(self) -> None: | ||
| super().__init__( | ||
| instructions="You are Jessica, a helpful assistant", | ||
| llm=RealtimeModel( | ||
| model="google-ai-studio/gemini-3.1-flash-lite", | ||
| voice="Ashley", | ||
| tts_model="inworld-tts-2", | ||
| stt_model="inworld/inworld-stt-1", | ||
| modalities=["audio"], | ||
| provider_data={"auto_tool_response": False}, | ||
| ), | ||
| ) | ||
|
|
||
| async def on_enter(self): | ||
| chat_history = [ | ||
| { | ||
| "role": "user", | ||
| "content": "Hello. I'm just picking up.", | ||
| }, | ||
| ] | ||
| # Google models require a user item to generate a response, so pass it through chat_ctx. | ||
| chat_ctx = llm.ChatContext.empty() | ||
| for item in chat_history: | ||
| chat_ctx.add_message(role=item["role"], content=item["content"]) | ||
|
|
||
| self.session.generate_reply( | ||
| instructions="introduce yourself very briefly and ask about the user's day", | ||
| chat_ctx=chat_ctx, | ||
| ) | ||
|
|
||
| @function_tool | ||
| async def get_weather(self, city: str): | ||
| """Get the weather for a given city""" | ||
| return f"The weather in {city} is sunny and 70 degrees" | ||
|
|
||
|
|
||
| server = AgentServer() | ||
|
|
||
|
|
||
| @server.rtc_session() | ||
| async def entrypoint(ctx: JobContext): | ||
| session = AgentSession() | ||
|
|
||
| await session.start( | ||
| agent=MyAgent(), | ||
| room=ctx.room, | ||
| room_options=room_io.RoomOptions( | ||
| text_output=room_io.TextOutputOptions(transcription_speed_factor=1.5), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| cli.run_app(server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
livekit-plugins/livekit-plugins-inworld/livekit/plugins/inworld/realtime/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Copyright 2025 LiveKit, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from .provider_data import ( | ||
| BackchannelProviderData, | ||
| CachingProviderData, | ||
| MemoryProviderData, | ||
| ProviderData, | ||
| ReasoningConfig, | ||
| ResponsivenessProviderData, | ||
| STTProviderData, | ||
| TextGenerationConfig, | ||
| TTSProviderData, | ||
| ) | ||
| from .realtime_model import RealtimeModel, RealtimeSession | ||
|
|
||
| __all__ = [ | ||
| "RealtimeModel", | ||
| "RealtimeSession", | ||
| "ProviderData", | ||
| "STTProviderData", | ||
| "TTSProviderData", | ||
| "MemoryProviderData", | ||
| "BackchannelProviderData", | ||
| "ResponsivenessProviderData", | ||
| "CachingProviderData", | ||
| "TextGenerationConfig", | ||
| "ReasoningConfig", | ||
| ] | ||
|
|
||
| # Cleanup docs of unexported modules | ||
| _module = dir() | ||
| NOT_IN_ALL = [m for m in _module if m not in __all__] | ||
|
|
||
| __pdoc__ = {} | ||
|
|
||
| for n in NOT_IN_ALL: | ||
| __pdoc__[n] = False |
145 changes: 145 additions & 0 deletions
145
livekit-plugins/livekit-plugins-inworld/livekit/plugins/inworld/realtime/provider_data.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| # Copyright 2025 LiveKit, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Typed schema for Inworld's ``providerData`` Realtime API extensions. | ||
|
|
||
| These are ``TypedDict``s (plain dicts at runtime) so they serialize verbatim into the | ||
| ``session.update`` payload. All keys are optional; omit a key to inherit the server default. | ||
| See https://docs.inworld.ai/realtime/provider-data for the field-by-field reference. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Literal, TypedDict | ||
|
|
||
|
|
||
| class STTProviderData(TypedDict, total=False): | ||
| """``providerData.stt`` — STT tuning. Hot-swappable.""" | ||
|
|
||
| prompt: str | ||
| voice_profile: bool | ||
| language_hints: list[str] | ||
| end_of_turn_confidence_threshold: float | ||
| vad_threshold: float | ||
| min_end_of_turn_silence: int | ||
| max_turn_silence: int | ||
|
|
||
|
|
||
| class TTSProviderData(TypedDict, total=False): | ||
| """``providerData.tts`` — segmentation, language, delivery, alignment.""" | ||
|
|
||
| segmenter_strategy: Literal[ | ||
| "auto", "balanced", "sentence", "full_turn", "fast_start", "per_segment_context" | ||
| ] | ||
| steering_handling: Literal["repeat_each_chunk", "emit_once"] | ||
| language: str | ||
| delivery_mode: Literal["STABLE", "BALANCED", "CREATIVE"] | ||
| conversational: bool # locked at session open | ||
| user_turn_mode: Literal["both", "audio_only", "text_only", "none"] # locked at session open | ||
| timestamp_type: Literal["WORD", "CHARACTER"] | ||
| timestamp_transport_strategy: Literal["SYNC", "ASYNC"] | ||
|
|
||
|
|
||
| class MemoryProviderData(TypedDict, total=False): | ||
| """``providerData.memory`` — automatic conversation memory and summarization.""" | ||
|
|
||
| enabled: bool | ||
| turn_interval: int | ||
| max_memory_length: int | ||
| max_transcript_items: int | ||
| max_facts: int | ||
| trim_after_summarize: bool | ||
|
|
||
|
|
||
| class BackchannelProviderData(TypedDict, total=False): | ||
| """``providerData.backchannel`` — short interjections while the user speaks.""" | ||
|
|
||
| enabled: bool | ||
| small_model: str | ||
| eval_interval_ms: int | ||
| min_speech_ms: int | ||
| min_gap_ms: int | ||
| max_per_turn: int | ||
| hard_deadline_ms: int | ||
| history_tail_items: int | ||
| temperature: float | ||
| max_tokens: int | ||
| volume_gain: float | ||
| require_pause: bool | ||
| allowed_phrases: list[str] | ||
| prompt_template: str | ||
| decider_kind: str | ||
|
|
||
|
|
||
| class ResponsivenessProviderData(TypedDict, total=False): | ||
| """``providerData.responsiveness`` — filler audio while the LLM warms up.""" | ||
|
|
||
| enabled: bool | ||
| small_model: str | ||
| initial_wait_timeout_ms: int | ||
| hard_deadline_ms: int | ||
| history_tail_items: int | ||
| temperature: float | ||
| max_tokens: int | ||
| min_filler_gap_ms: int | ||
| max_initial_per_turn: int | ||
| max_buffer_deltas: int | ||
| enable_filler_on_first_assistant_reply: bool | ||
| prompt_template: str | ||
| pause_text: str | ||
|
|
||
|
|
||
| class CachingProviderData(TypedDict, total=False): | ||
| """``providerData.caching`` — explicit prompt caching for instructions/tools.""" | ||
|
|
||
| enabled: bool | ||
| ttl: str | ||
| cache_instructions: bool | ||
| cache_tools: bool | ||
|
|
||
|
|
||
| class ReasoningConfig(TypedDict, total=False): | ||
| effort: Literal["NONE", "MINIMAL", "LOW", "MEDIUM", "HIGH", "XHIGH"] | ||
| maxTokens: int | ||
| exclude: bool | ||
|
|
||
|
|
||
| class TextGenerationConfig(TypedDict, total=False): | ||
| """LLM generation parameters (camelCase on the wire, per Inworld).""" | ||
|
|
||
| reasoning: ReasoningConfig | ||
| maxNewTokens: int | ||
| temperature: float | ||
| topP: float | ||
| frequencyPenalty: float | ||
| presencePenalty: float | ||
| repetitionPenalty: float | ||
| stopSequences: list[str] | ||
| seed: int | ||
| logitBias: list[dict[str, Any]] | ||
|
|
||
|
|
||
| class ProviderData(TypedDict, total=False): | ||
| """Root ``providerData`` object merged into the Inworld session config.""" | ||
|
|
||
| auto_tool_response: bool | ||
| stt: STTProviderData | ||
| tts: TTSProviderData | ||
| memory: MemoryProviderData | ||
| backchannel: BackchannelProviderData | ||
| responsiveness: ResponsivenessProviderData | ||
| caching: CachingProviderData | ||
| text_generation_config: TextGenerationConfig | ||
| user_id: str | ||
| metadata: dict[str, str] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.