From 12104c8d46c0b688e0db21617b23d54f012970ba Mon Sep 17 00:00:00 2001 From: ethanclaw Date: Wed, 11 Mar 2026 14:22:33 +0800 Subject: [PATCH] fix(memory): pass temperature, max_tokens and reasoning_effort to memory consolidation Fix issue #1823: Memory consolidation does not inherit agent temperature and maxTokens configuration. The agent's configured generation parameters were not being passed through to the memory consolidation call, causing it to fall back to default values. This resulted in the consolidation response being truncated before the save_memory tool call was emitted. - Pass temperature, max_tokens, reasoning_effort from AgentLoop to MemoryConsolidator and then to MemoryStore.consolidate() - Forward these parameters to the provider.chat_with_retry() call Fixes #1823 --- nanobot/agent/loop.py | 3 +++ nanobot/agent/memory.py | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 8605a09..edf1e8e 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -114,6 +114,9 @@ class AgentLoop: context_window_tokens=context_window_tokens, build_messages=self.context.build_messages, get_tool_definitions=self.tools.get_definitions, + temperature=self.temperature, + max_tokens=self.max_tokens, + reasoning_effort=self.reasoning_effort, ) self._register_default_tools() diff --git a/nanobot/agent/memory.py b/nanobot/agent/memory.py index cd5f54f..d79887b 100644 --- a/nanobot/agent/memory.py +++ b/nanobot/agent/memory.py @@ -99,6 +99,9 @@ class MemoryStore: messages: list[dict], provider: LLMProvider, model: str, + temperature: float | None = None, + max_tokens: int | None = None, + reasoning_effort: str | None = None, ) -> bool: """Consolidate the provided message chunk into MEMORY.md + HISTORY.md.""" if not messages: @@ -121,6 +124,9 @@ class MemoryStore: ], tools=_SAVE_MEMORY_TOOL, model=model, + temperature=temperature, + max_tokens=max_tokens, + reasoning_effort=reasoning_effort, ) if not response.has_tool_calls: @@ -160,6 +166,9 @@ class MemoryConsolidator: context_window_tokens: int, build_messages: Callable[..., list[dict[str, Any]]], get_tool_definitions: Callable[[], list[dict[str, Any]]], + temperature: float | None = None, + max_tokens: int | None = None, + reasoning_effort: str | None = None, ): self.store = MemoryStore(workspace) self.provider = provider @@ -168,6 +177,9 @@ class MemoryConsolidator: self.context_window_tokens = context_window_tokens self._build_messages = build_messages self._get_tool_definitions = get_tool_definitions + self._temperature = temperature + self._max_tokens = max_tokens + self._reasoning_effort = reasoning_effort self._locks: weakref.WeakValueDictionary[str, asyncio.Lock] = weakref.WeakValueDictionary() def get_lock(self, session_key: str) -> asyncio.Lock: @@ -176,7 +188,14 @@ class MemoryConsolidator: async def consolidate_messages(self, messages: list[dict[str, object]]) -> bool: """Archive a selected message chunk into persistent memory.""" - return await self.store.consolidate(messages, self.provider, self.model) + return await self.store.consolidate( + messages, + self.provider, + self.model, + temperature=self._temperature, + max_tokens=self._max_tokens, + reasoning_effort=self._reasoning_effort, + ) def pick_consolidation_boundary( self,