-
Notifications
You must be signed in to change notification settings - Fork 679
Python: Add Handoff orchestration pattern support #1469
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 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8fbc4a1
Add Handoff orchestration pattern support
moonbox3 f8c3b14
PR feedback
moonbox3 e333dd9
Use AOAI client in samples
moonbox3 f7e105f
Adjust to tool
moonbox3 07abcbb
Handoff to sub-agent via ai function
moonbox3 0b6d984
PR feedback
moonbox3 639735e
More cleanup
moonbox3 a4f0103
Merge branch 'main' into workflow-handoff-20251014
moonbox3 5223f12
Merge branch 'main' into workflow-handoff-20251014
moonbox3 6e4c9c5
Improvements
moonbox3 f271af0
Merge branch 'workflow-handoff-20251014' of github.com:moonbox3/agent…
moonbox3 3445ac3
Merge branch 'main' into workflow-handoff-20251014
moonbox3 13a86ba
PR feedback cleanup
moonbox3 5714fea
Add handoff migration sample.
moonbox3 7462eca
Remove type ignore
moonbox3 be475c1
fix markdown link formatting
moonbox3 00b7ccb
Remove readme link for non-existent sample
moonbox3 cc26704
Merge branch 'main' into workflow-handoff-20251014
moonbox3 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
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
77 changes: 77 additions & 0 deletions
77
python/packages/core/agent_framework/_workflows/_conversation_state.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| from collections.abc import Iterable | ||
| from typing import Any, cast | ||
|
|
||
| from agent_framework import ChatMessage, Role | ||
|
|
||
| from ._checkpoint_encoding import decode_checkpoint_value, encode_checkpoint_value # type: ignore | ||
|
|
||
| """Utilities for serializing and deserializing chat conversations for persistence. | ||
|
|
||
| These helpers convert rich `ChatMessage` instances to checkpoint-friendly payloads | ||
| using the same encoding primitives as the workflow runner. This preserves | ||
| `additional_properties` and other metadata without relying on unsafe mechanisms | ||
| such as pickling. | ||
| """ | ||
|
|
||
|
|
||
| def encode_chat_messages(messages: Iterable[ChatMessage]) -> list[dict[str, Any]]: | ||
| """Serialize chat messages into checkpoint-safe payloads.""" | ||
| encoded: list[dict[str, Any]] = [] | ||
| for message in messages: | ||
| encoded.append({ | ||
| "role": encode_checkpoint_value(message.role), | ||
| "contents": [encode_checkpoint_value(content) for content in message.contents], | ||
| "author_name": message.author_name, | ||
| "message_id": message.message_id, | ||
| "additional_properties": { | ||
| key: encode_checkpoint_value(value) for key, value in message.additional_properties.items() | ||
| }, | ||
| }) | ||
| return encoded | ||
|
|
||
|
|
||
| def decode_chat_messages(payload: Iterable[dict[str, Any]]) -> list[ChatMessage]: | ||
| """Restore chat messages from checkpoint-safe payloads.""" | ||
| restored: list[ChatMessage] = [] | ||
| for item in payload: | ||
| if not isinstance(item, dict): | ||
| continue | ||
|
|
||
| role_value = decode_checkpoint_value(item.get("role")) | ||
| if isinstance(role_value, Role): | ||
| role = role_value | ||
| elif isinstance(role_value, dict): | ||
| role_dict = cast(dict[str, Any], role_value) | ||
| role = Role.from_dict(role_dict) | ||
| elif isinstance(role_value, str): | ||
| role = Role(value=role_value) | ||
| else: | ||
| role = Role.ASSISTANT | ||
|
|
||
| contents_field = item.get("contents", []) | ||
| contents: list[Any] = [] | ||
| if isinstance(contents_field, list): | ||
| contents_iter: list[Any] = contents_field # type: ignore[assignment] | ||
| for entry in contents_iter: | ||
| decoded_entry: Any = decode_checkpoint_value(entry) | ||
| contents.append(decoded_entry) | ||
|
|
||
| additional_field = item.get("additional_properties", {}) | ||
| additional: dict[str, Any] = {} | ||
| if isinstance(additional_field, dict): | ||
| additional_dict = cast(dict[str, Any], additional_field) | ||
| for key, value in additional_dict.items(): | ||
| additional[key] = decode_checkpoint_value(value) | ||
|
|
||
| restored.append( | ||
| ChatMessage( | ||
| role=role, | ||
| contents=contents, | ||
| author_name=item.get("author_name"), | ||
| message_id=item.get("message_id"), | ||
| additional_properties=additional, | ||
| ) | ||
| ) | ||
| return restored | ||
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.