-
Notifications
You must be signed in to change notification settings - Fork 74
Adopt @livekit/agents 1.5.0 (pre-release) #54
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
toubatbrian
wants to merge
5
commits into
main
Choose a base branch
from
brian/agents-1.5.0-prerelease
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
5 commits
Select commit
Hold shift + click to select a range
4f343a8
Adopt @livekit/agents 1.5.0 (pre-release)
toubatbrian 5c6a23b
save 1.5.0 template
toubatbrian 2bb3048
Update main.ts
toubatbrian e6824cf
Update agent.ts
toubatbrian 68e7cf8
ci: stop tracking pnpm-lock.yaml and pnpm-workspace.yaml
toubatbrian 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import { dedent, inference, voice } from '@livekit/agents'; | ||
| import { Agent, dedent, inference } from '@livekit/agents'; | ||
|
|
||
| // Define a custom voice AI assistant by extending the base Agent class | ||
| export class Agent extends voice.Agent { | ||
| constructor() { | ||
| super({ | ||
| instructions: dedent` | ||
| // Build a custom voice AI assistant with the functional `Agent.create` API | ||
| // (introduced in @livekit/agents 1.5.0). You can also subclass `voice.Agent`. | ||
| export function createAgent() { | ||
| return Agent.create({ | ||
| instructions: dedent` | ||
| You are a friendly, reliable voice assistant that answers questions, explains topics, and completes tasks with available tools. | ||
|
|
||
| # Output rules | ||
|
|
@@ -38,42 +38,72 @@ export class Agent extends voice.Agent { | |
| - Protect privacy and minimize sensitive data. | ||
| `, | ||
|
|
||
| // A Large Language Model (LLM) is your agent's brain, processing user input and generating a response | ||
| // See all available models at https://docs.livekit.io/agents/models/llm/ | ||
| llm: new inference.LLM({ model: 'openai/gpt-5.2-chat-latest' }), | ||
| // A Large Language Model (LLM) is your agent's brain, processing user input and generating a response | ||
| // See all available models at https://docs.livekit.io/agents/models/llm/ | ||
| llm: new inference.LLM({ model: 'openai/gpt-5.2-chat-latest' }), | ||
|
|
||
| // To use a realtime model instead of a voice pipeline, replace the LLM | ||
| // with a RealtimeModel and remove the STT/TTS from the AgentSession | ||
| // (Note: This is for the OpenAI Realtime API. For other providers, see https://docs.livekit.io/agents/models/realtime/) | ||
| // 1. Install '@livekit/agents-plugin-openai' | ||
| // 2. Set OPENAI_API_KEY in .env.local | ||
| // 3. Add `import * as openai from '@livekit/agents-plugin-openai'` to the top of this file | ||
| // 4. Replace the llm option with: | ||
| // llm: new openai.realtime.RealtimeModel({ voice: 'marin' }), | ||
| // To use a realtime model instead of a voice pipeline, replace the LLM | ||
| // with a RealtimeModel and remove the STT/TTS from the AgentSession | ||
| // (Note: This is for the OpenAI Realtime API. For other providers, see https://docs.livekit.io/agents/models/realtime/) | ||
| // 1. Install '@livekit/agents-plugin-openai' | ||
| // 2. Set OPENAI_API_KEY in .env.local | ||
| // 3. Add `import * as openai from '@livekit/agents-plugin-openai'` to the top of this file | ||
| // 4. Replace the llm option with: | ||
| // llm: new openai.realtime.RealtimeModel({ voice: 'marin' }), | ||
|
|
||
| // To add tools, specify `tools` in the constructor. | ||
| // Here's an example that adds a simple weather tool. | ||
| // You also have to add `import { llm } from '@livekit/agents' and `import { z } from 'zod'` to the top of this file | ||
| // tools: { | ||
| // getWeather: llm.tool({ | ||
| // description: dedent` | ||
| // Use this tool to look up current weather information in the given location. | ||
| // | ||
| // If the location is not supported by the weather service, the tool will indicate this. | ||
| // You must tell the user the location's weather is unavailable. | ||
| // `, | ||
| // parameters: z.object({ | ||
| // location: z | ||
| // .string() | ||
| // .describe('The location to look up weather information for (e.g. city name)'), | ||
| // }), | ||
| // execute: async ({ location }) => { | ||
| // console.log(`Looking up weather for ${location}`); | ||
| // | ||
| // return 'sunny with a temperature of 70 degrees.'; | ||
| // }, | ||
| // }), | ||
| // }, | ||
| }); | ||
| } | ||
| // To add tools, specify `tools` in the constructor. | ||
| // Here's an example that adds a simple weather tool. | ||
| // You also have to add `import { tool } from '@livekit/agents'` and `import { z } from 'zod'` to the top of this file | ||
| // tools: [ | ||
| // tool({ | ||
| // name: 'getWeather', | ||
| // description: dedent` | ||
| // Use this tool to look up current weather information in the given location. | ||
| // | ||
| // If the location is not supported by the weather service, the tool will indicate this. | ||
| // You must tell the user the location's weather is unavailable. | ||
| // `, | ||
| // parameters: z.object({ | ||
| // location: z | ||
| // .string() | ||
| // .describe('The location to look up weather information for (e.g. city name)'), | ||
| // }), | ||
| // execute: async ({ location }) => { | ||
| // console.log(`Looking up weather for ${location}`); | ||
| // | ||
| // return 'sunny with a temperature of 70 degrees.'; | ||
| // }, | ||
| // }), | ||
| // ], | ||
|
|
||
| // You can also group long-running async tools behind a shared, scoped lifecycle with an | ||
| // `AsyncToolset` (import `AsyncToolset` from '@livekit/agents'). `setup` runs when the agent | ||
| // becomes active — connect to a backend and register tools via `updateTools` — and `aclose` | ||
| // tears it down. Its tools run on a scoped executor, so non-blocking / cancellable async | ||
| // tools keep working across agent handoffs. Add the toolset to this `tools` array like any | ||
| // other tool: | ||
| // | ||
| // let supportClient: SupportClient | undefined; | ||
|
Contributor
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. maybe we should actually have a working example here? what's a simple backend service that we could connect to that requires a long-running connection that we could showcase? |
||
| // AsyncToolset.create({ | ||
| // id: 'support-backend', | ||
| // tools: [], | ||
| // setup: async ({ updateTools }) => { | ||
| // supportClient = await connectToSupportBackend(); | ||
| // updateTools([ | ||
| // tool({ | ||
| // name: 'lookupOrder', | ||
| // description: 'Look up the status of a customer order by its ID.', | ||
| // parameters: z.object({ orderId: z.string() }), | ||
| // execute: async ({ orderId }, { ctx }) => { | ||
| // ctx.update('Looking up your order, one moment.'); | ||
| // return `Order ${orderId} is ${await supportClient!.statusOf(orderId)}.`; | ||
| // }, | ||
| // }), | ||
| // ]); | ||
| // }, | ||
| // aclose: async () => { | ||
| // await supportClient?.disconnect(); | ||
| // }, | ||
| // }), | ||
| }); | ||
| } | ||
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
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.
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.
I don't think it's a good idea to say you can also subclass
voice.Agent, since they should be equally powerful(?)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.
are they?
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.
Both are equally powerful just differ in syntax