Skip to content

Python: emit tool definitions individually for telemetry#6302

Closed
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/python-tool-definitions-otel
Closed

Python: emit tool definitions individually for telemetry#6302
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/python-tool-definitions-otel

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

Fixes #6300.

The Python telemetry mapper now emits gen_ai.tool.definitions as a list of per-tool JSON strings instead of one JSON string containing the whole array. That matches the shape Aspire expects for its Tools tab and keeps the existing _tools_to_dict normalization path.

Validation

  • python -m pytest python\packages\core\tests\core\test_observability.py -q -k tool_definitions
  • python -m pytest python\packages\core\tests\core\test_observability.py -q -k get_span_attributes
  • python -m ruff check python\packages\core\agent_framework\observability.py python\packages\core\tests\core\test_observability.py
  • python -m ruff format --check python\packages\core\agent_framework\observability.py python\packages\core\tests\core\test_observability.py
  • python -m mypy --config-file python\packages\core\pyproject.toml python\packages\core\agent_framework\observability.py
  • git diff --check

Copilot AI review requested due to automatic review settings June 3, 2026 10:54
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

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates how tool definitions are recorded into span attributes so each tool is serialized independently, and adds a regression test to validate the new structure.

Changes:

  • Add _serialize_tool_definitions() helper to serialize tool definitions into a list of JSON strings.
  • Update the OTEL attribute mapping for tools to use the new serializer.
  • Add a unit test asserting a single tool produces a single, individually-serialized definition.

Reviewed changes

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

File Description
python/packages/core/agent_framework/observability.py Switch tool-definition span attribute serialization from a single JSON blob to per-tool JSON entries via a helper.
python/packages/core/tests/core/test_observability.py Add a test verifying per-tool serialization behavior and JSON structure.

Comment on lines +2096 to +2102
def _serialize_tool_definitions(tools: Any) -> list[str] | None:
from agent_framework._tools import _tools_to_dict

tools_dict = _tools_to_dict(tools)
if not tools_dict:
return None
return [json.dumps(tool_def, ensure_ascii=False) for tool_def in tools_dict]
Comment on lines +2899 to +2912
def test_get_span_attributes_serializes_tool_definitions_individually():
from agent_framework.observability import OtelAttr, _get_span_attributes

@tool
def lookup_weather(city: str) -> str:
return f"sunny in {city}"

attrs = _get_span_attributes(tools=[lookup_weather])
definitions = attrs[OtelAttr.TOOL_DEFINITIONS]

assert isinstance(definitions, list)
assert len(definitions) == 1
definition = json.loads(definitions[0])
assert definition["function"]["name"] == "lookup_weather"
@moonbox3
Copy link
Copy Markdown
Contributor

moonbox3 commented Jun 3, 2026

Thank you for your contribution, @he-yufeng.

To keep the review queue manageable, we currently limit community contributors to 10 open pull requests at a time. This PR would put you at 20 open pull requests, so we are closing it automatically.

Please focus on getting your existing PRs reviewed, merged, or closed before opening another one. If a maintainer asked you to open this PR, they can apply the pr-limit-exempt label and reopen it.

@moonbox3 moonbox3 closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: gen_ai.tool.definitions emitted as single JSON blob, breaks Aspire Tools view

3 participants