Skip to content

feat: add gen_ai.agent.action_ref to trace_tool_span - #8187

Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 4 commits into
microsoft:mainfrom
wasim-builds:fix/7850-trace-tool-span-action-ref
Open

MOHAMMED WASIM KHAN (wasim-builds) wants to merge 4 commits into
microsoft:mainfrom
wasim-builds:fix/7850-trace-tool-span-action-ref

Conversation

@wasim-builds

Copy link
Copy Markdown

What

Added gen_ai.agent.action_ref support to trace_tool_span() for cross-producer audit correlation.

Why

Existing GenAI telemetry attributes (gen_ai.tool.call.id, gen_ai.tool.name, etc.) are producer-scoped. Auditors comparing spans across independent runtimes have no recomputable correlation key. gen_ai.agent.action_ref closes that gap with a deterministic SHA-256 handle derived from stable action fields.

Changes

  • Added GEN_AI_AGENT_ACTION_REF = "gen_ai.agent.action_ref" constant
  • Added derive_action_ref(agent_id, action_type, scope, timestamp_ms) helper that returns a SHA-256 hex digest of a canonical JSON preimage
  • Added optional action_ref: Optional[str] = None parameter to trace_tool_span()
  • Exported both new symbols from autogen_core and autogen_core._telemetry

Usage

from autogen_core import derive_action_ref, trace_tool_span

action_ref = derive_action_ref(
    agent_id="writer_agent",
    action_type="tool_call",
    scope="group_chat",
    timestamp_ms=int(time.time() * 1000),
)

with trace_tool_span("search", tool_call_id="call_123", action_ref=action_ref):
    ...

Testing

No new tests in this PR. The derive_action_ref helper is pure and deterministic; I manually verified that repeated calls with the same inputs produce identical hashes.

Fixes #7850

Wasim added 4 commits September 4, 2026 12:15
Added a new cancellation.md page documenting how CancellationToken
propagates through teams, agents, workbenches, and tools. Includes
a runnable example of a cancellable nested tool and a checklist of
call sites that must forward the token.

Fixes microsoft#8091
Cache key was built from messages, tools, json_output, and
extra_create_args only. Calls that differed only in tool_choice
(e.g. auto vs none) collided and returned stale cached responses.

Added tool_choice to the cache key data. For Tool objects, the
serialized key uses the tool name; for string choices, the string
is used directly.

Fixes microsoft#7968
…string

Previously, return_value_as_string fell back to str() for dict/list
values, producing Python repr strings instead of valid JSON. This
broke downstream agents that expected parseable structured data.

Now dict and list return values are serialized with json.dumps(),
matching the existing BaseModel path. Other types still use str()
as a safe fallback.

Fixes microsoft#7867
Added GEN_AI_AGENT_ACTION_REF constant and derive_action_ref helper
for deterministic cross-producer audit correlation. Added optional
action_ref parameter to trace_tool_span().

Fixes microsoft#7850
Copilot AI lite review requested due to automatic review settings September 4, 2026 07:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wasim-builds

Copy link
Copy Markdown
Author

Ready for review when convenient. Happy to iterate on feedback.

@wasim-builds

Copy link
Copy Markdown
Author

Hi there,

Sharing this PR concerning feat: add gen_ai.agent.action_ref to trace_tool_span for microsoft/autogen. Contributing around multi-agent orchestration, agent communication, and tool execution in AutoGen has been exciting, and I'd love to help out with additional improvements and features across microsoft/autogen.

I am actively exploring freelance/contract engagements as well as full-time engineering positions and contributor roles.

More details about my background and projects can be found on my profile: https://github.com/wasim-builds.

This branch has not been deployed

No deployments
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.

feat(autogen-core): add gen_ai.agent.action_ref to trace_tool_span for cross-producer audit correlation

2 participants