Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
bd7863d
feat(session): add the livekit-session crate manifest and module layout
MaxHeimbrock Nov 3, 2026
39460bf
chore(workspace): register livekit-session with cargo, knope and CODE…
MaxHeimbrock Nov 3, 2026
e76258c
IMPORTANT(session): add the agent interop constants
MaxHeimbrock Nov 3, 2026
7bd04d9
feat(session): add the start and send error types
MaxHeimbrock Nov 3, 2026
01eac79
feat(session): add the Message model and the MessageStore feed
MaxHeimbrock Nov 3, 2026
1e79ba6
test(session): cover MessageStore ordering, upsert and restore
MaxHeimbrock Nov 3, 2026
94e8c2d
IMPORTANT(session): aggregate lk.transcription streams into transcrip…
MaxHeimbrock Nov 3, 2026
96d387d
test(session): cover transcript aggregation
MaxHeimbrock Nov 3, 2026
5637b84
feat(session): add AgentState and AgentFailure
MaxHeimbrock Nov 3, 2026
662c238
feat(session): find the agent, its avatar worker and their tracks
MaxHeimbrock Nov 3, 2026
94c3a3b
IMPORTANT(session): project AgentState with timeout and leave detection
MaxHeimbrock Nov 3, 2026
925a049
test(session): cover agent discovery and state parsing
MaxHeimbrock Nov 3, 2026
a3d4c13
test(session): cover agent projection across reconnects, leaves and t…
MaxHeimbrock Nov 3, 2026
1cbb509
feat(session): add the Dispatcher fan-out
MaxHeimbrock Nov 3, 2026
b344981
test(session): cover Dispatcher pruning
MaxHeimbrock Nov 3, 2026
673f061
feat(session): add the state shared between a session and its actor
MaxHeimbrock Nov 3, 2026
821e405
feat(session): add SessionOptions, SessionState and SessionEvent
MaxHeimbrock Nov 3, 2026
3e80c94
feat(session): add the Session handle and its constructors
MaxHeimbrock Nov 3, 2026
668a2e7
IMPORTANT(session): add the session actor and its agent-state projection
MaxHeimbrock Nov 3, 2026
b8c2b61
IMPORTANT(session): read chat and transcript streams in the actor
MaxHeimbrock Nov 3, 2026
cd02a39
IMPORTANT(session): start and end a session
MaxHeimbrock Nov 3, 2026
ce27505
feat(session): expose state, room, agent tracks and the message feed
MaxHeimbrock Nov 3, 2026
e810c78
test(session): assert with_agent fetches with the agent name
MaxHeimbrock Nov 3, 2026
57ecc70
test(session): add the e2e harness with a stand-in agent
MaxHeimbrock Nov 3, 2026
9240097
test(session): e2e agent state follows joins, leaves and reconnects
MaxHeimbrock Nov 3, 2026
75a16ce
test(session): e2e agent connect timeout
MaxHeimbrock Nov 3, 2026
2c9bc28
test(session): e2e start publishes the platform microphone
MaxHeimbrock Nov 3, 2026
279430d
test(session): e2e the feed merges chat and transcripts
MaxHeimbrock Nov 3, 2026
74c9a5b
test(session): e2e agent audio and avatar video tracks
MaxHeimbrock Nov 3, 2026
1163192
test(session): e2e restart after a disconnect and a rejected token
MaxHeimbrock Nov 3, 2026
c099316
test(session): e2e end and drop cancel a pending start
MaxHeimbrock Nov 3, 2026
bd572b8
test(session): e2e a start cancelled during the handshake leaves noth…
MaxHeimbrock Nov 3, 2026
8d23ac7
test(session): e2e memory lifecycle
MaxHeimbrock Nov 3, 2026
8fb6d40
docs(session): add the crate README
MaxHeimbrock Nov 3, 2026
50da432
feat(example): add the session voice and text chat example
MaxHeimbrock Nov 3, 2026
810281d
chore(session): add the changeset
MaxHeimbrock Nov 3, 2026
e288351
AgentState is now nested like Swift
MaxHeimbrock Nov 4, 2026
22a30ef
Moving waiting for publish microphone into the actor
MaxHeimbrock Nov 4, 2026
527eb25
agent tracks can be tracked without touching room
MaxHeimbrock Nov 9, 2026
15cb834
Session options are now private
MaxHeimbrock Nov 9, 2026
20f290c
Documented that sids should be compared on state changeds
MaxHeimbrock Nov 9, 2026
bcb88fd
Room connection state Disconnected maps to session connection state D…
MaxHeimbrock Nov 16, 2026
cc01f83
Making actor enums non exhaustive
MaxHeimbrock Nov 16, 2026
608ed5c
Agent is a concept that lives in the agent state holding the audio an…
MaxHeimbrock Nov 18, 2026
b8dada0
Use clap for example
MaxHeimbrock Nov 18, 2026
4c38411
Debug on Session
MaxHeimbrock Nov 18, 2026
9900be5
Mark message as non exhaustive
MaxHeimbrock Nov 18, 2026
977a6fb
builder lite pattern for message
MaxHeimbrock Nov 19, 2026
9627dab
Message restore makes less copies
MaxHeimbrock Nov 19, 2026
7903b02
Move integration tests out into test folder
MaxHeimbrock Nov 19, 2026
cdb6e42
agent identity is part of the failed left agent state to prepare for …
MaxHeimbrock Nov 20, 2026
e20fd1c
Formatting error
MaxHeimbrock Nov 20, 2026
1a93849
adapt test to new pattern
MaxHeimbrock Nov 23, 2026
1e1c931
Add canListen which right now maps to is_connected since Rust has no …
MaxHeimbrock Nov 23, 2026
67e30df
SessionOptions as the builder
MaxHeimbrock Nov 23, 2026
0fe9b1a
Remove random implicit error conversion
MaxHeimbrock Nov 25, 2026
ec460af
Exchanged dispatcher for tokio broadcast and use a new SessionEventSt…
MaxHeimbrock Nov 26, 2026
63c8d71
Use SystemTime for message timestamps instead of chrono
MaxHeimbrock Nov 30, 2026
3af5b3c
Add livekit-session to verwalter and change version to 0.0.0 for manu…
MaxHeimbrock Nov 30, 2026
12011d7
Move protocol submodule back to main commit
MaxHeimbrock Dec 3, 2026
84c198a
Update cargo after rebase
MaxHeimbrock Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add_livekit_session_crate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
livekit-session: minor
---

Add the `livekit-session` crate, whose `Session` fetches credentials from a token source, connects a room, publishes the platform microphone and plays the agent's audio by default (`SessionOptions::with_platform_audio`), projects the agent's state (`AgentState`) into a `watch` channel, and merges chat and transcripts into one message feed, with a README and an `examples/session` voice and text chat.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
/livekit-wakeword/ @pham-tuan-binh
/livekit-net/ @jhugman
/livekit-token-source/ @MaxHeimbrock
/livekit-session/ @MaxHeimbrock
/livekit-signaling/ @lukasIO
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ check = [
]
```

A crate with no such table is not feature-checked at all. Today eleven crates are `"powerset"`, `livekit` and `livekit-api` are `"curated"`, and `livekit-ffi` deliberately declares nothing.
A crate with no such table is not feature-checked at all. Today twelve crates are `"powerset"`, `livekit`, `livekit-api` and `livekit-session` are `"curated"`, and `livekit-ffi` deliberately declares nothing.

- **When adding a workspace crate**, give it `mode = "powerset"` and stop there
- Its features are then picked up automatically as they are added, and no CI file changes
- Reach for `"curated"` only when the powerset is genuinely too expensive — that is a real loss of coverage, so it needs a reason recorded next to the table
- cargo-hack only varies the features of packages it is given. A crate with no table still gets built as a dependency, which makes it easy to assume it is covered when it is not
- **When adding a feature to a `"curated"` crate** (`livekit`, `livekit-api`), add the configurations a user would plausibly select to that crate's `check` list
Comment thread
1egoman marked this conversation as resolved.
Resolved
- **When adding a feature to a `"curated"` crate** (`livekit`, `livekit-api`, `livekit-session`), add the configurations a user would plausibly select to that crate's `check` list
- A curated crate's new feature is invisible to this job until it is listed there — this is the standing cost of `"curated"`
- Each entry is a complete feature set, run as `--no-default-features --features <entry joined by commas>`. Spell defaults as `"default"`, since a bare `[]` already means "no features at all"
- Pair the feature with what it realistically ships alongside (a TLS backend together with `native`, say) rather than listing it on its own
Expand Down
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"livekit-telemetry",
"livekit-token",
"livekit-token-source",
"livekit-session",
"livekit-ffi-node-bindings",
"livekit-capture",
"livekit-net",
Expand Down Expand Up @@ -41,6 +42,7 @@ members = [
"examples/rpc",
"examples/save_to_disk",
"examples/screensharing",
"examples/session",
"examples/telemetry_ping",
"examples/token_source",
"examples/webhooks",
Expand All @@ -62,6 +64,7 @@ livekit-capture = { version = "0.3.2", path = "livekit-capture" }
livekit-ffi = { version = "0.17.0", path = "livekit-ffi" }
livekit-datatrack = { version = "0.3.1", path = "livekit-datatrack" }
livekit-telemetry = { version = "0.3.1", path = "livekit-telemetry" }
livekit-session = { version = "0.0.0", path = "livekit-session" }
livekit-signaling = { version = "0.4.0", path = "livekit-signaling" }
livekit-token = { version = "0.6.0", path = "livekit-token" }
livekit-token-source = { version = "0.2.1", path = "livekit-token-source" }
Expand Down
13 changes: 13 additions & 0 deletions examples/session/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "session"
version = "0.1.0"
edition.workspace = true
publish = false

[dependencies]
clap = { workspace = true, features = ["derive", "env"] }
env_logger = { workspace = true }
futures-util = { workspace = true }
livekit-session = { workspace = true, features = ["rustls-tls-native-roots"] }
livekit-token-source = { workspace = true }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: At present, users must manually depend on livekit and livekit-token-source at the correct version to use types from those crates that appear in the public API of livekit-session. I think it's worth thinking about re-exporting them from this crate to avoid that requirement:

// lib.rs
pub use livekit; 
pub use livekit_token_source;

@1egoman, curious your thoughts here.

@1egoman 1egoman Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point to consider. I am a bit conflicted though, in other places to solve this type of problem (ie, a "peer dependency") I've seen places where standard practice seems to dictate that keeping multiple packages in sync via version to be what people recommend. I've never really liked this pattern though and think it is really easy to cause things to break.

I think if we went down this path, then there would be a natural push for people going forward to do livekit_session::livekit::Room instead of livekit::Room. Would the idea be that we'd point people at livekit_session::livekit::Room generally though going forward in all docs surfaces? Or a mixture of livekit::Room / livekit_session::livekit::Room?

Other idea: expose a session feature on livekit which inverts the dependency, would mean livekit-session stays internal, and that all users would always access livekit objects under the same namespace:

# Cargo.toml
livekit = { version = "0.10", features = ["session"] } 
// A user's main.rs
use livekit::session::Session;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decide to for now leave the import up to the devs, considering re-export or a feature solutions till but we don't want to block this PR.

tokio = { workspace = true, features = ["full"] }
31 changes: 31 additions & 0 deletions examples/session/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Session

A conversation with a LiveKit agent, built on `livekit-session`. The microphone is published and
the agent's audio is played through platform audio, with echo cancellation, so no headphones are
needed. Lines typed on stdin are sent to the agent as well; the agent's replies, what you say once
transcribed, and state changes are printed as they arrive.

Credentials come from a [development token server](https://docs.livekit.io/frontends/build/authentication/development-token-server/),
which also dispatches the agent:

```bash
LIVEKIT_TOKEN_SERVER_ID=<token server id> LIVEKIT_AGENT_NAME=<agent name> cargo run -p session
```

Or from a pre-generated token, whose room configuration dispatches the agent:

```bash
LIVEKIT_URL=wss://<project>.livekit.cloud LIVEKIT_TOKEN=<token> cargo run -p session
```

Every variable also has a flag (`--token-server-id`, `--agent-name`, `--url`, `--token`); see
`cargo run -p session -- --help`.

Pass `--text` to leave the audio devices alone and talk by typing only, e.g. on a machine without
a microphone. The agent then needs to accept text input.

```bash
cargo run -p session -- --text
```

Close stdin (Ctrl-D) to end the session.
127 changes: 127 additions & 0 deletions examples/session/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use std::error::Error;
use std::time::Duration;

use clap::Parser;
use futures_util::StreamExt;
use livekit_session::{
Message, MessageOrigin, Session, SessionEvent, SessionOptions, SessionState,
};

use livekit_token_source::{development_token_server, literal, TokenSourceFetchOptions};
use tokio::io::{AsyncBufReadExt, BufReader};

/// A conversation with a LiveKit agent over voice and typed text
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// LiveKit server URL, used together with --token
#[arg(long, env = "LIVEKIT_URL")]
url: Option<String>,

/// Pre-generated token whose room configuration dispatches the agent
#[arg(long, env = "LIVEKIT_TOKEN", hide_env_values = true)]
token: Option<String>,

/// Development token server ID, used when no URL and token are given
#[arg(long, env = "LIVEKIT_TOKEN_SERVER_ID")]
token_server_id: Option<String>,

/// Agent for the development token server to dispatch
#[arg(long, env = "LIVEKIT_AGENT_NAME")]
agent_name: Option<String>,

/// Leave the audio devices alone and talk by typing only
#[arg(long)]
text: bool,
}

/// Creates session options with credentials from a pre-generated token if one
/// is given, and from a development token server otherwise.
fn create_options(args: Args) -> Result<SessionOptions, Box<dyn Error>> {
if let (Some(url), Some(token)) = (args.url, args.token) {
return Ok(SessionOptions::new_fixed_source(literal(url, token)));
}
let token_server_id = args
.token_server_id
.ok_or("pass --token-server-id, or --url and --token (or set the LIVEKIT_* variables)")?;
let mut fetch_options = TokenSourceFetchOptions::new();
if let Some(agent_name) = args.agent_name {
fetch_options = fetch_options.with_agent_name(agent_name);
}
Ok(SessionOptions::new_configurable_source(
development_token_server(token_server_id),
fetch_options,
))
}

/// Prints a message once it is complete. The user's own input is skipped, as
/// it is already on screen.
fn print_message(message: &Message) {
if !message.is_final {
return;
}
let speaker = match message.origin {
MessageOrigin::AgentTranscript => "agent",
MessageOrigin::UserTranscript => "you (transcribed)",
MessageOrigin::UserInput => return,
_ => message.participant_identity.as_str(),
};
println!("{speaker}: {}", message.text);
}

fn print_state(state: &SessionState) {
println!("[{:?}, agent {:?}]", state.connection, state.agent);
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();
let args = Args::parse();

// By default the session captures the microphone and plays the agent's
// audio, with echo cancellation between the two. `--text` keeps the
// conversation to typed lines, e.g. on a machine without audio devices.
let text = args.text;
let session_options = create_options(args)?
.with_agent_connect_timeout(Duration::from_secs(15))
.with_platform_audio(!text);
let session = Session::new(session_options);
let mut events = session.subscribe();
session.start().await?;

// `changed` reports only later updates, so print where the session starts.
let mut state = session.state();
print_state(&state.borrow_and_update());
let mut lines = BufReader::new(tokio::io::stdin()).lines();
loop {
tokio::select! {
changed = state.changed() => {
if changed.is_err() {
break;
}
let current = state.borrow_and_update().clone();
println!("{:?}", session);
if !current.connection.is_connected() {
break;
}
}
Some(event) = events.next() => {
if let SessionEvent::MessageUpserted(message) = event {
print_message(&message);
}
}
line = lines.next_line() => match line? {
Some(line) if line.trim().is_empty() => {}
Some(line) => {
if let Err(err) = session.send_text(line.trim()).await {
eprintln!("failed to send: {err}");
}
}
None => break,
},
}
}

session.end().await;
Ok(())
}
63 changes: 63 additions & 0 deletions livekit-session/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[package]
name = "livekit-session"
description = "Agent sessions for the LiveKit Rust SDK"
version = "0.0.0"
license.workspace = true
edition.workspace = true
repository.workspace = true
readme = "README.md"

[features]
default = ["native"]

# Backend and TLS pass-throughs, forwarded to both the room connection
# (livekit) and the token fetch (livekit-token-source).
native = ["livekit/native", "livekit-token-source/native"]
native-tls = ["livekit/native-tls", "livekit-token-source/native-tls"]
native-tls-vendored = ["livekit/native-tls-vendored", "livekit-token-source/native-tls-vendored"]
rustls-tls-native-roots = [
"livekit/rustls-tls-native-roots",
"livekit-token-source/rustls-tls-native-roots",
]
rustls-tls-webpki-roots = [
"livekit/rustls-tls-webpki-roots",
"livekit-token-source/rustls-tls-webpki-roots",
]

# End-to-end tests against a running `livekit-server --dev`.
__lk-e2e-test = []

# How CI checks this crate's features, read by
# `.github/workflows/feature-combinations-curated.yml` via `cargo metadata`.
# See the equivalent table in `livekit/Cargo.toml` for the encoding.
#
# Curated rather than a powerset: every TLS feature is forwarded to `livekit`,
# so most powerset entries rebuild `livekit` underneath, and depth 2 would
# spend 22 checks mostly on two TLS backends at once or `__lk-e2e-test` paired
# with something unrelated, which nobody can select. The TLS forwards
# themselves are covered by `livekit`'s own list.
[package.metadata.feature-combinations]
mode = "curated"
check = [
["default"], # a plain `cargo check`
[], # --no-default-features
["native", "rustls-tls-webpki-roots"],
["default", "rustls-tls-native-roots"], # defaults *plus* one
]

[dependencies]
futures-util = { workspace = true, features = ["std"] }
livekit = { workspace = true }
livekit-token-source = { workspace = true }
Comment thread
MaxHeimbrock marked this conversation as resolved.
Resolved
log = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt", "sync", "time"] }
tokio-stream = { workspace = true, features = ["sync"] }

[dev-dependencies]
anyhow = { workspace = true }
async-trait = "0.1"
livekit-api = { workspace = true }
livekit-protocol = { workspace = true }
livekit-token = { workspace = true }
tokio = { workspace = true, features = ["io-util", "macros", "net", "rt-multi-thread", "sync", "time"] }
Loading
Loading