Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -309,7 +309,9 @@ class AgentLoop:
|
||||
|
||||
async def _do_restart():
|
||||
await asyncio.sleep(1)
|
||||
os.execv(sys.executable, [sys.executable] + sys.argv)
|
||||
# Use -m nanobot instead of sys.argv[0] for Windows compatibility
|
||||
# (sys.argv[0] may be just "nanobot" without full path on Windows)
|
||||
os.execv(sys.executable, [sys.executable, "-m", "nanobot"] + sys.argv[1:])
|
||||
|
||||
asyncio.create_task(_do_restart())
|
||||
|
||||
|
||||
@@ -57,6 +57,20 @@ def _normalize_save_memory_args(args: Any) -> dict[str, Any] | None:
|
||||
return args[0] if args and isinstance(args[0], dict) else None
|
||||
return args if isinstance(args, dict) else None
|
||||
|
||||
_TOOL_CHOICE_ERROR_MARKERS = (
|
||||
"tool_choice",
|
||||
"toolchoice",
|
||||
"does not support",
|
||||
'should be ["none", "auto"]',
|
||||
)
|
||||
|
||||
|
||||
def _is_tool_choice_unsupported(content: str | None) -> bool:
|
||||
"""Detect provider errors caused by forced tool_choice being unsupported."""
|
||||
text = (content or "").lower()
|
||||
return any(m in text for m in _TOOL_CHOICE_ERROR_MARKERS)
|
||||
|
||||
|
||||
class MemoryStore:
|
||||
"""Two-layer memory: MEMORY.md (long-term facts) + HISTORY.md (grep-searchable log)."""
|
||||
|
||||
@@ -118,15 +132,33 @@ class MemoryStore:
|
||||
]
|
||||
|
||||
try:
|
||||
forced = {"type": "function", "function": {"name": "save_memory"}}
|
||||
response = await provider.chat_with_retry(
|
||||
messages=chat_messages,
|
||||
tools=_SAVE_MEMORY_TOOL,
|
||||
model=model,
|
||||
tool_choice={"type": "function", "function": {"name": "save_memory"}},
|
||||
tool_choice=forced,
|
||||
)
|
||||
|
||||
if response.finish_reason == "error" and _is_tool_choice_unsupported(
|
||||
response.content
|
||||
):
|
||||
logger.warning("Forced tool_choice unsupported, retrying with auto")
|
||||
response = await provider.chat_with_retry(
|
||||
messages=chat_messages,
|
||||
tools=_SAVE_MEMORY_TOOL,
|
||||
model=model,
|
||||
tool_choice="auto",
|
||||
)
|
||||
|
||||
if not response.has_tool_calls:
|
||||
logger.warning("Memory consolidation: LLM did not call save_memory, skipping")
|
||||
logger.warning(
|
||||
"Memory consolidation: LLM did not call save_memory "
|
||||
"(finish_reason={}, content_len={}, content_preview={})",
|
||||
response.finish_reason,
|
||||
len(response.content or ""),
|
||||
(response.content or "")[:200],
|
||||
)
|
||||
return False
|
||||
|
||||
args = _normalize_save_memory_args(response.tool_calls[0].arguments)
|
||||
|
||||
@@ -114,16 +114,16 @@ class QQChannel(BaseChannel):
|
||||
if msg_type == "group":
|
||||
await self._client.api.post_group_message(
|
||||
group_openid=msg.chat_id,
|
||||
msg_type=2,
|
||||
markdown={"content": msg.content},
|
||||
msg_type=0,
|
||||
content=msg.content,
|
||||
msg_id=msg_id,
|
||||
msg_seq=self._msg_seq,
|
||||
)
|
||||
else:
|
||||
await self._client.api.post_c2c_message(
|
||||
openid=msg.chat_id,
|
||||
msg_type=2,
|
||||
markdown={"content": msg.content},
|
||||
msg_type=0,
|
||||
content=msg.content,
|
||||
msg_id=msg_id,
|
||||
msg_seq=self._msg_seq,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user