-
Notifications
You must be signed in to change notification settings - Fork 464
async hooks #1119
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
async hooks #1119
Conversation
…nto async_hooks
zastrowm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inclined towards this - however I'd like to see if we can do full async (minus Agent.__init__) instead of trying to support both. Agent.init needs further api design (#330) which is why I'm okay holding off on that
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Sorry, high level, if we are executing sequentially why do we care if we are blocking the event loop? Isn't it already blocked by being sequential? If this is more of a benefit to hook authors where they can write async code, that makes sense to me. But can you explain what other benefit they get? |
The Usage example above highlights this. Hooks run sequentially amongst themselves but they run concurrently with other concurrent tasks. So the Usage example shows an external function ( |
Oh haha, ok event loop is an overloaded term. This is about the asyncio event loop not the Strands Agents Event Loop |
Oh yes lol. TypeScript fortunately we are switching to the term "agent loop". |
|
Note to be a reminder: we will need to add hooks to the Bidirectional Agent constructor once this is merged in |
mehtarac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if we had a chance to test this with the bidirectional agent as well?
Have not yet tested with Bidirectional agents. I first need to adjust the hook events so they can accept a bidirectional agent. Right now they only support a converse stream agent (src). The solution for that is being tracked in another issue. |
Description
Support asynchronous hooks so as not to block the async event loop when invoking agents asynchronously. Note, this will be particularly useful for Bidirectional Agents, which only operates asynchronously.
Usage
A few additional notes:
AgentInitializedEventstill does not support async callbacks since it is emitted from__init__. If users attempt to register an async callback on this event, they will receive aValueError. We could wrap the event in a thread, which would allow us to call its hooks asynchronously, but this technically is a breaking change.hook_1andhook_2into sync methods would result in the following output (note the lack of interleaving withfunc_1):Related Issues
#1017
Documentation PR
Will follow up after review.
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepare: Updated unit testshatch test tests_integ/hooks/**/*.py: Wrote new integ tests.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.