Conversation
| * Clears conversation history and resets agent state. | ||
| */ | ||
| clearHistory(): void { | ||
| async clearHistory(): Promise<void> { |
There was a problem hiding this comment.
Claude found that this change may require updating the following to properly await the function call here:
Line 188 in 62da3ae
There was a problem hiding this comment.
This function is called asynchronously, on click.
AFAIK, awaiting it in the chat model would not prevent the user to send a message... Or we should "lock" the input waiting for it.
Do you think that it worth it ?
| } | ||
| } | ||
| return sanitized; | ||
| return sanitized.length === messages.length ? sanitized : []; |
There was a problem hiding this comment.
Does this mean all messages are dropped if only one of them is removed during sanitization?
There was a problem hiding this comment.
This is actually expected:
- 'assistant' message and 'tool' messages may be linked by a
toolCallIdor anapprovalId. If one of them is removed, the history may be corrupted. Another solution could be to restart the sanitization, to ensure it did not break anything, but it seems a bit overkill (not sure it'll happen often) - if only the 'user' message left, the agent will try to answer it again on next call, so it is probably safer to clean it too for now. But we may handle it in a better way, as @Yahiewi proposed in Improve history sanitization #290 (comment)
|
I haven't run into an error while testing this PR and I like the new logic you've implemented. Thanks for working on this @brichet ! |
👍 totally agree, this PR only avoid to respond to a cancelled message endlessly, but it would be nice to instead keep it in history. |
e5fa0f6 to
3f119f9
Compare
Follow up #284
Currently, the end of the message history is truncated when an unexpected message is detected (e.g.
tool-callwithout result). This fix is applied when an error occurred during stream, including user abort.This PR change this logic, in favor of including in history only the sanitized message sequence. The whole messages sequence is added to the history (after sanitization) when the response is fully generated.
It is also a workaround for #285: if the stream is stopped, the user message is not added to the history, which avoid continuous responses to an aborted message.