-
Notifications
You must be signed in to change notification settings - Fork 468
Enable multi agent session persistence #900
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
Enable multi agent session persistence #900
Conversation
a2fa154 to
29a7dd8
Compare
29a7dd8 to
41d2f44
Compare
41d2f44 to
64a2ecb
Compare
src/strands/experimental/multiagent_session/multiagent_events.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/multiagent_session/multiagent_events.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/multiagent_session/multiagent_state.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/multiagent_session/multiagent_state_adapter.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/multiagent_session/multiagent_state_adapter.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/multiagent_session/multiagent_state_adapter.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/multiagent_session/multiagent_state_adapter.py
Outdated
Show resolved
Hide resolved
c9a0034 to
a774434
Compare
a774434 to
b53ba36
Compare
b53ba36 to
947261a
Compare
947261a to
4e3c44b
Compare
4e3c44b to
f47d3b9
Compare
Unshure
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.
I see you doing getattr throughout the code. I would like to avoid doing this, and instead check if objects are instances of classes. Two classes could have the same attribute, leading to undesirable behavior.
src/strands/experimental/hooks/multiagent_hooks/multiagent_events.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/hooks/multiagent_hooks/multiagent_events.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/hooks/multiagent_hooks/multiagent_events.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/hooks/multiagent_hooks/multiagent_events.py
Outdated
Show resolved
Hide resolved
src/strands/experimental/hooks/multiagent_hooks/multiagent_events.py
Outdated
Show resolved
Hide resolved
…s, refactor interface
pgrayy
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.
See comments.
| self.state.results[node_id] = node_result | ||
|
|
||
| # Persist failure here | ||
| self.hooks.invoke_callbacks(AfterNodeCallEvent(self, node_id=node_id, invocation_state=invocation_state)) |
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.
why can't we just do a finally here for both the happy and sad path case
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.
The idea is we should fire this event right after a node failed. But for sucess node we should fire after it has been added to self.state.node_history that's where it represent state updated. .
|
Closing this PR now. Thank you for reviewing this large PR and for all your valuable comments |
Description
This PR introduce interfaces, hooks and utils that multiagent persistence needs.
Key Change:
Hooks and Events
add Multiagent events and register within
SessionManager. All newly added events are used now.Graph and Swarm:
add session persistence to Graph and Swarm. Swarm and Graph can restore from saved session.
completed.completedsince Swarm has execution different logic but Swarm will call _build_result() with saved context.New APIs:
Test code/ User reference:
S3:
File:
Save multiagent_state_json example:
{ "type": "swarm", "status": "completed", "completed_nodes": [ "researcher", "analyst", "writer" ], "node_results": { "researcher": { "result": { "type": "agent_result", "stop_reason": "end_turn", "message": { "role": "assistant", "content": [ { "text": "I've completed the research phase and handed off to the analyst to create the requested 100-word report on AI in healthcare. The analyst has all the key findings including applications (diagnostic imaging, drug discovery, personalized medicine, etc.), benefits (improved accuracy, reduced costs, faster diagnosis), and challenges (data privacy, regulatory approval, system integration)." } ] } }, "execution_time": 9778, "status": "completed", "accumulated_usage": { "inputTokens": 1759, "outputTokens": 570, "totalTokens": 2329 }, "accumulated_metrics": { "latencyMs": 9476 }, "execution_count": 1 }, "analyst": { "result": { "type": "agent_result", "stop_reason": "end_turn", "message": { "role": "assistant", "content": [ { "text": "I've handed off the task to the writer agent who will now create the concise 100-word report on AI in healthcare using all the research findings that were previously gathered. The writer has all the necessary information about key applications, benefits, challenges, and the specific requirements for the report." } ] } }, "execution_time": 8644, "status": "completed", "accumulated_usage": { "inputTokens": 1951, "outputTokens": 405, "totalTokens": 2356 }, "accumulated_metrics": { "latencyMs": 8339 }, "execution_count": 1 }, "writer": { "result": { "type": "agent_result", "stop_reason": "end_turn", "message": { "role": "assistant", "content": [ { "text": "Based on the context provided, it appears that both the researcher and analyst agents have already worked on this task. Since I'm being asked to write the final report and the previous agents have presumably gathered and analyzed the necessary information, I'll proceed with creating a concise 100-word report on AI in healthcare.\n\n**AI in Healthcare: Executive Summary**\n\nArtificial Intelligence is revolutionizing healthcare through enhanced diagnostics, personalized treatment plans, and operational efficiency. Machine learning algorithms analyze medical imaging with unprecedented accuracy, enabling early disease detection. AI-powered drug discovery accelerates pharmaceutical development, reducing costs and timeframes. Predictive analytics help prevent hospital readmissions and optimize resource allocation. Virtual health assistants improve patient engagement and medication adherence. Robotic surgery systems enhance precision and minimize invasive procedures. However, challenges include data privacy concerns, regulatory compliance, and integration with existing systems. Despite obstacles, AI's potential to improve patient outcomes while reducing healthcare costs makes it indispensable for modern medical practice advancement.\n\nThe task is now complete with a comprehensive 100-word report on AI in healthcare." } ] } }, "execution_time": 4921, "status": "completed", "accumulated_usage": { "inputTokens": 622, "outputTokens": 231, "totalTokens": 853 }, "accumulated_metrics": { "latencyMs": 4716 }, "execution_count": 1 } }, "next_node_to_execute": [], "current_task": "Research AI in healthcare and produce a concise report in 100 words.", "execution_order": [ "researcher", "analyst", "writer" ], "context": { "shared_context": {}, "handoff_message": null } }Related Issues
#867
#500
Documentation PR
Type of Change
Bug fix
New feature
Breaking change
Documentation update
Other (please describe):
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 prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.