cold-night-84844
07/23/2025, 8:14 AMtall-airline-16756
07/23/2025, 8:14 AMtall-airline-16756
07/23/2025, 8:18 AMcold-night-84844
07/23/2025, 8:34 AMtall-airline-16756
07/23/2025, 8:35 AMListAgents API or this friendly CLI command:
lk agent list
- This will give you a complete rundown of all your awesome agents. 😊
• Delete an agent:
- Sometimes you need to say goodbye to an agent. No worries! Use the DeleteAgent API or this simple CLI command:
lk agent delete --id AGENT_ID
- Don't worry, you'll get a chance to double-check before anything gets deleted. We've got your back! 👍
• Modify an agent:
- Need to tweak something? We make it easy! Use the UpdateAgent API or this handy CLI command:
lk agent update --id AGENT_ID [--secrets KEY=VALUE]
- You can update agent metadata, secrets, and regions - whatever you need. 🛠️
The best part? You can do all of these with the Go SDK, the lk CLI tool, or directly through the CloudAgent service APIs. Just remember, you'll need admin-level authentication to make these changes. We're here to help make managing your agents a breeze! 🚀
Sources: agent_client.go | cmd/lk/dispatch.go | livekit/livekit_cloud_agent.pb.gocold-night-84844
07/23/2025, 11:02 AMtall-airline-16756
07/23/2025, 11:03 AMclass MyAgent(Agent):
def __init__(self, instructions):
super().__init__(instructions=instructions, ...)
# Usage
agent = MyAgent(instructions="Your custom instructions here")
- Pro tip: You can even use context variables to make your instructions super dynamic.
• Passing and storing metadata for tracking customers:
- Think of this like creating a digital profile for each customer. Use the userdata attribute to store custom info you might want to remember.
from dataclasses import dataclass
@dataclass
class MySessionInfo:
user_name: str | None = None
customer_id: str | None = None
session = AgentSession[MySessionInfo](userdata=MySessionInfo(...))
- This is super handy because the metadata sticks around during the whole session, so you can use it whenever you need.
• Passing initial data via job metadata:
- When you're sending out an agent, you can include some extra info right in the job. Then grab it in your entrypoint function.
import json
async def entrypoint(ctx: JobContext):
metadata = json.loads(ctx.job.metadata)
user_id = metadata["user_id"]
# Use this data to initialize your agent or session
With these methods, you'll be creating super adaptable agents that remember and care about each customer's unique needs. Pretty cool, right?
Sources: Job lifecycle | LiveKit Docs | complex-agents/personal_shopper/README.md | Workflows | LiveKit Docscold-night-84844
07/23/2025, 11:09 AMtall-airline-16756
07/23/2025, 11:11 AMpython agent.py dev command in a way that makes your life easier. When you're developing, this command is pretty straightforward, but you might be wondering how to pass custom data to your agent. No worries—I've got you covered!
• Passing metadata or instructions is super simple:
- When you're dispatching your agent (through the API or CLI), you can include your custom data as a JSON string in the metadata field. It's like giving your agent a little note with extra details.
lk dispatch create \
--new-room \
--agent-name your-agent \
--metadata '{"user_id": "12345", "instructions": "Custom instructions"}'
- Inside your agent's entrypoint function, you can easily grab this metadata using ctx.job.metadata and parse it. Think of it like unpacking a care package!
import json
async def entrypoint(ctx: JobContext):
metadata = json.loads(ctx.job.metadata)
user_id = metadata["user_id"]
instructions = metadata["instructions"]
# Now you can use these values to make your agent super personalized
This approach is like giving your agent a Swiss Army knife—it can adapt to different users and scenarios, making your code flexible and ready for anything. Pretty cool, right?
Sources: External data and RAG | LiveKit Docs | Agent dispatch | LiveKit Docs | Workflows | LiveKit Docs | Job lifecycle | LiveKit Docs | README.mdcold-night-84844
07/23/2025, 11:24 AMpython3 agent.py console --metadata='{"user_id": "12345", "instructions": "Custom instructions"}'
I got an error message
Usage: agent.py console [OPTIONS]
Try 'agent.py console --help' for help.
Error: No such option: --metadatatall-airline-16756
07/23/2025, 11:26 AMconsole command in agent.py. No worries – the --metadata option isn't supported here, which is why you're seeing that "No such option" error. Think of the console command like a quick, no-frills testing tool for local development.
Let me walk you through some friendly ways to test your agent with custom metadata:
• Dispatch the agent with metadata using the API:
import asyncio
from livekit import api
async def create_dispatch():
lkapi = api.LiveKitAPI()
await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name="your-agent-name",
room="test-room",
metadata='{"user_id": "12345", "instructions": "Custom instructions"}'
)
)
await lkapi.aclose()
• Modify your agent code for console testing:
- In your entrypoint function, check if ctx.job.metadata exists. If not, provide default metadata for local testing.
async def entrypoint(ctx: JobContext):
import json
if ctx.job.metadata:
metadata = json.loads(ctx.job.metadata)
else:
metadata = {"user_id": "console_test", "instructions": "Default instructions"}
# Use metadata as needed
Pro tip: For the most comprehensive metadata testing, I recommend using the agent dispatch API or CLI in a real LiveKit server environment. The console command is perfect for those quick, simple local tests. Hope this helps you out!
Sources: livekit-agents/livekit/agents/cli/cli.py | examples/agent_dispatch.py | Job lifecycle | LiveKit Docscold-night-84844
07/23/2025, 11:38 AMtall-airline-16756
07/23/2025, 11:39 AM/start_call API. We'll use the create_dispatch API to spin up a new agent for each request. I've got a friendly Python example using FastAPI that'll make this crystal clear:
from fastapi import FastAPI, Request, HTTPException
from livekit import api
import asyncio
import json
import uuid
app = FastAPI()
AGENT_NAME = "call-agent"
@app.post("/start_call")
async def start_call(request: Request):
data = await request.json()
user_id = data.get("user_id")
if not user_id:
raise HTTPException(status_code=400, detail="user_id is required")
room_name = f"call-{user_id}-{uuid.uuid4().hex[:8]}"
metadata = json.dumps({
"user_id": user_id,
"instructions": data.get("instructions", "Default instructions")
})
lkapi = api.LiveKitAPI()
try:
dispatch = await lkapi.agent_dispatch.create_dispatch(
api.CreateAgentDispatchRequest(
agent_name=AGENT_NAME,
room=room_name,
metadata=metadata
)
)
return {"status": "success", "dispatch_id": dispatch.id, "room": room_name}
finally:
await lkapi.aclose()
• Every time /start_call is hit, we create a brand new agent with a unique room and personalized metadata just for that user.
• Pro tip: Set agent_name in your agent worker's WorkerOptions to make dispatching a breeze.
• In your agent's entrypoint, you can easily grab the metadata via ctx.job.metadata and tailor the agent experience for each awesome user.
Pretty neat, right? This approach lets you effortlessly scale and manage multiple agent sessions, each one kicked off by a user's API call. It's like having a team of friendly assistants ready to jump into action!
Sources: Agent dispatch | LiveKit Docs | telephony/make_call/make_call.pycold-night-84844
07/23/2025, 11:43 AMtall-airline-16756
07/23/2025, 11:45 AMagent.py file that lets you create a super personalized AI assistant. It uses explicit dispatch and customizes the agent for each user using ctx.job.metadata – how cool is that?
import json
from livekit.agents import JobContext, WorkerOptions, cli
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import openai, deepgram, silero
def build_instructions(user_name, instructions):
return f"You are a helpful AI assistant for {user_name}. {instructions}"
class CustomAgent(Agent):
def __init__(self, instructions):
super().__init__(
instructions=instructions,
stt=deepgram.STT(),
llm=openai.LLM(model="gpt-4o"),
tts=openai.TTS(),
vad=silero.VAD.load()
)
async def entrypoint(ctx: JobContext):
await ctx.connect()
try:
metadata = json.loads(ctx.job.metadata)
user_name = metadata.get("user_name", "Guest")
instructions = metadata.get("instructions", "How can I help you today?")
except Exception:
user_name = "Guest"
instructions = "How can I help you today?"
agent = CustomAgent(build_instructions(user_name, instructions))
session = AgentSession()
await session.start(agent=agent, room=ctx.room)
if __name__ == "__main__":
cli.run_app(
WorkerOptions(
entrypoint_fnc=entrypoint,
agent_name="call-agent", # Must match the agent_name used in your dispatch
)
)
• This friendly agent will kick off with create_dispatch and use the metadata you send (like user_name and instructions) to create a totally personalized experience for each user.
• Pro tip: Make sure to set agent_name in WorkerOptions to match the name you use in your dispatch API call.cold-night-84844
07/23/2025, 11:56 AMtall-airline-16756
07/23/2025, 11:57 AMcold-night-84844
07/24/2025, 3:51 AM