Skip to content

Python: Clean up imports#2318

Merged
moonbox3 merged 5 commits intomicrosoft:mainfrom
brandonmcconnell:brandonmcconnell/cleanup-imports
Nov 19, 2025
Merged

Python: Clean up imports#2318
moonbox3 merged 5 commits intomicrosoft:mainfrom
brandonmcconnell:brandonmcconnell/cleanup-imports

Conversation

@brandonmcconnell
Copy link
Contributor

Motivation and Context

This change is improves code readability and maintainability. It provides consistent imports and removes unnecessary imports. It contributes to a cleaner codebase.

Description

This PR updates the import statements in the agent examples to remove unnecessary _clients imports and uses the direct import path for AgentFrameworkAgent and confirmation strategies.

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.

Copilot AI review requested due to automatic review settings November 19, 2025 06:28
@brandonmcconnell brandonmcconnell requested a review from a team as a code owner November 19, 2025 06:28
@markwallace-microsoft markwallace-microsoft added documentation Improvements or additions to documentation python labels Nov 19, 2025
@brandonmcconnell brandonmcconnell changed the title Cleans up imports in agent examples Python: clean up imports in agent examples Nov 19, 2025
@github-actions github-actions bot changed the title Python: clean up imports in agent examples Python: Cleans up imports in agent examples Nov 19, 2025
@brandonmcconnell brandonmcconnell changed the title Python: Cleans up imports in agent examples Python: Clean up imports Nov 19, 2025
@brandonmcconnell
Copy link
Contributor Author

@microsoft-github-policy-service agree

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 cleans up import statements across Python agent examples and packages by:

  • Removing unnecessary from __future__ import annotations imports (Python 3.10+ doesn't strictly require this for basic type hints)
  • Updating imports from the internal agent_framework._clients module to use the public agent_framework API
  • Updating imports from agent_framework_ag_ui to use the re-export path agent_framework.ag_ui
  • Cleaning up excessive blank lines in some files

Key Changes

  • Removed from __future__ import annotations from 12 files (purview, redis, devui, azurefunctions packages and samples)
  • Updated ChatClientProtocol imports from agent_framework._clients to agent_framework in 10 files (tests, examples, agents)
  • Updated AG-UI related imports from agent_framework_ag_ui to agent_framework.ag_ui in 15 files (tests, examples, documentation)

Reviewed Changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/samples/getting_started/purview_agent/sample_purview_agent.py Removed unnecessary from __future__ import annotations
python/packages/redis/agent_framework_redis/_chat_message_store.py Removed unnecessary from __future__ import annotations
python/packages/purview/agent_framework_purview/_settings.py Removed unnecessary from __future__ import annotations
python/packages/purview/agent_framework_purview/_processor.py Removed unnecessary from __future__ import annotations
python/packages/purview/agent_framework_purview/_models.py Removed unnecessary from __future__ import annotations
python/packages/purview/agent_framework_purview/_middleware.py Removed unnecessary from __future__ import annotations
python/packages/purview/agent_framework_purview/_exceptions.py Removed unnecessary from __future__ import annotations
python/packages/purview/agent_framework_purview/_client.py Removed unnecessary from __future__ import annotations
python/packages/purview/agent_framework_purview/_cache.py Removed unnecessary from __future__ import annotations
python/packages/devui/agent_framework_devui/models/_openai_custom.py Removed unnecessary from __future__ import annotations
python/packages/devui/agent_framework_devui/models/_discovery_models.py Removed unnecessary from __future__ import annotations
python/packages/devui/agent_framework_devui/_discovery.py Removed unnecessary from __future__ import annotations
python/packages/core/tests/core/test_middleware.py Updated ChatClientProtocol import to use public API
python/packages/core/agent_framework/observability.py Updated ChatClientProtocol import in documentation example
python/packages/core/agent_framework/ag_ui/init.pyi Changed import path from agent_framework_ag_ui to agent_framework.ag_ui (has issues - see comments)
python/packages/azurefunctions/agent_framework_azurefunctions/_models.py Removed unnecessary from __future__ import annotations
python/packages/azurefunctions/agent_framework_azurefunctions/_errors.py Removed unnecessary from __future__ import annotations and excess blank lines
python/packages/azurefunctions/agent_framework_azurefunctions/_callbacks.py Removed imports and from __future__ import annotations (has issues - see comments)
python/packages/ag-ui/tests/test_structured_output.py Updated AG-UI imports to use agent_framework.ag_ui
python/packages/ag-ui/tests/test_agent_wrapper_comprehensive.py Updated AG-UI imports to use agent_framework.ag_ui
python/packages/ag-ui/getting_started/client_with_agent.py Updated AG-UI imports to use agent_framework.ag_ui
python/packages/ag-ui/getting_started/client_advanced.py Updated AG-UI imports to use agent_framework.ag_ui
python/packages/ag-ui/getting_started/client.py Updated AG-UI imports to use agent_framework.ag_ui
python/packages/ag-ui/agent_framework_ag_ui_examples/server/main.py Updated AG-UI imports to use agent_framework.ag_ui
python/packages/ag-ui/agent_framework_ag_ui_examples/server/api/backend_tool_rendering.py Updated AG-UI imports to use agent_framework.ag_ui
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/weather_agent.py Updated ChatClientProtocol import to use public API
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/ui_generator_agent.py Updated both ChatClientProtocol and AG-UI imports
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/task_steps_agent.py Updated both ChatClientProtocol and AG-UI imports
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/task_planner_agent.py Updated both ChatClientProtocol and AG-UI imports
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/simple_agent.py Updated ChatClientProtocol import to use public API
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/research_assistant_agent.py Updated both ChatClientProtocol and AG-UI imports
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/recipe_agent.py Updated both ChatClientProtocol and AG-UI imports
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/human_in_the_loop_agent.py Updated ChatClientProtocol import to use public API
python/packages/ag-ui/agent_framework_ag_ui_examples/agents/document_writer_agent.py Updated both ChatClientProtocol and AG-UI imports
python/packages/ag-ui/agent_framework_ag_ui_examples/README.md Updated AG-UI imports in documentation examples
python/packages/ag-ui/README.md Updated AG-UI imports in documentation examples
Comments suppressed due to low confidence (1)

python/packages/core/agent_framework/ag_ui/init.pyi:15

  • The import path in this stub file is incorrect. This file is a type stub for re-exports from the separate agent_framework_ag_ui package, and should import from agent_framework_ag_ui, not from agent_framework.ag_ui (which would create a circular reference in the type system).

The import should be:

from agent_framework_ag_ui import (
    AgentFrameworkAgent,
    ...
)
from agent_framework.ag_ui import (
    AgentFrameworkAgent,
    AGUIChatClient,
    AGUIEventConverter,
    AGUIHttpService,
    ConfirmationStrategy,
    DefaultConfirmationStrategy,
    DocumentWriterConfirmationStrategy,
    RecipeConfirmationStrategy,
    TaskPlannerConfirmationStrategy,
    __version__,
    add_agent_framework_fastapi_endpoint,
)

brandonmcconnell and others added 4 commits November 19, 2025 01:54
…_errors.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…_callbacks.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azurefunctions/agent_framework_azurefunctions
   _callbacks.py120100% 
   _errors.py4250%10–11
packages/core/agent_framework
   observability.py6089883%238, 264–266, 268, 270–274, 282–283, 288–289, 294–299, 322–324, 326–327, 333, 417, 427, 449, 455, 474–476, 484–486, 509–511, 521–523, 656, 658, 745–749, 752–756, 765–768, 778–781, 783, 1050, 1198–1200, 1358, 1366, 1370, 1374, 1380, 1382, 1384, 1392, 1402, 1430–1431, 1444–1447, 1466–1468, 1470–1473, 1475–1476, 1480, 1483, 1541, 1557, 1561, 1695, 1697
packages/purview/agent_framework_purview
   _cache.py70592%80, 82–84, 86
   _client.py1191488%109, 128–131, 149, 177–178, 185, 189–190, 194–196
   _exceptions.py70100% 
   _middleware.py931188%68–70, 95, 97–99, 103, 163, 187, 191
   _processor.py1652286%160, 233, 236–240, 242, 244–245, 247–248, 266–267, 270–273, 275, 281, 283, 336
   _settings.py370100% 
TOTAL14982220785% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2041 127 💤 0 ❌ 0 🔥 39.744s ⏱️

@moonbox3 moonbox3 enabled auto-merge November 19, 2025 07:42
@moonbox3 moonbox3 added this pull request to the merge queue Nov 19, 2025
Merged via the queue into microsoft:main with commit 79bb870 Nov 19, 2025
24 checks passed
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
* chore: tidy imports

* Update python/packages/azurefunctions/agent_framework_azurefunctions/_errors.py

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

* Update python/packages/azurefunctions/agent_framework_azurefunctions/_callbacks.py

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

* chore: revert stub file change

* chore: trigger pre-commit hook, re-add `annotations` import

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants