-
Notifications
You must be signed in to change notification settings - Fork 131
Update readme to include agents sdk example #1219
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
1egoman
wants to merge
3
commits into
main
Choose a base branch
from
agents-sdk-readme-updates
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
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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -21,7 +21,88 @@ Use this SDK to add realtime video, audio and data features to your React app. B | |
|
|
||
|  | ||
|
|
||
| ## Quick Start | ||
| ## Agents Quick Start | ||
|
|
||
| First add the library to your project: | ||
|
|
||
| ```shell | ||
| npm i @livekit/components-react | ||
| ``` | ||
|
|
||
| Next, you need a running agent. If you don't already have one, [it only takes a few minutes to set one up](https://docs.livekit.io/agents/start/voice-ai). | ||
|
|
||
| The rest of this guide assumes your agent is configured for [explicit dispatch](https://docs.livekit.io/agents/worker/agent-dispatch/#explicit) with `agent_name="example-agent"`. | ||
|
|
||
| Then, you can use the agents sdk to connect and interact with your agent: | ||
|
|
||
| ```tsx | ||
| import { useEffect, useState } from "react"; | ||
| import { TokenSource } from "livekit-client"; | ||
| import { | ||
| useSession, | ||
| useAgent, | ||
| SessionProvider, | ||
| VideoTrack, | ||
| StartAudio, | ||
| RoomAudioRenderer, | ||
| } from "@livekit/components-react"; | ||
|
|
||
| // Generated credentials manually and put them here | ||
| // Or, generate them another way: FIXME: add docs link here! | ||
|
Comment on lines
+50
to
+51
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another place the eventual TokenSource docs from here should be linked: livekit/client-sdk-js#1681 |
||
| const tokenSource = TokenSource.literal({ | ||
| serverUrl: "wss://my-livekit-server", | ||
| participantToken: 'generated-jwt', | ||
| }); | ||
|
|
||
| export default function Example() { | ||
| const session = useSession(tokenSource, { | ||
| agentName: 'example-agent', /* <== Put your agent name here! */ | ||
| }); | ||
|
|
||
| const toggleStarted = () => { | ||
| if (session.connectionState === 'disconnected') { | ||
| session.start(); | ||
| } else { | ||
| session.end(); | ||
| } | ||
| }; | ||
|
|
||
| const agent = useAgent(session); | ||
|
|
||
| return ( | ||
| <SessionProvider session={session}> | ||
| <button onClick={toggleStarted} disabled={session.connectionState === 'connecting'}> | ||
| {session.isConnected ? 'Disconnect' : 'Connect'} | ||
| </button> | ||
|
|
||
| {session.isConnected ? ( | ||
| <div className="flex flex-col gap-4 p-4"> | ||
| <span> | ||
| <strong>Connection State:</strong> | ||
| {session.connectionState} | ||
| </span> | ||
| <span> | ||
| <strong>Agent State:</strong> | ||
| {agent.state} | ||
| </span> | ||
|
|
||
| {session.local.cameraTrack ? ( | ||
| <VideoTrack trackRef={session.local.cameraTrack} /> | ||
| ) : null} | ||
| {agent.cameraTrack ? ( | ||
| <VideoTrack trackRef={agent.cameraTrack} /> | ||
| ) : null} | ||
|
|
||
| <StartAudio label="Start audio" /> | ||
| <RoomAudioRenderer /> | ||
| </div> | ||
| ) : null} | ||
| </SessionProvider> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### Video Conference Quick Start | ||
|
|
||
| First add the library to your project: | ||
1egoman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: by looking at the doc today, it seems Video Conference Quick Start is under Agent SDK Example, while I think they should be separate sections.
Does it make sense to have 1, 2 to distinguish the session that they are for different use cases like
1. Agent SDK Example
2. Video Conference Quick Start