Repository navigation
Prompt reduction - #270
Prompt reduction#270jgindin wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes LLM chat history management and token usage by introducing failed/cancelled turn context exclusion, compacting JSON serialization for schemas and history, and dynamically injecting multimodal guidelines into system prompts when image attachments are present. It also adds robust unit tests to verify these behaviors. The review feedback highlights a potential runtime TypeError in ChatCleaner.isUserLayoutSnapshot if msg.content is not a string, and suggests adding a defensive type guard before calling .trim().
⚡ A2UI Composer PR PreviewYour automated preview is successfully live (commit
|
Browser Verification Evidence:
|
| Scenario | main Request Bytes |
prompt-reduction Request Bytes |
main contents Turns |
prompt-reduction contents Turns |
prompt-reduction Multimodal Guidelines Included? |
|---|---|---|---|---|---|
| Prompt 1 (Text-Only Form & Action) | 144,726 B | 52,590 B (-63.7%) | 1 (formatted snapshot) | 1 (compact snapshot) | false |
| Prompt 2 (Follow-Up Incremental Edit) | 150,478 B | 54,319 B (-63.9%) | 3 (formatted model turn + duplicate snapshot) | 3 (compact model turn, no duplicate snapshot) | false |
| Prompt 3 (Text-Only Dynamic List) | 158,876 B | 56,802 B (-64.2%) | 5 | 5 | false |
Prompt 4 (Include screenshot ON) |
167,123 B | 70,048 B (-58.1%) | 7 (with 3,436 B PNG) |
7 (with 3,436 B PNG) |
true |
Prompt 5 (mockup.png Uploaded) |
150,197 B | 66,339 B (-55.8%) | 1 (with 5,464 B PNG) |
1 (with 5,464 B PNG) |
true |
| Prompt 6a (503 Error + Text-Only Retry) | 150,180 B | 52,449 B (-65.1%) | 1 (leaks failed user text + 5,464 B PNG) |
1 (clean retry turn, 0 B PNG) |
false |
| Prompt 6b (Stopped Stream + Text-Only Retry) | 150,273 B | 52,449 B (-65.1%) | 3 (leaks stopped turn + 5,464 B PNG) |
1 (clean retry turn, 0 B PNG) |
false |
ba89dbf to
aebfe38
Compare
suyangw-g
left a comment
There was a problem hiding this comment.
Reviewed commit aebfe382 across all 14 modified files. The prompt compaction, catalog $defs pruning, compact snapshot serialization, and failed/cancelled turn context exclusion are well-structured and backed by thorough unit tests. Left 3 inline comments on user snapshot classification in ChatPanelBase, previewUrl MIME header construction in FileIngestionService, and promptId fallback/test coverage in ChatCoordinator, plus 1 minor test assertion nit in chat-panel.spec.ts.
Add memoized text-only and multimodal system prompt signals behind
buildSystemPrompt({includeMultimodalGuidelines}) in
ChatPromptFactoryService. Include multimodal guidelines in
ChatCoordinator and ChatPanelBase only when active context or staged
inputs contain an image or screenshot, and infer missing file MIME
types in FileIngestionService via a2a-attachments helpers.
Serialize COMMON_TYPES_SCHEMA and the active catalog with compact JSON.stringify instead of pretty-printed formatJson. Prune unreferenced $defs entries from the catalog before prompt injection while preserving transitively referenced definitions and without mutating input objects.
Replace the Simple Example and verbose vacation_booking Complex Form Example in ChatPromptFactoryService with a compact form and action example while retaining the dynamic list template example. Document optional updateDataModel.path updates and clarify root vs. relative template paths in Data Binding.
Keep activeDraft() and Monaco editor text formatted via formatJson() while compacting sanitized layout snapshots and model responses written to chatHistory via JSON.stringify(). Add ChatCleaner isUserLayoutSnapshot(), stamp isSnapshot on synced layout messages, track LLM-committed layouts in lastSynchronizedLayout, and compute componentCount for user snapshots in ChatPanelBase.
Filter out USER prompt messages and attachments paired with failed (ERROR or parseError) or cancelled (isCancelled) MODEL outcomes in ChatCoordinator.getFullMessageContext() and systemPrompt while keeping them in chatHistory for UI rendering. Preserve earlier succeeded turns when retries reuse promptId, deduplicate adjacent layout snapshots, and correlate MODEL placeholders by promptId.
Stamp isSnapshot: false on submitted USER prompt messages in ChatCoordinator.submitPrompt and gate USER snapshot inference on ChatCleaner.isUserLayoutSnapshot in ChatPanelBase.visibleChatHistory and getBubbleClass. Construct FileIngestionService previewUrl from the inferred MIME type and base64 payload, restrict the findTargetModelMessageIndex fallback to untagged MODEL turns, and expand unit test coverage.
79b56b3 to
59d3a0f
Compare
Description
Reduce LLM prompt payload size and prune failed turn history
Reduce prefill token volume across system instructions, schemas, layout snapshots, and conversation history:
Pre-launch Checklist