Skip to content

Add structure to input output messages on all the scopes#221

Merged
nikhilNava merged 7 commits intomainfrom
nikhilc/addInputOutputStructure
Apr 7, 2026
Merged

Add structure to input output messages on all the scopes#221
nikhilNava merged 7 commits intomainfrom
nikhilc/addInputOutputStructure

Conversation

@nikhilNava
Copy link
Copy Markdown
Contributor

Task
Add a message structure to input and output messages on all scopes

Result

    "name": "Chat gpt-4o-mini",
    "context": {
        "trace_id": "0xcefaf1417342c02faac980deef9c0835",
        "span_id": "0xfde16c98a5acc42f",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": "0xff9e6ac6180eca51",
    "start_time": "2026-04-03T19:51:45.960138Z",
    "end_time": "2026-04-03T19:51:49.943292Z",
    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "gen_ai.conversation.id": "5308b196-ae5b-46df-b830-6181d467502e",
        "microsoft.conversation.item.link": "http://localhost:56150/_connector",
        "microsoft.agent.user.email": "b7a3a940-b39a-4a82-9629-0048f947f80a",
        "microsoft.channel.name": "msteams",
        "user.id": "a92962f3-9ed4-4bcd-9ae0-ad0002b6ca76",
        "user.name": "Alex Wilber",
        "telemetry.sdk.name": "A365ObservabilitySDK",
        "telemetry.sdk.language": "python",
        "telemetry.sdk.version": "0.0.0",
        "gen_ai.agent.id": "84d06baf-416c-4a43-a22d-f2ee93ea9e7e",
        "gen_ai.agent.name": "Azure OpenAI Agent",
        "gen_ai.agent.description": "An AI agent powered by Azure OpenAI",
        "microsoft.a365.agent.blueprint.id": "4a380e3b-7092-4d73-bb9d-b6a54702684af",
        "microsoft.tenant.id": "badf1f56-284d-4dc5-ac59-0dd53900e743",
        "gen_ai.input.messages": "{\"messages\": [{\"role\": \"user\", \"parts\": [{\"content\": \"\ufeffwhat is the weather in seattle?\\n\\nTool result: Weather information for current location: Sunny, 72\u00b0F\", \"type\": \"text\"}]}], \"version\": \"0.1.0\"}",
        "gen_ai.operation.name": "Chat",
        "gen_ai.request.model": "gpt-4o-mini",
        "gen_ai.provider.name": "Azure OpenAI",
        "gen_ai.output.messages": "{\"messages\": [{\"role\": \"assistant\", \"parts\": [{\"content\": \"The current weather in Seattle is sunny with a temperature of 72\u00b0F.\", \"type\": \"text\"}]}], \"version\": \"0.1.0\"}",    
        "gen_ai.usage.input_tokens": 50,
        "gen_ai.usage.output_tokens": 16,
        "gen_ai.response.finish_reasons": "[\"stop\"]"
    },
    "events": [],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.38.0",
            "service.namespace": "AzureOpenAiKairoTesting",
            "service.name": "AzureOpenAiKairoTracing"
        },
        "schema_url": ""
    }
}
{
    "name": "output_messages 84d06baf-416c-4a43-a22d-f2ee93ea9e7e",
    "context": {
        "trace_id": "0xcefaf1417342c02faac980deef9c0835",
        "span_id": "0x3673b4b4a88d00b2",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": "0xff9e6ac6180eca51",
    "start_time": "2026-04-03T19:51:49.943292Z",
    "end_time": "2026-04-03T19:51:49.946284Z",
    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "microsoft.conversation.item.link": "http://localhost:56150/_connector",
        "gen_ai.operation.name": "output_messages",
        "telemetry.sdk.name": "A365ObservabilitySDK",
        "telemetry.sdk.language": "python",
        "telemetry.sdk.version": "0.0.0",
        "gen_ai.agent.id": "84d06baf-416c-4a43-a22d-f2ee93ea9e7e",
        "gen_ai.agent.name": "nikhilcPermTest",
        "gen_ai.agent.description": "agenticUser",
        "microsoft.agent.user.email": "b7a3a940-b39a-4a82-9629-0048f947f80a",
        "microsoft.tenant.id": "badf1f56-284d-4dc5-ac59-0dd53900e743",
        "gen_ai.conversation.id": "5308b196-ae5b-46df-b830-6181d467502e",
        "gen_ai.output.messages": "{\"messages\": [{\"role\": \"assistant\", \"parts\": [{\"content\": \"The current weather in Seattle is sunny with a temperature of 72\u00b0F.\", \"type\": \"text\"}]}], \"version\": \"0.1.0\"}",    
        "user.id": "a92962f3-9ed4-4bcd-9ae0-ad0002b6ca76",
        "user.name": "Alex Wilber",
        "microsoft.channel.name": "msteams"
    },
    "events": [],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.38.0",
            "service.namespace": "AzureOpenAiKairoTesting",
            "service.name": "AzureOpenAiKairoTracing"
        },
        "schema_url": ""
    }
}
{
    "name": "invoke_agent Azure OpenAI Agent",
    "context": {
        "trace_id": "0xcefaf1417342c02faac980deef9c0835",
        "span_id": "0xff9e6ac6180eca51",
        "trace_state": "[]"
    },
    "kind": "SpanKind.CLIENT",
    "parent_id": null,
    "start_time": "2026-04-03T19:51:44.090270Z",
    "end_time": "2026-04-03T19:51:49.952267Z",
    "status": {
        "status_code": "UNSET"
    },
    "attributes": {
        "gen_ai.conversation.id": "5308b196-ae5b-46df-b830-6181d467502e",
        "microsoft.conversation.item.link": "http://localhost:56150/_connector",
        "microsoft.agent.user.email": "b7a3a940-b39a-4a82-9629-0048f947f80a",
        "microsoft.channel.name": "msteams",
        "user.id": "a92962f3-9ed4-4bcd-9ae0-ad0002b6ca76",
        "user.name": "Alex Wilber",
        "gen_ai.operation.name": "invoke_agent",
        "telemetry.sdk.name": "A365ObservabilitySDK",
        "telemetry.sdk.language": "python",
        "telemetry.sdk.version": "0.0.0",
        "gen_ai.agent.id": "84d06baf-416c-4a43-a22d-f2ee93ea9e7e",
        "gen_ai.agent.name": "Azure OpenAI Agent",
        "gen_ai.agent.description": "An AI agent powered by Azure OpenAI",
        "microsoft.a365.agent.blueprint.id": "4a380e3b-7092-4d73-bb9d-b6a54702684af",
        "microsoft.tenant.id": "badf1f56-284d-4dc5-ac59-0dd53900e743",
        "microsoft.session.id": "5308b196-ae5b-46df-b830-6181d467502e",
        "gen_ai.input.messages": "{\"messages\": [{\"role\": \"user\", \"parts\": [{\"content\": \"\ufeffwhat is the weather in seattle?\", \"type\": \"text\"}]}], \"version\": \"0.1.0\"}"
    },
    "events": [],
    "links": [],
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.38.0",
            "service.namespace": "AzureOpenAiKairoTesting",
            "service.name": "AzureOpenAiKairoTracing"
        },
        "schema_url": ""
    }
}

@nikhilNava nikhilNava requested review from a team as code owners April 3, 2026 20:00
Copilot AI review requested due to automatic review settings April 3, 2026 20:00
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA c2316e4.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a structured, versioned message schema for recording gen-ai input/output messages (and related tool inputs/outputs) across observability scopes, aligning telemetry payloads with OpenTelemetry gen-ai semantic conventions while keeping some backward compatibility for plain string inputs.

Changes:

  • Added OTEL gen-ai message model types (InputMessages/OutputMessages, roles, parts) plus normalization/serialization helpers.
  • Updated InvokeAgentScope, InferenceScope, and OutputScope to record input/output messages as versioned JSON wrappers rather than raw JSON lists.
  • Replaced URL parse results with a ServiceEndpoint(hostname, port) model and updated tests/examples accordingly.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/usage_example.py Updates sample usage to use ServiceEndpoint instead of urlparse.
tests/observability/core/test_trace_context_propagation.py Updates endpoint usage and tool argument structure to new message wrappers.
tests/observability/core/test_scope_messages.py Adds new tests covering structured message recording across scopes.
tests/observability/core/test_output_scope_bounded.py Updates bounded-output tests to reflect OutputMessage accumulation behavior.
tests/observability/core/test_message_utils.py Adds unit tests for message normalization and serialization helpers.
tests/observability/core/test_invoke_agent_scope.py Updates invoke scope tests to use ServiceEndpoint.
tests/observability/core/test_execute_tool_scope.py Updates tool scope tests to use tool message wrappers and new method names.
tests/observability/core/test_custom_start_end_time.py Updates tool arguments to structured tool input messages.
libraries/.../core/tool_call_details.py Changes tool call arguments/endpoints to structured types.
libraries/.../core/tenant_details.py Removes TenantDetails (deleted file).
libraries/.../core/spans_scopes/output_scope.py Normalizes/accumulates output messages as structured objects and flushes on scope end.
libraries/.../core/request.py Updates request content typing to structured input messages param.
libraries/.../core/models/service_endpoint.py Introduces ServiceEndpoint model for host/port endpoints.
libraries/.../core/models/response.py Updates response messages typing to structured output messages param.
libraries/.../core/models/messages.py Adds OTEL gen-ai message schema dataclasses, enums, wrappers, and param aliases.
libraries/.../core/message_utils.py Adds normalization and robust serialization helpers for message wrappers.
libraries/.../core/invoke_agent_scope.py Records input/output messages via structured wrapper serialization.
libraries/.../core/invoke_agent_details.py Updates endpoint typing to ServiceEndpoint.
libraries/.../core/inference_scope.py Records input/output messages via structured wrapper serialization.
libraries/.../core/inference_call_details.py Moves ServiceEndpoint to shared model import.
libraries/.../core/execution_type.py Removes ExecutionType (deleted file).
libraries/.../core/execute_tool_scope.py Records tool input/output via serialized wrappers and adds new recording APIs.
libraries/.../core/init.py Re-exports message schema types, Response, and ServiceEndpoint from the core package.

Copilot AI review requested due to automatic review settings April 6, 2026 14:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.

Copilot AI review requested due to automatic review settings April 6, 2026 15:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

@nikhilNava nikhilNava enabled auto-merge (squash) April 6, 2026 19:15
@nikhilNava nikhilNava merged commit 402f822 into main Apr 7, 2026
9 checks passed
@nikhilNava nikhilNava deleted the nikhilc/addInputOutputStructure branch April 7, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants