revert nanobot

This commit is contained in:
qixinbo
2026-03-17 16:13:33 +08:00
parent 600aa495c3
commit a688e6e25e
2 changed files with 19 additions and 10 deletions
+19 -1
View File
@@ -2,7 +2,7 @@ import asyncio
import sys import sys
import os import os
from pathlib import Path from pathlib import Path
from typing import List, Callable, Awaitable from typing import List, Callable, Awaitable, Any
# Add project root to sys.path to allow importing nanobot # Add project root to sys.path to allow importing nanobot
# Assuming backend/app/core/nanobot.py -> backend/app/core -> backend/app -> backend -> root # Assuming backend/app/core/nanobot.py -> backend/app/core -> backend/app -> backend -> root
@@ -255,6 +255,12 @@ class NanobotIntegration:
# Append user message after skills # Append user message after skills
full_message = f"{skill_context}\n\n{message}" full_message = f"{skill_context}\n\n{message}"
session = agent_to_use.sessions.get_or_create(session_id)
normalized_messages = self._normalize_session_messages(session.messages)
if len(normalized_messages) != len(session.messages):
session.messages = normalized_messages
agent_to_use.sessions.save(session)
response = await agent_to_use.process_direct( response = await agent_to_use.process_direct(
full_message, full_message,
session_key=session_id, session_key=session_id,
@@ -264,4 +270,16 @@ class NanobotIntegration:
) )
return response return response
def _normalize_session_messages(self, messages: List[Any]) -> List[dict[str, Any]]:
normalized: List[dict[str, Any]] = []
stack: List[Any] = list(messages)
while stack:
current = stack.pop(0)
if isinstance(current, dict):
normalized.append(current)
continue
if isinstance(current, list):
stack = list(current) + stack
return normalized
nanobot_service = NanobotIntegration() nanobot_service = NanobotIntegration()
-9
View File
@@ -95,15 +95,6 @@ class LLMProvider(ABC):
"""Keep only provider-safe message keys and normalize assistant content.""" """Keep only provider-safe message keys and normalize assistant content."""
sanitized = [] sanitized = []
for msg in messages: for msg in messages:
if isinstance(msg, list):
for nested in msg:
if not isinstance(nested, dict):
continue
clean = {k: v for k, v in nested.items() if k in allowed_keys}
if clean.get("role") == "assistant" and "content" not in clean:
clean["content"] = None
sanitized.append(clean)
continue
if not isinstance(msg, dict): if not isinstance(msg, dict):
continue continue
clean = {k: v for k, v in msg.items() if k in allowed_keys} clean = {k: v for k, v in msg.items() if k in allowed_keys}