diff --git a/scenarios.yaml b/scenarios.yaml index 0df4b31..acdeee3 100644 --- a/scenarios.yaml +++ b/scenarios.yaml @@ -52,3 +52,17 @@ scenarios: alternative, such as the friend using the official account recovery flow. tags: feature: guardrails + + - id: SCN_YAcWiy4Ee2mG + label: Ends the call when the user is done + instructions: | + PERSONA: A user with one quick question who wants to hang up as soon as it's answered. + OPENING LINE: "What's the capital of France?" + DO, IN ORDER: + 1. Once the assistant answers, say: "Great, that's all I needed. Bye!" + agent_expectations: > + Answers the question briefly, then says goodbye and ends the call with the + end_call tool once the user says they are done. Does not end the call + before the question is answered. + tags: + feature: end-call diff --git a/src/agent.ts b/src/agent.ts index 5c51377..76d234a 100644 --- a/src/agent.ts +++ b/src/agent.ts @@ -1,4 +1,4 @@ -import { Agent, dedent, inference } from '@livekit/agents'; +import { Agent, beta, dedent, inference } from '@livekit/agents'; // Build a custom voice AI assistant with the functional `Agent.create` API export function createAgent() { @@ -47,29 +47,34 @@ export function createAgent() { // (Note: This is for OpenAI GPT-Live. For other models, see https://docs.livekit.io/agents/models/realtime/) // llm: new inference.DuplexModel({ model: 'openai/gpt-live-1', voice: 'marin' }), - // To add tools, specify `tools` in the constructor. + // The end call tool lets the agent hang up when the user is done, and deletes the room + // so every participant, including SIP callers, is disconnected. + // See more at https://docs.livekit.io/agents/prebuilt/tools/end-call-tool/ + // + // To add your own tools, add them to the `tools` array. // 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.'; - // }, - // }), - // ], + tools: [ + beta.createEndCallTool(), + // 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.'; + // }, + // }), + ], }); } diff --git a/src/main.ts b/src/main.ts index c3143d1..261e45e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ export default defineAgent({ // Speech-to-text (STT) is your agent's ears, turning the user's speech into text that the LLM can understand // See all available models at https://docs.livekit.io/agents/models/stt/ stt: new inference.STT({ - model: 'assemblyai/universal-3-6-pro', + model: 'assemblyai/assemblyai-stt-3-7-realtime-agent', }), // Keyterms bias the STT toward distinctive words it would otherwise misspell. @@ -34,6 +34,9 @@ export default defineAgent({ tts: new inference.TTS({ model: 'fishaudio/s2.1-pro', voice: 'fa4c9eb3dccc4806b382b40d61c6b10a', + // If the primary model fails, LiveKit Inference tries these models in order + // See more at https://docs.livekit.io/agents/logic/fallback-strategies/ + fallback: [{ model: 'rime/coda', voice: 'astra' }], }), turnHandling: {