better-sandwich-65834
09/04/2025, 1:04 PMtall-airline-16756
09/04/2025, 1:04 PMtall-airline-16756
09/04/2025, 1:05 PMapi.CreateAgentDispatchRequest metadata field because it's static and only set when the agent dispatch is first created. But no worries! You can use the update_instructions method from the LiveKit SDKs to make dynamic updates on the fly.
Python Implementation:
# Assuming 'agent' is an instance of livekit.agents.voice.Agent
try:
# Update the agent's instructions to a new value
await agent.update_instructions("Your new instructions here.")
except llm.RealtimeError:
# Handle potential errors from the LLM service
logger.exception("failed to update the instructions")
JavaScript/TypeScript Implementation:
// Create the RealtimeModel with initial configuration
const model = new livekit.RealtimeModel({
apiKey: process.env.OPENAI_API_KEY,
instructions: "Your initial instructions here."
});
// Create a realtime session for the conversation
const session = model.session();
// Update the instructions for the active session
await session.updateInstructions("Your new instructions here.");
These methods make it super easy to send real-time updates to the LLM's instructions while your session is active. If you have any questions or want me to walk you through it, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/llm/realtime.py | agents/src/llm/realtime.tsbetter-sandwich-65834
09/04/2025, 1:06 PMtall-airline-16756
09/04/2025, 1:07 PMinstructions property from the Agent class. This handy property gives you the main instructions that are steering the agent’s behavior.
Here’s a quick example in Python:
# Grab the instructions during runtime\ncurrent_instructions = agent.instructions\nprint(f\"Current instructions: {current_instructions}\")
And if you happen to update the instructions on the fly using update_instructions(), no worries—the instructions property will show the latest version right away.
Feel free to ask if you want me to explain anything further or if you need a hand with something else!
Sources: livekit-agents/livekit/agents/voice/agent_activity.pybetter-sandwich-65834
09/04/2025, 1:09 PMtall-airline-16756
09/04/2025, 1:10 PMapi.CreateAgentDispatchRequest, you’ll want to look at the response object you get right after creating a dispatch. The create_dispatch() method gives you an AgentDispatch object that includes handy details like id, agent_name, room, metadata, and state.
Here’s a quick Python example for you:
from livekit import api\n\nasync def create_and_retrieve_dispatch():\n lkapi = api.LiveKitAPI()\n dispatch = await lkapi.agent_dispatch.create_dispatch(\n api.CreateAgentDispatchRequest(\n agent_name=\"test-agent\",\n room=\"my-room\",\n metadata='{\"user_id\": \"12345\"}'\n )\n )\n\n # Now, let’s grab some info from the response\n print(\"Dispatch ID:\", dispatch.id)\n print(\"Agent Name:\", dispatch.agent_name)\n print(\"Room:\", dispatch.room)\n print(\"Metadata:\", dispatch.metadata)\n print(\"Created At:\", dispatch.state.created_at if dispatch.state else None)
If you want to fetch dispatches later on, you can use get_dispatch() or list_dispatch() like this:
# Get a specific dispatch by its ID\ndispatch = await lkapi.agent_dispatch.get_dispatch(dispatch_id=\"disp_abc123\", room_name=\"my-room\")\n\n# Or list all dispatches in a room\ndispatches = await lkapi.agent_dispatch.list_dispatch(room_name=\"my-room\")\nfor d in dispatches:\n print(\"Dispatch:\", d.agent_name, d.id)
If you’d like me to walk you through other SDKs or need any more help, just give me a shout!
Sources: Agent dispatch | LiveKit Docs | examples/agent_dispatch.py | packages/livekit-server-sdk/src/AgentDispatchClient.ts | agent_dispatch_client.go | lib/livekit/agent_dispatch_service_client.rb