Skip to content

Commit 2fbbd13

Browse files
authored
Update session.py
1 parent 5d33baa commit 2fbbd13

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎python_agent_harness/session.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
from typing import TYPE_CHECKING, Any
1717

1818
from . import config
19+
from .attachments import image_placeholder
1920
from .client import Client, LLMClient
2021
from .diffrender import sanitize_for_display
2122
from .mcp.config import MCPConfig
2223
from .mcp.manager import MCPManager
23-
from .models import AgentMode
24+
from .models import AgentMode, ImagePart
2425
from .persistence import SessionPersistence, escape_role_headers
2526
from .planmode import PlanMode
2627
from .prompts import RESERVED_AGENT_NAME, _tool_excluded, discover_agents, index_skills
@@ -650,6 +651,18 @@ def _conversation_text(self, messages: list) -> str:
650651
# escaped: a body line that looks like a `**role**: ` block
651652
# header would otherwise split the message on restore
652653
body = escape_role_headers(m.text())
654+
# Mark messages that contained image attachments: the image
655+
# data itself cannot be persisted in the markdown format, so
656+
# a placeholder notes what was attached. The original file
657+
# path (when the image came from a path) is recorded so a
658+
# restored session can re-attach it. On restore, the
659+
# placeholder text survives so the user/agent knows an image
660+
# was present but is no longer available.
661+
if isinstance(m.content, list):
662+
image_count = sum(1 for p in m.content if isinstance(p, ImagePart))
663+
if image_count:
664+
paths = [p.path for p in m.content if isinstance(p, ImagePart) and p.path]
665+
body = f"{image_placeholder(image_count, paths)}\n{body}"
653666
if m.role == "assistant" and m.tool_calls:
654667
calls = ", ".join(tc.name for tc in m.tool_calls)
655668
body = (body + f"\n[tool calls: {calls}]").strip()

0 commit comments

Comments
 (0)