-
Notifications
You must be signed in to change notification settings - Fork 9
Add hostings SDK #92
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
Add hostings SDK #92
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9235a23
add agents hosting and auto populate functionality
nikhilc-microsoft 5b70293
rename folder
nikhilc-microsoft 1b36023
ensure cycle dependencies are resolved
nikhilc-microsoft b7b2e33
add tests
nikhilc-microsoft 97612e7
add token cache
nikhilc-microsoft e22b878
add tests
nikhilc-microsoft 37a94df
remove unused tests
nikhilc-microsoft 1dc7c2e
rename test file due to conflict
nikhilc-microsoft 0a2a152
address pr comments
nikhilc-microsoft 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
192 changes: 0 additions & 192 deletions
192
...vability-core/microsoft_agents_a365/observability/core/middleware/turn_context_baggage.py
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
libraries/microsoft-agents-a365-observability-hosting/README.md
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,9 @@ | ||
| # Microsoft Agent 365 Observability Hosting Library | ||
|
|
||
| This library provides hosting components for Agent 365 observability. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install microsoft-agents-a365-observability-hosting | ||
| ``` |
6 changes: 6 additions & 0 deletions
6
...agents-a365-observability-hosting/microsoft_agents_a365/observability/hosting/__init__.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,6 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| """ | ||
| Microsoft Agent 365 Observability Hosting Library. | ||
| """ |
2 changes: 2 additions & 0 deletions
2
...servability-hosting/microsoft_agents_a365/observability/hosting/scope_helpers/__init__.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,2 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. |
42 changes: 42 additions & 0 deletions
42
...ity-hosting/microsoft_agents_a365/observability/hosting/scope_helpers/populate_baggage.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,42 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterator | ||
| from typing import Any | ||
|
|
||
| from microsoft_agents.hosting.core.turn_context import TurnContext | ||
| from microsoft_agents_a365.observability.core.middleware.baggage_builder import BaggageBuilder | ||
|
|
||
| from .utils import ( | ||
| get_caller_pairs, | ||
| get_conversation_pairs, | ||
| get_execution_type_pair, | ||
| get_source_metadata_pairs, | ||
| get_target_agent_pairs, | ||
| get_tenant_id_pair, | ||
| ) | ||
|
|
||
|
|
||
| def _iter_all_pairs(turn_context: TurnContext) -> Iterator[tuple[str, Any]]: | ||
| activity = turn_context.activity | ||
| if not activity: | ||
| return | ||
| yield from get_caller_pairs(activity) | ||
| yield from get_execution_type_pair(activity) | ||
| yield from get_target_agent_pairs(activity) | ||
| yield from get_tenant_id_pair(activity) | ||
| yield from get_source_metadata_pairs(activity) | ||
| yield from get_conversation_pairs(activity) | ||
|
|
||
|
|
||
| def populate(builder: BaggageBuilder, turn_context: TurnContext) -> BaggageBuilder: | ||
| """Populate BaggageBuilder with baggage values extracted from a turn context. | ||
|
|
||
| Args: | ||
| builder: The BaggageBuilder instance to populate | ||
| turn_context: The TurnContext containing activity information | ||
|
|
||
| Returns: | ||
| The updated BaggageBuilder instance (for method chaining) | ||
| """ | ||
| builder.set_pairs(_iter_all_pairs(turn_context)) | ||
| return builder |
78 changes: 78 additions & 0 deletions
78
.../microsoft_agents_a365/observability/hosting/scope_helpers/populate_invoke_agent_scope.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,78 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| from microsoft_agents_a365.observability.core.invoke_agent_scope import InvokeAgentScope | ||
|
|
||
| from .utils import ( | ||
| get_caller_pairs, | ||
| get_conversation_pairs, | ||
| get_execution_type_pair, | ||
| get_source_metadata_pairs, | ||
| get_target_agent_pairs, | ||
| get_tenant_id_pair, | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from microsoft_agents.hosting.core.turn_context import TurnContext | ||
|
|
||
|
|
||
| def populate(scope: InvokeAgentScope, turn_context: TurnContext) -> InvokeAgentScope: | ||
| """ | ||
| Populate all supported InvokeAgentScope tags from the provided TurnContext. | ||
| :param scope: The InvokeAgentScope instance to populate. | ||
| :param turn_context: The TurnContext containing activity information. | ||
| :return: The updated InvokeAgentScope instance. | ||
| """ | ||
| if not turn_context: | ||
| raise ValueError("turn_context is required") | ||
|
|
||
| if not turn_context.activity: | ||
| return scope | ||
|
|
||
| activity = turn_context.activity | ||
|
|
||
| set_caller_tags(scope, activity) | ||
| set_execution_type_tags(scope, activity) | ||
| set_target_agent_tags(scope, activity) | ||
| set_tenant_id_tags(scope, activity) | ||
| set_source_metadata_tags(scope, activity) | ||
| set_conversation_id_tags(scope, activity) | ||
| set_input_message_tags(scope, activity) | ||
| return scope | ||
|
|
||
|
|
||
| def set_caller_tags(scope: InvokeAgentScope, activity) -> None: | ||
| """Sets the caller-related attribute values from the Activity.""" | ||
| scope.record_attributes(get_caller_pairs(activity)) | ||
|
|
||
|
|
||
| def set_execution_type_tags(scope: InvokeAgentScope, activity) -> None: | ||
| """Sets the execution type tag based on caller and recipient agentic status.""" | ||
| scope.record_attributes(get_execution_type_pair(activity)) | ||
|
|
||
|
|
||
| def set_target_agent_tags(scope: InvokeAgentScope, activity) -> None: | ||
| """Sets the target agent-related tags from the Activity.""" | ||
| scope.record_attributes(get_target_agent_pairs(activity)) | ||
|
|
||
|
|
||
| def set_tenant_id_tags(scope: InvokeAgentScope, activity) -> None: | ||
| """Sets the tenant ID tag, extracting from ChannelData if necessary.""" | ||
| scope.record_attributes(get_tenant_id_pair(activity)) | ||
|
|
||
|
|
||
| def set_source_metadata_tags(scope: InvokeAgentScope, activity) -> None: | ||
| """Sets the source metadata tags from the Activity.""" | ||
| scope.record_attributes(get_source_metadata_pairs(activity)) | ||
|
|
||
|
|
||
| def set_conversation_id_tags(scope: InvokeAgentScope, activity) -> None: | ||
| """Sets the conversation ID and item link tags from the Activity.""" | ||
| scope.record_attributes(get_conversation_pairs(activity)) | ||
|
|
||
|
|
||
| def set_input_message_tags(scope: InvokeAgentScope, activity) -> None: | ||
| """Sets the input message tag from the Activity.""" | ||
| if activity.text: | ||
| scope.record_input_messages([activity.text]) | ||
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.