Skip to content

feat: add cancellation handling to tools #1057

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

Merged
merged 2 commits into from
Apr 22, 2025
Merged

Conversation

jpinkney-aws
Copy link
Contributor

Problem

tools can't be canceled

Solution

  • plumb the cancellation token through to the tools
  • tools can optionally handle the cancellation token if it makes sense. e.g. execute bash/list directories makes sense, write file and read file doesn't
  • when a token is cancelled, it bubbles up the main agentic loop, sending an answer back to the chat-client and unlocking the UI

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jpinkney-aws jpinkney-aws requested a review from a team as a code owner April 22, 2025 17:11
Copy link
Contributor

@Hweinstock Hweinstock left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -554,6 +554,10 @@ export class AgenticChatController implements ChatHandlers {
break
}
} catch (err) {
if (CancellationError.isUserCancelled(err)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I handle tool validation rejections very similarly here. Do you think their logic should be combined more?

I think they should be separate since the stop button and the reject button are different, and could warrant different behavior in the future, but open to changing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should separate them since their intentions are different. I think they'd just have a minor overlap

@jpinkney-aws jpinkney-aws merged commit f2ea9ac into aws:main Apr 22, 2025
6 checks passed
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