ChatCLI: Assistant console output lacks preceding newline, breaking external print statements
Feature Type
Nice to have
Feature Description
When using the conversation_item_added event in console mode to print custom output (e.g., Rich panels), assistant messages render incorrectly because they lack a preceding newline, while user messages render correctly.
The Problem
In chat_cli.py, _print_audio_mode() continuously overwrites the current line using \r (carriage return) at 16 FPS to display the audio level meter:
# chat_cli.py lines 505-514
def _print_audio_mode(self) -> None:
# ...
sys.stdout.write(
f"\r[Audio] {self._input_device_name[-20:]} [{self._micro_db:6.2f} dBFS] ..."
)
sys.stdout.flush()
When the conversation_item_added event fires for assistant messages, any external print() or console.print() call ends up on the same line as the audio meter, breaking the output:
[Audio] rophone (Plantronics [-87.05 dBFS] [------------------------------]╭──────────── Assistant ────────────╮
│ Hello, how can I help you today? │
╰───────────────────────────────────╯
However, user messages render correctly because the DEBUG livekit.agents - received user transcript log is printed first, which includes a newline:
2025-12-12 17:16:43,528 - DEBUG livekit.agents - received user transcript {"user_transcript": "Yes.", "language": "en"}
╭─ User ─╮
│ Yes. │
╰────────╯
Reproduction
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
from rich.console import Console
from rich.panel import Panel
console = Console()
role = event.item.role
console.print(Panel(event.item.text_content or "", title=role.capitalize()))
Run with livekit-agents console in audio mode. Assistant panels will have their top border merged with the audio level line.
Suggested Fix
Before emitting conversation_item_added (or other events where user code might print to stdout), the ChatCLI should:
- Print a newline to move to a fresh line, OR
- Clear the current line with
\r+ spaces +\r, OR - Provide a mechanism to pause/resume the audio bar rendering around event emissions
Workarounds / Alternatives
As a workaround, users can manually print a newline before their output:
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
if event.item.role == "assistant":
print() # Force newline before assistant output
console.print(Panel(...))
However, this is not ideal as it requires users to understand the internal rendering behavior of ChatCLI.
Additional Context
Additional Context
- Affects:
livekit-agentsconsole mode (ChatCLI) - File:
livekit/agents/voice/chat_cli.py - Method:
_print_audio_mode()(lines 505-514) - Event:
conversation_item_addedemission timing relative to audio bar rendering