Merge PR #1191: fix base64 images stored in session history causing context overflow
This commit is contained in:
@@ -469,6 +469,14 @@ class AgentLoop:
|
|||||||
content = entry["content"]
|
content = entry["content"]
|
||||||
if len(content) > self._TOOL_RESULT_MAX_CHARS:
|
if len(content) > self._TOOL_RESULT_MAX_CHARS:
|
||||||
entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)"
|
entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)"
|
||||||
|
if entry.get("role") == "user" and isinstance(entry.get("content"), list):
|
||||||
|
entry["content"] = [
|
||||||
|
{"type": "text", "text": "[image]"} if (
|
||||||
|
c.get("type") == "image_url"
|
||||||
|
and c.get("image_url", {}).get("url", "").startswith("data:image/")
|
||||||
|
) else c
|
||||||
|
for c in entry["content"]
|
||||||
|
]
|
||||||
entry.setdefault("timestamp", datetime.now().isoformat())
|
entry.setdefault("timestamp", datetime.now().isoformat())
|
||||||
session.messages.append(entry)
|
session.messages.append(entry)
|
||||||
session.updated_at = datetime.now()
|
session.updated_at = datetime.now()
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def ensure_dir(path: Path) -> Path:
|
def ensure_dir(path: Path) -> Path:
|
||||||
"""Ensure a directory exists, creating it if necessary."""
|
"""Ensure a directory exists, creating it if necessary."""
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user