Skip to content
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

stop works client side, but backend continue to stream #68

Open
sam-goodwin opened this issue Mar 10, 2025 · 4 comments
Open

stop works client side, but backend continue to stream #68

sam-goodwin opened this issue Mar 10, 2025 · 4 comments

Comments

@sam-goodwin
Copy link
Contributor

sam-goodwin commented Mar 10, 2025

useAgentChat proxies the underlying useChat's stop function, but does not reflect on the server.

I know this, because if i refresh after stopping the stream, the message appears.

const {
  stop,
  // ..
} = useAgentChat({ .. });

const handleCancel = () => {
  stop();
}

To workaround, I had to create an AbortController and pass the AbortSignal through to streamText:

const result = streamText({
  // ..
  abortSignal: controller.signal,
});

Then, I call my own API on the Agent to trigger the Abort Signal.

The final barrier I haven't yet gotten over is how to make sure the final message parts are persisted.

Not sure if I am approaching this in the right way.

@threepointone
Copy link
Collaborator

I'll fix it this week

@threepointone
Copy link
Collaborator

question on expected behaviour: do you want to stop the stream midway on the server side, as well as delete the full message itself? or do you expect the message midstream to be persisted? I suspect the former, but checking with you.

@sam-goodwin
Copy link
Contributor Author

Persist the message.

Then, I'd expect to be able to delete the message as another operation (and ui control).

This would match behavior of tools like Cursor.

@threepointone
Copy link
Collaborator

persist the half streamed message? not sure if that's the desired behaviour, would be confusing. I suspect it's better to just reset to the state before the message was sent.

it's also a bit tricky because the response might be changing previous messages as well, especially for human in the loop stuff.

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

No branches or pull requests

2 participants