generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 605
Feat: graduate multiagent hook events from experimental #1498
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05dd45f
feat: graduate multiagent hook events from experimental
JackYPCOnline b238370
Merge branch 'main' into move_out
JackYPCOnline 82ff688
fix: remove unnecessary warnings
JackYPCOnline 845275e
fix: flatten import path
JackYPCOnline 2f978f0
fix: fix warning path
JackYPCOnline 4ff3e31
fix: fix unit test path
JackYPCOnline File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,118 +1,28 @@ | ||
| """Multi-agent execution lifecycle events for hook system integration. | ||
|
|
||
| These events are fired by orchestrators (Graph/Swarm) at key points so | ||
| hooks can persist, monitor, or debug execution. No intermediate state model | ||
| is used—hooks read from the orchestrator directly. | ||
| Deprecated: Use strands.hooks.multiagent instead. | ||
| """ | ||
|
|
||
| import uuid | ||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from typing_extensions import override | ||
|
|
||
| from ....hooks import BaseHookEvent | ||
| from ....types.interrupt import _Interruptible | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ....multiagent.base import MultiAgentBase | ||
|
|
||
|
|
||
| @dataclass | ||
| class MultiAgentInitializedEvent(BaseHookEvent): | ||
| """Event triggered when multi-agent orchestrator initialized. | ||
|
|
||
| Attributes: | ||
| source: The multi-agent orchestrator instance | ||
| invocation_state: Configuration that user passes in | ||
| """ | ||
|
|
||
| source: "MultiAgentBase" | ||
| invocation_state: dict[str, Any] | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class BeforeNodeCallEvent(BaseHookEvent, _Interruptible): | ||
| """Event triggered before individual node execution starts. | ||
|
|
||
| Attributes: | ||
| source: The multi-agent orchestrator instance | ||
| node_id: ID of the node about to execute | ||
| invocation_state: Configuration that user passes in | ||
| cancel_node: A user defined message that when set, will cancel the node execution with status FAILED. | ||
| The message will be emitted under a MultiAgentNodeCancel event. If set to `True`, Strands will cancel the | ||
| node using a default cancel message. | ||
| """ | ||
|
|
||
| source: "MultiAgentBase" | ||
| node_id: str | ||
| invocation_state: dict[str, Any] | None = None | ||
| cancel_node: bool | str = False | ||
|
|
||
| def _can_write(self, name: str) -> bool: | ||
| return name in ["cancel_node"] | ||
|
|
||
| @override | ||
| def _interrupt_id(self, name: str) -> str: | ||
| """Unique id for the interrupt. | ||
|
|
||
| Args: | ||
| name: User defined name for the interrupt. | ||
|
|
||
| Returns: | ||
| Interrupt id. | ||
| """ | ||
| node_id = uuid.uuid5(uuid.NAMESPACE_OID, self.node_id) | ||
| call_id = uuid.uuid5(uuid.NAMESPACE_OID, name) | ||
| return f"v1:before_node_call:{node_id}:{call_id}" | ||
|
|
||
|
|
||
| @dataclass | ||
| class AfterNodeCallEvent(BaseHookEvent): | ||
| """Event triggered after individual node execution completes. | ||
|
|
||
| Attributes: | ||
| source: The multi-agent orchestrator instance | ||
| node_id: ID of the node that just completed execution | ||
| invocation_state: Configuration that user passes in | ||
| """ | ||
|
|
||
| source: "MultiAgentBase" | ||
| node_id: str | ||
| invocation_state: dict[str, Any] | None = None | ||
|
|
||
| @property | ||
| def should_reverse_callbacks(self) -> bool: | ||
| """True to invoke callbacks in reverse order.""" | ||
| return True | ||
|
|
||
|
|
||
| @dataclass | ||
| class BeforeMultiAgentInvocationEvent(BaseHookEvent): | ||
| """Event triggered before orchestrator execution starts. | ||
|
|
||
| Attributes: | ||
| source: The multi-agent orchestrator instance | ||
| invocation_state: Configuration that user passes in | ||
| """ | ||
|
|
||
| source: "MultiAgentBase" | ||
| invocation_state: dict[str, Any] | None = None | ||
|
|
||
|
|
||
| @dataclass | ||
| class AfterMultiAgentInvocationEvent(BaseHookEvent): | ||
| """Event triggered after orchestrator execution completes. | ||
|
|
||
| Attributes: | ||
| source: The multi-agent orchestrator instance | ||
| invocation_state: Configuration that user passes in | ||
| """ | ||
|
|
||
| source: "MultiAgentBase" | ||
| invocation_state: dict[str, Any] | None = None | ||
|
|
||
| @property | ||
| def should_reverse_callbacks(self) -> bool: | ||
| """True to invoke callbacks in reverse order.""" | ||
| return True | ||
| import warnings | ||
|
|
||
| from ....hooks import ( | ||
| AfterMultiAgentInvocationEvent, | ||
| AfterNodeCallEvent, | ||
| BeforeMultiAgentInvocationEvent, | ||
| BeforeNodeCallEvent, | ||
| MultiAgentInitializedEvent, | ||
| ) | ||
|
|
||
| warnings.warn( | ||
| "strands.experimental.hooks.multiagent is deprecated. Use strands.hooks instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "AfterMultiAgentInvocationEvent", | ||
| "AfterNodeCallEvent", | ||
| "BeforeMultiAgentInvocationEvent", | ||
| "BeforeNodeCallEvent", | ||
| "MultiAgentInitializedEvent", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ooks/multiagent/test_multi_agent_hooks.py → ...s/strands/hooks/test_multi_agent_hooks.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.