Skip to content

Python: fix(python): validate settings and expose agent lifecycle methods - #8709

Merged
westey (westey-m) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:core-api-fixes
Sep 24, 2026
Merged

westey (westey-m) merged 3 commits into
microsoft:mainfrom
eavanvalkenburg:core-api-fixes

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Motivation & Context

Invalid optional numeric or boolean values supplied through environment variables and .env files could silently become raw strings or False, hiding configuration mistakes. The agent documentation also used unsupported constructor arguments, and applications need explicit resource-lifecycle methods alongside async with.

Description & Review Guide

  • What are the major changes? Validate environment and .env scalar settings with field/source-specific errors while retaining precedence and valid provider settings; add async open()/close() to RawAgent and Agent, delegate async context management to them, and clean up partial startup; correct the default_options examples and add focused regressions.
  • What is the impact of these changes? Invalid supplied values now fail immediately; valid settings, callable overrides, SecretString, and existing context-manager behavior remain supported. Explicit lifecycle control is now available.
  • What do you want reviewers to focus on? Nullable-union coercion (including provider-specific string arms) and client/MCP cleanup after partial initialization or a lazy connection.

Related Issue

None; this PR intentionally has no linked issue.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI balanced review requested due to automatic review settings September 23, 2026 18:17
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Sep 23, 2026
@github-actions github-actions Bot changed the title fix(python): validate settings and expose agent lifecycle methods Python: fix(python): validate settings and expose agent lifecycle methods Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Nullable Any and non-string Literal settings are incorrectly rejected.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds stricter Python settings validation and explicit agent resource lifecycle management.

Changes:

  • Validates environment and .env scalar values.
  • Adds open() and close() to agents with cleanup handling.
  • Updates documentation and regression tests.
File Description
python/​packages/​core/​agent_framework/​_settings.py Adds source-aware coercion errors.
python/​packages/​core/​agent_framework/​_agents.py Adds explicit lifecycle methods and fixes examples.
python/​packages/​core/​tests/​core/​test_settings.py Tests settings validation and precedence.
python/​packages/​core/​tests/​core/​test_agents.py Tests lifecycle and partial-startup cleanup.
python/​packages/​core/​AGENTS.md Documents the new behavior.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@westey-m
westey (westey-m) added this pull request to the merge queue Sep 24, 2026
Merged via the queue into microsoft:main with commit b20927b Sep 24, 2026
45 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 942b612f Deployed Sep 24, 2026 by eavanvalkenburg via add_label #23697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants