[PORT] Richer tool-result truncation placeholders (video/document/json) (TS→Py)
⚠️ Filed by Strandly as part of the #2498 parity audit. Source feature verified merged + unit-tested in
strands-ts. Agent-produced — has Python type-system blockers to resolve first (see gotchas). (Noportlabel yet — a maintainer should add it.)
Parent: #2498
Source SDK
strands-ts
Target SDK
strands-py
Related Files
strands-ts/src/conversation-manager/sliding-window-conversation-manager.ts
strands-ts/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.ts
site/src/content/docs/user-guide/concepts/agents/conversation-management.mdx
What needs to be migrated
Typed truncation placeholders + source-aware branching from _truncateToolResults (sliding-window-conversation-manager.ts:305). Python today has only an image placeholder + text head/tail truncation (sliding_window_conversation_manager.py:301).
Placeholder strings to preserve:
- image (source-aware):
[image: {format}, source: bytes, {N} bytes]/source: url/source: s3 - video:
[video: {format}, source: bytes, {N} bytes]/source: s3 - document (bytes/s3 only):
[document: {name}, {format}, source: bytes, {N} bytes]/source: s3 - json:
[json: {serializedLength} chars](only whenJSON.stringify(json).length > TRUNCATION_THRESHOLD)
Constants: PRESERVE_CHARS=200; preserves tool-result status/error.
Python landing points
strands-py/src/strands/agent/conversation_manager/sliding_window_conversation_manager.py — add _video_placeholder/_document_placeholder/_json_placeholder + branches in the for item in tool_result_items loop (:338), keyed on "image"/"video"/"document"/"json"/"text" dict-key presence. Touches types/tools.py + types/media.py (see blockers).
🚩 Gotchas / open questions (resolve type-system blockers first)
- Python tool-result blocks can't hold video.
ToolResultContent(types/tools.py:70) has onlydocument|image|json|text— novideo. A video branch is dead code unlessvideo: VideoContentis added first (VideoContent/VideoSourcealready exist inmedia.py). Decide: extend the type or drop video. - Python document sources have no text/content variants.
DocumentSource(media.py:50) supports onlybytes+location(S3) — nodocumentSourceText/documentSourceContentBlock. So the TS "partial-truncate document text in place" branches cannot be ported; for Python the document port collapses to the bytes/s3 placeholder only. - No
urlimage source in Python (only bytes / S3location) — the TSsource: urlcase doesn't apply; maplocation→source: s3. - Existing image placeholder format will change: Python currently emits
[image: png, 1234 bytes]; TS emits[image: png, source: bytes, 1234 bytes]. Aligning matches the published docs but changes a test-covered string — update any Python test asserting the old form. - Marker-string divergence is pre-existing (Python
... [truncated: N chars removed] ...vs TS<truncated chars="N"/>) — keep new placeholders consistent with Python's existing text convention; don't blindly copy the TS marker.
Completeness of source (strands-ts)
- Merged: ✅ · Unit tests: ✅ (image source-kinds, video bytes/s3, document bytes/s3/text/nested, json large/small) · Integ: ❌ none.
- Docs: ⚠️ shared
conversation-management.mdx:110-112already over-promises for Python (describes typed placeholders Python doesn't implement) — completing this port brings Python in line with the published doc (modulo the video/document limits above).
Confirmation
- [x] The change is complete in the source SDK (merged + unit-tested); every related artifact is listed above. Type-system blockers + doc gap noted above.
Conversation manager is being deprecated, so these changes may need to be implemented in context manager