i want to make tool call the collect email form us...
# ask-ai
n
i want to make tool call the collect email form user it should wait untilll user send his email form the fornt end
t
Thanks for reaching out, Mohamed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd be happy to help you collect an email from a user and wait for their input on the front end! You can use the prebuilt
GetEmailTask
in LiveKit, which is thoughtfully designed to handle email collection, including validation and user confirmation. Here’s a simple way to get started: 1. In your agent, use the
GetEmailTask
to kick off the email collection process. For example:
Copy code
from livekit.agents.beta.workflows import GetEmailTask

email_result = await GetEmailTask(chat_ctx=self.chat_ctx)
print(f"Collected email: {email_result.email_address}")
This task will patiently wait for the user to provide and confirm their email address. On the front end, just make sure the user’s input (whether speech or text) is sent over to LiveKit. For text input, you can use the
sendText
method on the room’s local participant. Here’s a quick example:
Copy code
// JavaScript Example
const text = "My email is john@example.com";
await room.localParticipant.sendText(text, "lk.chat");
If you have any questions or need a hand with the setup, please don’t hesitate to reach out—I’m here to help! Sources: Workflows | LiveKit Docs | examples/frontdesk/test_agent.py | Docs::Agents
n
EBUGlivekit.agentsreceived user transcript 2025-09-15 153936,862 - DEBUG livekit.agents - received user transcript {"user_transcript": "I haven't. I have an issue with my laptop.", "language": "en-US"} INFOavatar exampleplayback_finished 2025-09-15 153952,361 - INFO avatar-example - playback_finished {"playback_position": 13.270208333333326, "interrupted": false} DEBUGlivekit.agentsexecuting tool 2025-09-15 153954,168 - DEBUG livekit.agents - executing tool {"function": "get_user_email", "arguments": "{}", "speech_id": "speech_b1b1304a4f25"} INFOavatar exampleCollecting email from user 2025-09-15 153954,169 - INFO avatar-example - Collecting email from user ERRORasyncioTask exception was never retrieved future: <Task finished name='Task-347' coro=<RoomIO._on_user_text_input.<locals>._read_text() done, defined at C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\room_io\room_io.py:450> exception=RuntimeError('cannot schedule new speech, the speech scheduling is draining/pausing')> Traceback (most recent call last): File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\room_io\room_io.py", line 453, in _read_text text_input_result = self._input_options.text_input_cb( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\room_io\room_io.py", line 57, in _default_text_input_cb sess.generate_reply(user_input=ev.text) File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent_session.py", line 731, in generate_reply handle = self._next_activity._generate_reply( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent_activity.py", line 780, in _generate_reply self._schedule_speech(handle, SpeechHandle.SPEECH_PRIORITY_NORMAL) File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent_activity.py", line 846, in _schedule_speech raise RuntimeError( RuntimeError: cannot schedule new speech, the speech scheduling is draining/pausing 2025-09-15 154007,198 - ERROR asyncio - Task exception was never retrieved future: <Task finished name='Task-347' coro=<RoomIO._on_user_text_input.<locals>._read_text() done, defined at C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\room_io\room_io.py:450> exception=RuntimeError('cannot schedule new speech, the speech scheduling is draining/pausing')> Traceback (most recent call last): File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\room_io\room_io.py", line 453, in _read_text text_input_result = self._input_options.text_input_cb( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\room_io\room_io.py", line 57, in _default_text_input_cb sess.generate_reply(user_input=ev.text) File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent_session.py", line 731, in generate_reply handle = self._next_activity._generate_reply( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent_activity.py", line 780, in _generate_reply self._schedule_speech(handle, SpeechHandle.SPEECH_PRIORITY_NORMAL) File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent_activity.py", line 846, in _schedule_speech raise RuntimeError( RuntimeError: cannot schedule new speech, the speech scheduling is draining/pausing ERRORlivekit.agentsError in _llm_inference_task Traceback (most recent call last): File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\utils\log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\opentelemetry\util\_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\generation.py", line 124, in _llm_inference_task async for chunk in llm_node: File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 365, in llm_node activity = agent._get_activity_or_raise() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 318, in _get_activity_or_raise raise RuntimeError("no activity context found, the agent is not running") RuntimeError: no activity context found, the agent is not running 2025-09-15 154007,302 - ERROR livekit.agents - Error in _llm_inference_task Traceback (most recent call last): File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\utils\log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\opentelemetry\util\_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\generation.py", line 124, in _llm_inference_task async for chunk in llm_node: File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 365, in llm_node activity = agent._get_activity_or_raise() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 318, in _get_activity_or_raise raise RuntimeError("no activity context found, the agent is not running") RuntimeError: no activity context found, the agent is not running ERRORlivekit.agentsError in _tts_inference_task Traceback (most recent call last): File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\utils\log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\opentelemetry\util\_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\generation.py", line 212, in _tts_inference_task async for audio_frame in tts_node: File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 386, in tts_node activity = agent._get_activity_or_raise() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 318, in _get_activity_or_raise raise RuntimeError("no activity context found, the agent is not running") RuntimeError: no activity context found, the agent is not running 2025-09-15 154007,457 - ERROR livekit.agents - Error in _tts_inference_task Traceback (most recent call last): File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\utils\log.py", line 16, in async_fn_logs return await fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\opentelemetry\util\_decorator.py", line 71, in async_wrapper return await func(*args, **kwargs) # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\generation.py", line 212, in _tts_inference_task async for audio_frame in tts_node: File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 386, in tts_node activity = agent._get_activity_or_raise() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\ASUS\Desktop\Nancy AI\meeting-agent-livekit\livekitAzure-simli\venv\Lib\site-packages\livekit\agents\voice\agent.py", line 318, in _get_activity_or_raise raise RuntimeError("no activity context found, the agent is not running") RuntimeError: no activity context found, the agent is not running WARNINGlivekit.plugins.azureSpeech recognition canceled: CancellationDetails(reason=CancellationReason.Error, error_details="Timeout while waiting for service to stop SessionId: 76b272bad80c480696e69d829f8c9125") 2025-09-15 154012,616 - WARNING livekit.plugins.azure - Speech recognition canceled: CancellationDetails(reason=CancellationReason.Error, error_details="Timeout while waiting for service to stop SessionId: 76b272bad80c480696e69d829f8c9125") {"code": "CancellationErrorCode.ServiceTimeout", "reason": "CancellationReason.Error", "error_details": "Timeout while waiting for service to stop SessionId: 76b272bad80c480696e69d829f8c9125"} Process inference_proc: Traceback (most recent call last): File "C:\Program Files\Python311\Lib\asyncio\windows_events.py", line 494, in finish_recv return ov.getresult() ^^^^^^^^^^^^^^ OSError: [WinError 64] The specified network name is no longer available During handling of the above exception, another exception occurred:
t
It looks like you're encountering the error
RuntimeError: cannot schedule new speech, the speech scheduling is draining/pausing
. This happens when the agent's speech scheduling system is in a draining or paused state, which usually occurs during transitions like handoffs or when the agent is being paused or shut down. Here are some steps that can help you resolve this: 1. Try to avoid scheduling speech actions (such as
say()
or
generate_reply()
) while the agent is draining or paused. It’s best to initiate speech actions only when the agent is fully active. 2. If you need a tool to respond during draining, it’s safer to use the agent’s built-in tool response mechanism, which is designed to handle this smoothly. 3. When managing the agent’s lifecycle programmatically, please wait for the current activity to finish draining before starting any new speech actions. 4. Also, avoid scheduling additional speech after a handoff has started, since the system pauses speech scheduling to complete the handoff properly. If any of this feels unclear or if you’d like some help implementing these steps, please don’t hesitate to reach out. I’m here to support you! Sources: livekit-agents/livekit/agents/voice/speech_handle.py
n
write me the tool
t
I'd love to share an example of a tool implementation that gently collects an email from the user while making sure it avoids scheduling speech during draining or pausing states:
Copy code
from livekit.agents.beta.workflows import GetEmailTask
from livekit.agents.voice.agent_tools import function_tool

class EmailCollectionAgent:

    @function_tool
    async def collect_user_email(self, context):
        try:
            # Use GetEmailTask to collect the email from the user
            email_result = await GetEmailTask(chat_ctx=self.chat_ctx)
            email_address = email_result.email_address

            # Return a confirmation message
            return f"Thank you! Collected email: {email_address}"

        except RuntimeError as e:
            # Handle speech scheduling errors or other runtime issues
            if "speech scheduling is draining/pausing" in str(e):
                return "Unable to collect email at the moment due to agent state. Please try again later."
            else:
                raise e

        except Exception as e:
            # Handle any other exceptions
            return f"An error occurred: {str(e)}"
This tool thoughtfully uses the
GetEmailTask
to collect and validate the user's email address. It also includes careful error handling for speech scheduling issues and other unexpected exceptions. If you'd like, I'm here to help with any further customization or to add additional features to make this tool fit your needs perfectly. Just let me know!
n
this is the leatest tool defention way ?
t
I'd love to help you understand the latest way to define tools in LiveKit Agents, which varies depending on the programming language you're using: • Python: You can use the
@function_tool
decorator to define tools either within an agent class or as standalone functions. By default, the function's name and docstring become the tool's name and description. Here's a simple example to get you started:
Copy code
from livekit.agents import function_tool, Agent, RunContext

class MyAgent(Agent):
    @function_tool()
    async def lookup_weather(self, context: RunContext, location: str) -> dict:
        """Look up weather information for a given location."""
        return {"weather": "sunny", "temperature_f": 70}
• Node.js: You can define tools directly in the agent configuration using
llm.tool()
. Here's an example that might help:
Copy code
const getWeather = llm.tool({
  description: 'Called when the user asks about the weather.',
  parameters: z.object({
    location: z.string().describe('The location to get the weather for'),
  }),
  execute: async ({ location }, { ctx }) => {
    return `The weather in ${location} is sunny today.`;
  },
});

const agent = new voice.Agent({
  instructions: 'You are a helpful assistant.',
  tools: { getWeather },
});
Both of these approaches give you access to the agent's state via
RunContext
and support dynamic updates to your tools. If you'd like me to walk you through this further or provide more examples, just let me know—I'm here to help! Sources: Tool definition and use | LiveKit Docs | Agents 0.x migration guide | LiveKit Docs | Agents v0.x migration guide - Node.js | LiveKit Docs
n
i want to notify user in the frontend you to inter his email how ?
t
I’d be happy to help you notify a user in the frontend to enter their email! You have a couple of friendly options to consider: 1. Frontend Web UI: You can create a simple modal or form that kindly asks the user to enter their email before joining a LiveKit session. For example:
Copy code
<input id="email" type="email" name="email" placeholder="Enter your email address" required />
Once they submit their email, you can store it in your application’s state and then connect them to the LiveKit room. This can also tie in smoothly with your authentication flow. 1. Voice Agent Workflow: Another great option is to use the
GetEmailTask
from LiveKit’s Agents SDK, which prompts the user via voice and even handles validating and confirming the email address for you. If you'd like, I can provide a detailed code example for either method or assist you further—just let me know! I’m here to help. Sources: Building the all-in-one platform for voice AI agents | client/components/login-form.tsx | livekit-agents/livekit/agents/beta/workflows/email_address.py | flows/declarative_flow.py