Skip to content

Comments

Python: Add AssistantReasoningEvent and AssistantReasoningDeltaEvent support to GitHubCopilotAgent#3566

Open
Copilot wants to merge 4 commits intomainfrom
copilot/map-assistent-reasoning-events
Open

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

Conversation

Copy link
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()

Tests

  • C#: 6 unit tests covering event conversion and null handling
  • Python: 2 streaming tests with reasoning event fixtures

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
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,

if event.data.delta_content:
update = AgentResponseUpdate(
role=Role.ASSISTANT,
contents=[Content.from_text_reasoning(event.data.delta_content)],
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

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.delta_content).

This issue also appears on line 468 of the same file.

Copilot uses AI. Check for mistakes.

assert len(responses) == 1
assert isinstance(responses[0], AgentResponseUpdate)
assert responses[0].role == Role.ASSISTANT
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

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).

This issue also appears on line 531 of the same file.

Copilot uses AI. Check for mistakes.
elif event.type == SessionEventType.ASSISTANT_REASONING_DELTA:
if event.data.delta_content:
update = AgentResponseUpdate(
role=Role.ASSISTANT,
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

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.

This issue also appears on line 467 of the same file.

Copilot uses AI. Check for mistakes.
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.

3 participants