Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(agent): log mid-turn injected messages (#5878)
chengyongrue68afef6707a
diff --git a/nanobot/agent/runner.py b/nanobot/agent/runner.pyindex 8a8f900af..7ce8a815a 100644--- a/nanobot/agent/runner.py+++ b/nanobot/agent/runner.py@@ -41,6 +41,7 @@ from nanobot.providers.base import (ProviderConversationState,)from nanobot.providers.conversation_state import ProviderConversationStateController+from nanobot.session.history_visibility import is_hidden_history_messagefrom nanobot.session.summary import SessionSummaryCheckpointfrom nanobot.utils.helpers import (build_assistant_message,@@ -204,9 +205,17 @@ class AgentRunner:)self._append_injected_messages(messages, injections)if real_injection:+ preview = "[content hidden]"+ if tool_log_content_allowed():+ preview = "\n\n".join(+ message["content"] for message in injections+ if isinstance(message.get("content"), str)+ and not is_hidden_history_message(message)+ )+ preview = preview[:80] + "..." if len(preview) > 80 else previewlogger.info(- "Injected {} follow-up message(s) {} (snapshot {})",- len(injections), phase, injection_cycles,+ "Injected {} follow-up message(s) {} (snapshot {}): {}",+ len(injections), phase, injection_cycles, preview,)else:logger.info("Injected caller-requested continuation {}", phase)diff --git a/tests/agent/test_runner_injections.py b/tests/agent/test_runner_injections.pyindex 395965a09..520e7b9a6 100644--- a/tests/agent/test_runner_injections.py+++ b/tests/agent/test_runner_injections.py@@ -1514,11 +1514,21 @@ async def test_session_inbox_is_installed_before_worker_start(tmp_path):@pytest.mark.asyncio-async def test_busy_session_burst_reaches_next_model_call_as_one_ordered_batch(tmp_path):[email protected]("log_content", [True, False])+async def test_busy_session_burst_reaches_next_model_call_as_one_ordered_batch(+ tmp_path, request, log_content,+):"""Messages accumulated during a model call share its next request snapshot."""+ from loguru import logger+from nanobot.agent.loop import AgentLoopfrom nanobot.bus.events import InboundMessagefrom nanobot.bus.queue import MessageBus+ from nanobot.session.manager import SessionPolicy++ records = []+ sink = logger.add(lambda message: records.append(message.record))+ request.addfinalizer(lambda: logger.remove(sink))provider = MagicMock()provider.get_default_model.return_value = "test-model"@@ -1544,6 +1554,7 @@ async def test_busy_session_burst_reaches_next_model_call_as_one_ordered_batch(tmodel="test-model",)loop.tools.get_definitions = MagicMock(return_value=[])+ loop.sessions.get_or_create("cli:c").policy = SessionPolicy(log_content=log_content)followups = [f"follow-up-{index:02}" for index in range(12)]run_task = asyncio.create_task(loop.run())@@ -1585,6 +1596,17 @@ async def test_busy_session_burst_reaches_next_model_call_as_one_ordered_batch(tassert positions == sorted(positions)assert loop.bus.inbound_size == 0+ injections = [r for r in records if r["message"].startswith("Injected ")]+ assert len(injections) == 1+ record = injections[0]+ preview = "\n\n".join(followups)[:80] + "..." if log_content else "[content hidden]"+ assert record["message"] == (+ f"Injected {len(followups)} follow-up message(s) after final response (snapshot 1): {preview}"+ )+ assert record["level"].name == "INFO"+ assert record["extra"]["session_key"] == "cli:c"+ assert record["extra"]["turn_id"]+@pytest.mark.asyncioasync def test_session_worker_processes_leftovers_without_republishing(tmp_path):