Skip to content

Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent#3566

Closed
Copilot wants to merge 7 commits intomainfrom
copilot/map-assistent-reasoning-events
Closed

Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent#3566
Copilot wants to merge 7 commits intomainfrom
copilot/map-assistent-reasoning-events

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 31, 2026

Motivation and Context

GitHub Copilot SDK emits AssistantReasoningEvent and AssistantReasoningDeltaEvent for model reasoning/thinking output. GitHubCopilotAgent was not handling these events, causing reasoning content to be lost or stored as generic AIContent instead of the semantically correct TextReasoningContent.

Description

C# Implementation (GitHubCopilotAgent.cs)

  • Added case handlers for AssistantReasoningDeltaEvent and AssistantReasoningEvent
  • Map AssistantReasoningDeltaEvent.Data.DeltaContentTextReasoningContent (streaming)
  • Map AssistantReasoningEvent.Data.ContentTextReasoningContent (complete)
  • Handle null data/content gracefully

Python Implementation (_agent.py)

  • Added handlers for SessionEventType.ASSISTANT_REASONING_DELTA and SessionEventType.ASSISTANT_REASONING
  • Create AgentResponseUpdate with Content.from_text_reasoning(text=...) using keyword arguments
  • Use string literal "assistant" for role (following Role type documentation and existing pattern)

Tests

  • C#: 6 unit tests covering event conversion and null handling
  • Python: 2 streaming tests with reasoning event fixtures using agent.run(stream=True) API

Follows existing event handling patterns (e.g., AssistantMessageDeltaEventTextContent).

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.
Original prompt

Teach the GitHubCopilotAgent about AssistentReasoningEvent and AssistantReasoningDeltaEvent, mapping them to TextReasoningContent.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 31, 2026 21:25
…to GitHubCopilotAgent

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title [WIP] Add mapping for AssistentReasoningEvent and AssistantReasoningDeltaEvent Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent Jan 31, 2026
Copilot AI requested a review from stephentoub January 31, 2026 21:32
@stephentoub stephentoub marked this pull request as ready for review February 20, 2026 03:06
Copilot AI review requested due to automatic review settings February 20, 2026 03:06
@github-actions github-actions Bot changed the title Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent .NET: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent Feb 20, 2026
@github-actions github-actions Bot changed the title .NET: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent Feb 20, 2026
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 adds support for GitHub Copilot SDK's AssistantReasoningEvent and AssistantReasoningDeltaEvent to properly handle and preserve model reasoning/thinking output as TextReasoningContent instead of losing it or storing it as generic AIContent.

Changes:

  • Added event handlers for reasoning events in both C# and Python implementations
  • Created conversion methods to map reasoning events to TextReasoningContent
  • Added comprehensive unit tests covering reasoning event handling and null safety

Reviewed changes

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

File Description
dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs Added case handlers and conversion methods for AssistantReasoningDeltaEvent and AssistantReasoningEvent to create TextReasoningContent
dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentReasoningTests.cs Added 6 unit tests covering successful conversion of reasoning events and null handling scenarios
python/packages/github_copilot/agent_framework_github_copilot/_agent.py Added handlers for reasoning event types to create AgentResponseUpdate with TextReasoningContent
python/packages/github_copilot/tests/test_github_copilot_agent.py Added test fixtures and 2 streaming tests for reasoning delta and complete events
Comments suppressed due to low confidence (3)

python/packages/github_copilot/agent_framework_github_copilot/_agent.py:468

  • Content.from_text_reasoning() only accepts keyword arguments (note the *, in its signature at python/packages/core/agent_framework/_types.py:533). This call passes a positional argument and will fail with a TypeError. Change to Content.from_text_reasoning(text=event.data.content).
                        contents=[Content.from_text_reasoning(event.data.content)],

python/packages/github_copilot/tests/test_github_copilot_agent.py:531

  • Role is not imported in this test file, which will cause a NameError when this test runs. Either import Role from agent_framework, or use the string literal "assistant" directly as per the Role type documentation (python/packages/core/agent_framework/_types.py:1354-1373).
        assert responses[0].role == Role.ASSISTANT

python/packages/github_copilot/agent_framework_github_copilot/_agent.py:467

  • Role is not imported in this file, which will cause a NameError at runtime. The existing code uses string literals like "assistant" (see line 449). Change Role.ASSISTANT to "assistant" to match the existing pattern.
                        role=Role.ASSISTANT,

Comment thread python/packages/github_copilot/agent_framework_github_copilot/_agent.py Outdated
Comment thread python/packages/github_copilot/tests/test_github_copilot_agent.py Outdated
Comment thread python/packages/github_copilot/agent_framework_github_copilot/_agent.py Outdated
@stephentoub
Copy link
Copy Markdown
Member

@copilot address all feedback

@stephentoub stephentoub changed the title Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent .NET / Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent Feb 22, 2026
…rals for Role

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copilot AI changed the title .NET / Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent Feb 22, 2026
@stephentoub
Copy link
Copy Markdown
Member

@copilot there are CI failures

…ream()

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot there are CI failures

Fixed in 564d652. The tests were using agent.run_stream("Hello") which doesn't exist. Changed to use the correct API: agent.run("Hello", stream=True) to match the existing test patterns and the actual GitHubCopilotAgent implementation.

auto-merge was automatically disabled March 27, 2026 01:52

Pull request was closed

@stephentoub stephentoub deleted the copilot/map-assistent-reasoning-events branch March 27, 2026 01:52
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.

4 participants