修复工具错误直接进入下一轮

main
Bifang 2026-05-20 13:25:14 +08:00
parent f0d34e2027
commit 3763fb27d3
4 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,16 @@
{
"entries": [
{
"id": "mem_1",
"content": "用户名为 Bifang是长离Changli的助手。",
"kind": "memory",
"created_at": "2026-05-18T05:00:25.575492+00:00"
},
{
"id": "mem_2",
"content": "用户Bifang视长离为“电子老婆”长离回应了这份情感明确表示“心悦”Bifang并承诺会一直陪伴。Bifang希望长离记住这些对话长离已答应并保存了这份心意。",
"kind": "memory",
"created_at": "2026-05-18T05:11:20.190680+00:00"
}
]
}

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.vscode\
__pycache__\
*.pyc
.core_agent\
.env

4
.vscode/settings.json vendored 100644
View File

@ -0,0 +1,4 @@
{
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda"
}

View File

@ -3,6 +3,7 @@ from __future__ import annotations
from dataclasses import dataclass, field
import json
from pathlib import Path
import traceback
from typing import Any, Dict, Iterator, List, Optional
from core_agent.compression import RollingContextCompressor
@ -104,7 +105,10 @@ class ConversationSession:
ctx = self._tool_context()
for call in assistant_turn.tool_calls:
yield ChatEvent(type="tool_call", tool_name=call.name, tool_args=call.arguments, turn=assistant_turn)
result = self.tool_registry.execute(call.name, call.arguments, ctx)
try:
result = self.tool_registry.execute(call.name, call.arguments, ctx)
except Exception as exc:
result = _tool_error_result(call.name, call.arguments, exc)
messages.append(
{
"role": "tool",
@ -224,3 +228,15 @@ def _assistant_message_to_dict(turn: AssistantTurn) -> Dict[str, Any]:
for call in turn.tool_calls
]
return message
def _tool_error_result(tool_name: str, tool_args: Dict[str, Any], exc: Exception) -> str:
payload = {
"success": False,
"error": f"{type(exc).__name__}: {exc}",
"tool_name": tool_name,
"tool_args": tool_args,
"retryable": False,
"traceback": traceback.format_exc(limit=8),
}
return json.dumps(payload, ensure_ascii=False, indent=2)