how do I test my agent code in local .
# ask-ai
f
how do I test my agent code in local .
t
Thanks for reaching out, venu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! You’ve got a few friendly ways to test your agent code locally: • Console Mode: Just run
python myagent.py console
in your terminal for a quick check without worrying about extra dependencies. • Development Mode: Try
python myagent.py dev
to spin up the agent server with hot reloading. Don’t forget to set these environment variables first:
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
. • Agents Playground: Want a full UI experience? Connect your agent to the hosted playground or run it yourself by cloning the repo and launching it locally. • Automated Testing: For a thorough check, use the pytest-based framework. Just install the needed packages with
pip install pytest pytest-asyncio
and write tests to cover behavior, tool usage, and error handling. If you want me to walk you through any of these or have questions, just let me know—I’m happy to help! Sources: README.md | Vision Agent Quickstart | LiveKit Docs | README.md | Testing and evaluation | LiveKit Docs
f
how do I delete a deployed agent from livekit cloud
t
If you want to delete a deployed agent from LiveKit Cloud, you can do that easily with the
lk agent delete
command. Here’s how you can go about it: • Delete by Agent ID: Just run
lk agent delete --id CA_MyAgentId
to delete the agent using its ID directly. • Delete Using Configuration: If you’re in the folder with the
livekit.toml
file, simply run
lk agent delete
and it’ll grab the agent ID from there. • Delete from Specific Directory: You can also delete an agent by pointing to its config folder with
lk agent delete ./my-agent-directory
. The command will ask you to confirm before it goes ahead, so no worries about accidental deletions. Once you confirm, the agent and everything tied to it will be removed for good. If you have any questions or need a hand, just let me know—I’m here to help! Sources: autocomplete/fish_autocomplete | Agent deployment CLI reference | LiveKit Docs
f
how to listen for attribute changed state to paused for user and pause the agent from backend
t
Hey there! To keep an eye on attribute changes like 'paused' and pause the agent from the backend, here’s a simple way to do it: 1. Listen for Attribute Changes: You can use the
participant_attributes_changed
event to catch when the 'paused' attribute updates. Here’s a quick example:
Copy code
async def entrypoint(ctx: JobContext):
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
    participant = await ctx.wait_for_participant()

    @ctx.room.on("participant_attributes_changed")
    def on_participant_attributes_changed(changed_attrs: dict[str, str], p: rtc.Participant):
        if p == participant and "paused" in changed_attrs:
            is_paused = changed_attrs["paused"].lower() == "true"
            asyncio.create_task(handle_pause_state_change(session, is_paused))
1. Pause/Resume the Agent: Then, use
AgentSession.pause()
and
AgentSession.resume()
to switch the agent’s state based on that:
Copy code
async def handle_pause_state_change(session: AgentSession, is_paused: bool):
    if is_paused:
        await session.pause()
    else:
        await session.resume()
1. Set Attributes on the Client Side: Don’t forget to update the 'paused' attribute from the client side like this:
Copy code
await room.localParticipant.setAttributes({
  paused: "true"  // or "false"
});
This way, your backend will stay in sync and handle the agent’s pause state smoothly. If anything’s unclear or you want to dive deeper, just give me a shout—I’m here to help! Sources: Inside a session | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | Inside a session | LiveKit Docs
f
on_participant_attributes_changed is this the name of function that I need to calll on attribute change and is it constant
t
Hey there! Just a quick heads-up: the function name
on_participant_attributes_changed
isn’t a fixed thing or something LiveKit sets in stone. It’s more like a friendly naming habit folks use for event handler functions. What really matters is the event name you’re tuning into, which is
"participant_attributes_changed"
. Here’s a little example in Python to make it clearer:
Copy code
@ctx.room.on("participant_attributes_changed")
def on_participant_attributes_changed(changed_attrs: dict[str, str], p: rtc.Participant):
    # Your handler code here
Feel free to call your handler function whatever you want, as long as it’s listening for the
"participant_attributes_changed"
event. If anything’s still fuzzy or you want me to explain more, just give me a shout! Sources: livekit-rtc/livekit/rtc/room.py | Inside a session | LiveKit Docs | src/room/events.ts | callback.go | lib/src/events.dart
f
await session.pause() ^^^^^^^^^^^^^ AttributeError: 'AgentSession' object has no attribute 'pause' {
t
Hey there! The error happens because the
AgentSession
object doesn’t have a direct
pause()
method. Instead, the pause feature lives at the
AgentActivity
level, not right on
AgentSession
. To manage what the agent is doing, you can use these handy methods available in `AgentSession`: • `interrupt()`: This stops the current speech generation. • `drain()`: This waits for the current activity to finish up. • `aclose()`: This closes the session. If you’re looking to create a pause-like effect, you might need to handle the session’s state or interrupt the current activity. Feel free to reach out if you want a hand with setting this up—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent.py