Skip to content

Conversation

@clint-morgan
Copy link

This PR addresses Issue #2694 by adding support for serializing and propagating AgentContext across process boundaries (e.g., HTTP calls between agents).

Problem

Currently, AgentContext.CurrentThread is thread-local and is lost when an agent makes an outbound call to another agent via HTTP or other transports. This breaks the ambient context pattern, causing loss of ContextId, ConversationId, and distributed tracing correlation in downstream agents.

Changes

  1. AgentContext.cs: Added CreateSnapshot() and RestoreFromSnapshot() methods to serialize/deserialize the current thread context.
  2. AgentContextSnapshot: Introduced a serializable DTO for transmitting context metadata.
  3. RestoredAgentContextThread: Added an internal implementation of IAgentContextThread to support restored contexts.

Benefits

  • Enables true distributed tracing and context propagation in microservice-style agent architectures.
  • Allows downstream agents to access the original ContextId and ConversationId without explicit parameter passing.
  • Preserves governance metadata across the execution chain.

Testing

  • Verified locally with a multi-agent workflow (Orchestrator -> Agent A -> Agent B).
  • Confirmed that AgentContext.CurrentThread is correctly populated in the receiving agent.

@github-actions github-actions bot changed the title Fix: Enable AgentContext Propagation across Async/HTTP Boundaries (Issue #2694) .NET: Fix: Enable AgentContext Propagation across Async/HTTP Boundaries (Issue #2694) Dec 10, 2025
@clint-morgan
Copy link
Author

clint-morgan commented Dec 10, 2025 via email

@clint-morgan
Copy link
Author

clint-morgan commented Dec 10, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants