bulky-addition-19729
02/16/2026, 3:37 AMtall-airline-16756
02/16/2026, 3:37 AMtall-airline-16756
02/16/2026, 3:37 AMlk agent list).
What you can do next
• Use the CLI: continue using lk agent list for an official way to enumerate deployed agents.
• If you need a programmatic approach now: would you be able to run the CLI from Python and parse its output as a temporary workaround? If so, I can show a small example of invoking lk agent list from Python and parsing JSON/text output.
• If you want a native API/SDK method: I can help you draft a concise feature request describing your use case (e.g., list agents programmatically from Python to automate monitoring or deployment workflows).
Which option would you prefer — a Python example that calls the CLI, or help preparing a feature request for native SDK support?
Sources: Examples | livekit/livekit_composite | DeepWiki | Python SDKs | livekit/livekit_composite | DeepWiki | Agents (Python) | livekit/livekit_composite | DeepWikibulky-addition-19729
02/16/2026, 3:38 AMtall-airline-16756
02/16/2026, 3:38 AMlk agent list) and parses its output. I’ll include two variants: one that expects JSON output (preferred) and one that parses plain text output if JSON isn't available.
Before you run this:
• Ensure the lk CLI is installed and authenticated in the environment where your Python code will run.
• Confirm lk agent list supports a JSON output flag (if it does, prefer that) — if not, use the text-parsing example below.
1) Preferred: run CLI with JSON output (if supported)
• This runs the CLI asking for JSON output and parses it into Python objects.
import subprocess
import json
def list_agents_json():
# If the `lk` CLI supports a JSON flag like `--output json` or `-o json`, use it.
# Replace the flag below with the correct one if different.
cmd = ["lk", "agent", "list", "--output", "json"]
try:
completed = subprocess.run(cmd, capture_output=True, text=True, check=True)
data = json.loads(completed.stdout)
# `data` will be a dict/list depending on CLI output structure.
return data
except subprocess.CalledProcessError as e:
print("CLI returned non-zero exit:", e.returncode)
print("stderr:", e.stderr)
raise
except json.JSONDecodeError:
print("Failed to parse JSON output:")
print(completed.stdout)
raise
if __name__ == "__main__":
agents = list_agents_json()
print("Agents:", json.dumps(agents, indent=2))
2) Fallback: parse plain-text CLI output
• Use this if the CLI only returns human-readable text. Adjust parsing to match the exact text format returned by lk agent list.
import subprocess
def list_agents_text():
cmd = ["lk", "agent", "list"]
completed = subprocess.run(cmd, capture_output=True, text=True, check=True)
out = completed.stdout.strip().splitlines()
agents = []
# Example parsing strategy:
# - If the CLI prints a header row and columns, skip the header and split columns.
# - If it prints one agent per line, parse each line accordingly.
# Adjust the logic below to match actual CLI formatting.
# Example: header like "NAME STATUS VERSION"
if not out:
return agents
# detect and skip header if present
header_idx = 0
if any(h.lower().startswith("name") or "status" in h.lower() for h in out[0].split()):
header_idx = 1
for line in out[header_idx:]:
# simple split by whitespace (may need more robust parsing)
parts = line.split()
if not parts:
continue
# Example mapping; update indices to match real output
agent = {
"name": parts[0],
"status": parts[1] if len(parts) > 1 else None,
"version": parts[2] if len(parts) > 2 else None,
}
agents.append(agent)
return agents
if __name__ == "__main__":
agents = list_agents_text()
for a in agents:
print(a)
Notes and tips
• Prefer the JSON output option if the CLI supports it; it's more reliable than parsing human-readable text.
• If running this in production, handle errors and timeouts, and consider using subprocess.run(..., timeout=30).
• If you need help adapting the text parser to the exact lk agent list output, paste a sanitized example of the CLI output and I’ll tailor the parsing logic.