Skip to content

Conversation

@pranav100000
Copy link
Contributor

No description provided.

Comment on lines 87 to 90
const messageHistoryBeforeStream = expireMessages(
agentState.messageHistory,
'agentStep',
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary, this is run right before each step already (in runAgentStep)

input: transformed ? transformed.input : input,
fromHandleSteps: false,
skipDirectResultPush: isXmlMode,
skipDirectResultPush: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we should refactor to delete this param entirely if always true

Comment on lines 342 to 349
// Build message history from the pre-stream snapshot so tool_calls and
// tool_results are always appended in deterministic order.
agentState.messageHistory = buildArray<Message>([
...messageHistoryBeforeStream,
...assistantMessages,
...toolResultsToAddAfterStream,
...errorMessages,
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually, I think it does make more sense to do all the mutating of message history here, in one place.

Comment on lines 571 to 573
if (!excludeToolFromMessageHistory && !params.skipDirectResultPush) {
agentState.messageHistory.push(toolResult)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the new paradigm, we can delete this if and
agentState.messageHistory.push(toolResult).

We might want to rename toolResultsToAddAfterStream to toolResultsToAddToMessageHistory, since all tool results are added after stream and these are the ones included in the message history in particular

Copy link
Contributor

@jahooma jahooma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Pranav! This is a tricky bug and our code here is kinda bad haha.

Made some comments, but the thrust of the change seems good.

If you make these fixes, I'll test & merge it!

@jahooma
Copy link
Contributor

jahooma commented Feb 9, 2026

Made a few more changes and merged as this PR: #431

Thanks!

@jahooma jahooma closed this Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants