-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update agent message handling #1478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 7dd4a35 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 3 files
Greptile SummaryMoved message compression from middleware to Key changes:
Impact: The middleware approach was creating modified copies before passing to the LLM, but the original state messages remained unchanged in memory. This refactor mutates the actual message array, so compression (keeping 2 recent screenshots, 1 recent ariaTree) now actually reduces memory usage. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Agent as V3AgentHandler
participant PrepareStep as prepareStep Callback
participant LLM as Language Model
participant Messages as Message Array
Note over Agent,Messages: Before: Middleware Approach
Agent->>LLM: Call with middleware
LLM->>Messages: Copy messages
Messages-->>LLM: Return copied messages
Note over Messages: Original messages unchanged<br/>Memory not reduced
Note over Agent,Messages: After: PrepareStep Approach
Agent->>PrepareStep: createPrepareStep()
PrepareStep->>Messages: processMessages(options.messages)
Messages->>Messages: Mutate in-place<br/>Replace base64 with placeholders
Note over Messages: Keep 2 recent screenshots<br/>Keep 1 recent ariaTree
Messages-->>PrepareStep: Return mutated messages
PrepareStep->>LLM: Pass to model
Note over Messages: Memory actually reduced
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 1 comment
| userCallback?: PrepareStepFunction<ToolSet>, | ||
| ): PrepareStepFunction<ToolSet> { | ||
| return async (options) => { | ||
| processMessages(options.messages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using return value from processMessages() for logging/debugging compressed message count, or remove return value if not needed
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/core/lib/v3/handlers/v3AgentHandler.ts
Line: 135:135
Comment:
**style:** Consider using return value from `processMessages()` for logging/debugging compressed message count, or remove return value if not needed
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Why
The middleware approach kept the full message data in state and created modified copies each time before passing to the LLM so compression never actually reduced messages memory.
What Changed
processMessagesfrom middleware toprepareStepcallback, allowing us to mutate messages in place so image/aria tree compression actually takes effect in memoryoutput.valueandresultfields (base64 data lives inoutput.value)messageProcessing.tsTest Plan
Summary by cubic
Move agent message compression to prepareStep to mutate messages in place, pruning old screenshots and ARIA trees to reduce memory. Also support both output.value and result tool payloads.
Written for commit 7dd4a35. Summary will update automatically on new commits.