Commit 339e76d
Python: Fix GitHubCopilotAgent to invoke context provider before_run/after_run hooks (microsoft#5013)
* Fix GitHubCopilotAgent not calling context provider hooks (microsoft#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 microsoft#3984
* fix(microsoft#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 microsoft#3984: Python: [Bug]: GitHubCopilotAgent Memory Example
* refactor(microsoft#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 microsoft#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>1 parent 62595b2 commit 339e76d
2 files changed
Lines changed: 624 additions & 7 deletions
File tree
- python/packages/github_copilot
- agent_framework_github_copilot
- tests
Lines changed: 93 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
352 | 354 | | |
353 | 355 | | |
354 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
355 | 368 | | |
356 | 369 | | |
357 | 370 | | |
358 | 371 | | |
359 | 372 | | |
360 | | - | |
| 373 | + | |
361 | 374 | | |
| 375 | + | |
362 | 376 | | |
363 | 377 | | |
364 | 378 | | |
| |||
377 | 391 | | |
378 | 392 | | |
379 | 393 | | |
380 | | - | |
| 394 | + | |
381 | 395 | | |
382 | | - | |
383 | 396 | | |
384 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
385 | 410 | | |
386 | 411 | | |
387 | 412 | | |
| |||
408 | 433 | | |
409 | 434 | | |
410 | 435 | | |
411 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
412 | 440 | | |
413 | 441 | | |
414 | 442 | | |
415 | 443 | | |
416 | 444 | | |
417 | 445 | | |
418 | 446 | | |
| 447 | + | |
419 | 448 | | |
420 | 449 | | |
421 | 450 | | |
| |||
425 | 454 | | |
426 | 455 | | |
427 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
428 | 460 | | |
429 | 461 | | |
430 | 462 | | |
| |||
440 | 472 | | |
441 | 473 | | |
442 | 474 | | |
443 | | - | |
444 | 475 | | |
445 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
446 | 492 | | |
447 | 493 | | |
448 | 494 | | |
| |||
513 | 559 | | |
514 | 560 | | |
515 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
516 | 602 | | |
517 | 603 | | |
518 | 604 | | |
| |||
0 commit comments