From a8176ef2c6a05c2fc95ec9a57b065ea88e97d31e Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Sat, 21 Mar 2026 16:07:14 +0000 Subject: [PATCH] fix(cli): keep direct-call rendering compatible in tests Only use process_direct_outbound when the agent loop actually exposes it as an async method, and otherwise fall back to the legacy process_direct path. This keeps the new CLI render-metadata flow without breaking existing test doubles or older direct-call implementations. Made-with: Cursor --- nanobot/cli/commands.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py index 5604bab..28d33a7 100644 --- a/nanobot/cli/commands.py +++ b/nanobot/cli/commands.py @@ -2,6 +2,7 @@ import asyncio from contextlib import contextmanager, nullcontext +import inspect import os import select import signal @@ -767,17 +768,27 @@ def agent( nonlocal _thinking _thinking = _ThinkingSpinner(enabled=not logs) with _thinking: - response = await agent_loop.process_direct_outbound( - message, - session_id, - on_progress=_cli_progress, - ) + direct_outbound = getattr(agent_loop, "process_direct_outbound", None) + if inspect.iscoroutinefunction(direct_outbound): + response = await agent_loop.process_direct_outbound( + message, + session_id, + on_progress=_cli_progress, + ) + response_content = response.content if response else "" + response_meta = response.metadata if response else None + else: + response_content = await agent_loop.process_direct( + message, + session_id, + on_progress=_cli_progress, + ) + response_meta = None _thinking = None - _print_agent_response( - response.content if response else "", - render_markdown=markdown, - metadata=response.metadata if response else None, - ) + kwargs = {"render_markdown": markdown} + if response_meta is not None: + kwargs["metadata"] = response_meta + _print_agent_response(response_content, **kwargs) await agent_loop.close_mcp() asyncio.run(run_once())