Skip to content

Add deployment to CreateDispatchOptions#675

Open
lukasIO wants to merge 2 commits into
mainfrom
lukas/agent-deployment
Open

Add deployment to CreateDispatchOptions#675
lukasIO wants to merge 2 commits into
mainfrom
lukas/agent-deployment

Conversation

@lukasIO

@lukasIO lukasIO commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@changeset-bot

changeset-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 80b5d17

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
livekit-server-sdk Patch
agent-dispatch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

const svc = 'AgentDispatchService';

/** @throws TypeError on invalid deployment names */
export function validateAgentDeploymentString(deployment: string): void {

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.

tbd if we even need client side validation. If we don't I'll simply remove this helper and the related tests

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.

If you do decide this is important (you may have more context than me on this), definitely make sure it ends up in livekit/client-sdk-js#1971 too.

I also agree though that I think it probably makes sense to start without this, and if validation is really needed IMO it might be better to do it in upstream systems (ie, something agents hosting related?) and have it surface the validation error over webrtc.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@1egoman , could you please remove this validateAgentDeploymentString and land the PR ?

xianshijing-lk added a commit to livekit/client-sdk-swift that referenced this pull request Jun 17, 2026
## Summary
- Add `deployment` field to `RoomAgentDispatch` for targeting specific
agent deployments
- Add `agentDeployment` to `TokenRequestOptions` to pass deployment
through token requests

The `deployment` field allows targeting a specific agent deployment
(e.g., "staging"). Leave empty to target the production deployment.

Related PRs:
- node-sdks: livekit/node-sdks#675
- python-sdks: livekit/python-sdks#722
- rust-sdks: livekit/rust-sdks#1176
- client-sdk-js: livekit/client-sdk-js#1971

## Usage
```swift
let options = TokenRequestOptions(
    roomName: "my-room",
    agentName: "my-agent",
    agentDeployment: "staging"  // Optional: target specific deployment
)
```

Or directly via `RoomAgentDispatch`:
```swift
let dispatch = RoomAgentDispatch(
    agentName: "my-agent",
    metadata: "my-metadata",
    deployment: "staging"
)
```

## Test plan

### Unit Tests
```bash
swift test
# Or via Xcode
xcodebuild test -scheme LiveKit -destination "platform=iOS Simulator,name=iPhone 15"
```

### Manual Verification

**1. Verify JSON serialization includes deployment:**
```swift
let dispatch = RoomAgentDispatch(
    agentName: "my-agent",
    deployment: "staging"
)
let encoder = JSONEncoder()
let data = try encoder.encode(dispatch)
let json = String(data: data, encoding: .utf8)!
print(json)  // Should include "deployment": "staging"
```

**2. Verify TokenRequestOptions converts to request correctly:**
```swift
let options = TokenRequestOptions(
    roomName: "test-room",
    agentName: "my-agent",
    agentDeployment: "staging"
)
let request = options.toRequest()
print(request.roomConfiguration?.agents?.first?.deployment)  // Should print "staging"
```

**3. Verify token contains deployment (with TokenSource):**
```swift
let response = try await tokenSource.fetch(TokenRequestOptions(
    roomName: "test-room",
    agentName: "my-agent",
    agentDeployment: "staging"
))
if let jwt = response.jwt(),
   let agents = jwt.roomConfiguration?.agents {
    print("Deployment: \(agents.first?.deployment ?? "nil")")
}
```

### End-to-End Verification
1. Use TokenSource to get credentials with deployment
2. Connect to room - agent with matching deployment should join
3. Verify only staging agent receives the dispatch

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Błażej Pankowski <86720177+pblazej@users.noreply.github.com>
xianshijing-lk added a commit to livekit/rust-sdks that referenced this pull request Jun 17, 2026
## Summary
- Update docstrings to document the `deployment` field in
`create_dispatch`
- Update agent_dispatch example to support the `--deployment` argument
- Add changeset

The `deployment` field allows targeting a specific agent deployment
(e.g., "staging"). Leave empty to target the production deployment.

Related PRs:
- node-sdks: livekit/node-sdks#675
- python-sdks: livekit/python-sdks#722
- client-sdk-js: livekit/client-sdk-js#1971

## Test plan

### Unit Tests
```bash
cd /path/to/rust-sdks
cargo test -p livekit-api
```

### Manual Verification

**1. Run example with deployment flag:**
```bash
cd examples/agent_dispatch
cargo run -- \
  --url $LIVEKIT_URL \
  --key $LIVEKIT_API_KEY \
  --secret $LIVEKIT_API_SECRET \
  --room-name test-room \
  --agent-name my-agent \
  --deployment staging
```

**2. Verify response contains deployment:**
```rust
let dispatch = client.create_dispatch(CreateAgentDispatchRequest {
    agent_name: "my-agent".into(),
    room: "test-room".into(),
    deployment: "staging".into(),
    ..Default::default()
}).await?;

println!("Dispatch ID: {}", dispatch.id);
println!("Deployment: {}", dispatch.deployment);  // Should print "staging"
```

**3. Verify via list_dispatch:**
```rust
let dispatches = client.list_dispatch("test-room").await?;
for d in dispatches {
    println!("Dispatch {}: deployment={}", d.id, d.deployment);
}
```

### End-to-End Verification
1. Register an agent worker with `deployment="staging"`
2. Create a dispatch targeting `deployment="staging"` using the example
3. Verify only the staging agent receives the job

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
xianshijing-lk added a commit to livekit/client-sdk-flutter that referenced this pull request Jun 17, 2026
## Summary
- Add `deployment` field to `RoomAgentDispatch` for targeting specific
agent deployments
- Add `agentDeployment` to `TokenRequestOptions` to pass deployment
through token requests
- Update generated JSON serialization code

The `deployment` field allows targeting a specific agent deployment
(e.g., "staging"). Leave empty to target the production deployment.

Related PRs:
- node-sdks: livekit/node-sdks#675
- python-sdks: livekit/python-sdks#722
- rust-sdks: livekit/rust-sdks#1176
- client-sdk-swift:
livekit/client-sdk-swift#1043
- client-sdk-js: livekit/client-sdk-js#1971

## Usage
```dart
final options = TokenRequestOptions(
  roomName: 'my-room',
  agentName: 'my-agent',
  agentDeployment: 'staging',  // Optional: target specific deployment
);
```

Or directly via `RoomAgentDispatch`:
```dart
final dispatch = RoomAgentDispatch(
  agentName: 'my-agent',
  metadata: 'my-metadata',
  deployment: 'staging',
);
```

## Test plan

### Unit Tests
```bash
flutter test
flutter test test/token/token_source_test.dart -v
```

### Manual Verification

**1. Verify JSON serialization includes deployment:**
```dart
final dispatch = RoomAgentDispatch(
  agentName: 'my-agent',
  deployment: 'staging',
);
final json = dispatch.toJson();
print(json);  // Should include 'deployment': 'staging'
```

**2. Verify TokenRequestOptions converts to request correctly:**
```dart
final options = TokenRequestOptions(
  roomName: 'test-room',
  agentName: 'my-agent',
  agentDeployment: 'staging',
);
final request = options.toRequest();
print(request.roomConfiguration?.agents?.first?.deployment);  // Should print 'staging'
```

**3. Verify JSON round-trip:**
```dart
final original = RoomAgentDispatch(
  agentName: 'my-agent',
  deployment: 'staging',
);
final json = original.toJson();
final restored = RoomAgentDispatch.fromJson(json);
assert(restored.deployment == 'staging');
```

### End-to-End Verification
1. Use TokenSource to get credentials with agentDeployment set
2. Connect to room - agent with matching deployment should join
3. Verify only staging agent receives the dispatch

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>

@xianshijing-lk xianshijing-lk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please remove the validateAgentDeploymentString and relevant tests then land the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants