Skip to content

fix(agent): ignore cancel() when idle (#2156)#2241

Open
crazybolillo wants to merge 1 commit intostrands-agents:mainfrom
crazybolillo:main
Open

fix(agent): ignore cancel() when idle (#2156)#2241
crazybolillo wants to merge 1 commit intostrands-agents:mainfrom
crazybolillo:main

Conversation

@crazybolillo
Copy link
Copy Markdown

Description

Previously calling cancel() on an idle agent would make it so the next
invocation was immediately cancelled.

This is unexpected behavior, cancelling an idle agent should be a noop
and have no effect on future invocations. Active agent loops are now
tracked and cancel() won't have any effect if there are no active loops.

This method works for both concurrent modes, as UNSAFE_REENTRANT does
not use the existing invocation lock that could be used to tell if there
was a running agent.

Related Issues

[FEATURE] Make agent.cancel() a noop when agent is idle #2156

Documentation PR

N/A

Type of Change

Bug fix

Testing

  1. Ran unit tests hatch test
  2. Ran integration tests for cancellation hatch test tests_integ/test_cancellation.py
tests_integ/test_cancellation.py::test_cancel_with_bedrock 
tests_integ/test_cancellation.py::test_cancel_with_tools_bedrock 
tests_integ/test_cancellation.py::test_cancel_during_streaming_bedrock 
tests_integ/test_cancellation.py::test_cancel_from_thread_bedrock 
[gw1] [ 25%] PASSED tests_integ/test_cancellation.py::test_cancel_during_streaming_bedrock 
[gw0] [ 50%] PASSED tests_integ/test_cancellation.py::test_cancel_with_bedrock 
[gw3] [ 75%] PASSED tests_integ/test_cancellation.py::test_cancel_from_thread_bedrock 
[gw2] [100%] PASSED tests_integ/test_cancellation.py::test_cancel_with_tools_bedrock
  • I ran hatch run prepare

Checklist

  • [ X ] I have read the CONTRIBUTING document
  • [ X ] I have added any necessary tests that prove my fix is effective or my feature works
  • [ X ] I have updated the documentation accordingly
  • [ X ] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • [ X ] My changes generate no new warnings
  • [ X ] Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Previously calling cancel() on an idle agent would make it so the next
invocation was immediately cancelled.

This is unexpected behavior, cancelling an idle agent should be a noop
and have no effect on future invocations. Active agent loops are now
tracked and cancel() won't have any effect if there are no active loops.

This method works for both concurrent modes, as UNSAFE_REENTRANT does
not use the existing invocation lock that could be used to tell if there
was a running agent.
@crazybolillo
Copy link
Copy Markdown
Author

Closes #2156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant