Files
agent-framework/python/packages/github_copilot
T
Giles Odigwe 339e76d51f Python: Fix GitHubCopilotAgent to invoke context provider before_run/after_run hooks (#5013)
* Fix GitHubCopilotAgent not calling context provider hooks (#3984)

GitHubCopilotAgent accepted context_providers in its constructor but
never called before_run()/after_run() on them in _run_impl() or
_stream_updates(), silently ignoring all context providers.

Add _run_before_providers() helper to create SessionContext and invoke
before_run on each provider. Both _run_impl() and _stream_updates() now
run the full provider lifecycle: before_run before sending the prompt
(with provider instructions prepended) and after_run after receiving the
response. This follows the same pattern used by A2AAgent.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Python: Fix GitHubCopilotAgent to invoke context provider before_run/after_run hooks

Fixes #3984

* fix(#3984): address review feedback for context provider integration

- Build prompt from session_context.get_messages(include_input=True) so
  provider-injected context_messages are included in both non-streaming
  and streaming paths (review comments #1, #2)
- Preserve timeout in opts (use get instead of pop) so providers can
  observe it via context.options (review comment #3)
- Eliminate streaming double-buffer: move after_run invocation to a
  ResponseStream result_hook (matching Agent class pattern) instead of
  maintaining a separate updates list in the generator (review comment #4)
- Improve _run_before_providers docstring

Add tests for:
- Context messages included in prompt (non-streaming + streaming)
- Error path: after_run NOT called when send_and_wait/streaming raises
- Multiple providers: forward before_run, reverse after_run ordering
- BaseHistoryProvider with load_messages=False is skipped
- Streaming after_run response contains aggregated updates
- Streaming with no updates still sets empty response
- Timeout preserved in session context options for providers

Note: _run_before_providers remains on GitHubCopilotAgent for now. A
follow-up PR should extract it to BaseAgent so subclasses can reuse it
without duplicating the provider iteration logic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address review feedback for #3984: Python: [Bug]: GitHubCopilotAgent Memory Example

* refactor(#3984): promote _run_before_providers to BaseAgent

Move _run_before_providers from GitHubCopilotAgent into BaseAgent,
mirroring the existing _run_after_providers helper. Agent's
_prepare_session_and_messages now delegates to the shared base method,
eliminating the near-duplicate provider iteration logic that could
drift as the provider contract evolves.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address review feedback for #3984: Python: [Bug]: GitHubCopilotAgent Memory Example

* revert: keep _run_before_providers in GitHubCopilotAgent only

Undo the promotion of _run_before_providers to BaseAgent. The method
stays in GitHubCopilotAgent where it is needed, and _agents.py
retains its original inline provider iteration in RawAgent.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: replace deprecated BaseContextProvider/BaseHistoryProvider with ContextProvider/HistoryProvider

Update imports and usages in GitHubCopilotAgent and its tests to use
the new non-deprecated class names from the core package.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: address review feedback - reorder providers before session, wrap streaming after_run in try/except, assert after_run on skipped HistoryProvider

- Move _run_before_providers before _get_or_create_session so provider
  contributions can affect session configuration
- Wrap _run_after_providers in try/except in streaming _after_run_hook
  to prevent provider errors from replacing successful responses
- Add after_run assertion to test_history_provider_skip_when_load_messages_false

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
339e76d51f ยท 2026-04-02 09:43:02 +00:00
History
..

Get Started with Microsoft Agent Framework GitHub Copilot

Please install this package via pip:

pip install agent-framework-github-copilot --pre

GitHub Copilot Agent

The GitHub Copilot agent enables integration with GitHub Copilot, allowing you to interact with Copilot's agentic capabilities through the Agent Framework.