mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Redesign Python exception hierarchy (#4082)
* [BREAKING] Redesign Python exception hierarchy Replace the flat ServiceException family with domain-scoped branches: - AgentException (with InvalidAuth, InvalidRequest, InvalidResponse, ContentFilter) - ChatClientException (same consistent suberrors) - IntegrationException (same + InitializationError) - WorkflowException (Runner, Convergence, Checkpoint, Validation, Action, Declarative) - ContentError (AdditionItemMismatch) - ToolException / ToolExecutionException (unchanged) - MiddlewareException / MiddlewareTermination (unchanged) Key changes: - All Service* exceptions removed (ServiceException, ServiceInitializationError, etc.) - AgentExecutionException split into AgentInvalidRequest/ResponseException - AgentInvocationError removed, split into AgentInvalidRequest/ResponseException - Workflow exceptions moved from _workflows/_exceptions.py into main exceptions.py - _workflows/__init__.py emptied; main __init__.py imports directly from submodules - Purview exceptions re-parented under IntegrationException hierarchy - Init validation errors use built-in ValueError/TypeError instead of custom exceptions - CODING_STANDARD.md updated with hierarchy design and rationale Fixes microsoft/agent-framework#3410 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Clarify ToolException vs ToolExecutionException docstrings ToolException: base class for all tool-related exceptions (preconditions, connection/init failures). ToolExecutionException: runtime call failures (tool call failed, reconnect failed, MCP errors). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix remaining stale imports from agent_framework._workflows - azurefunctions: _context.py, _app.py, _serialization.py, test_func_utils.py used 'from agent_framework._workflows import X' which broke after emptying _workflows/__init__.py; changed to direct submodule imports - azure-ai-search: test still referenced ServiceInitializationError; updated to ValueError to match production code Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
7f606a2e3a
commit
5ee06853a1
@@ -40,7 +40,7 @@ from agent_framework._tools import (
|
||||
normalize_function_invocation_configuration,
|
||||
)
|
||||
from agent_framework._types import ResponseStream
|
||||
from agent_framework.exceptions import AgentExecutionException
|
||||
from agent_framework.exceptions import AgentInvalidResponseException
|
||||
|
||||
from ._message_adapters import normalize_agui_input_messages
|
||||
from ._orchestration._predictive_state import PredictiveStateHandler
|
||||
@@ -207,7 +207,7 @@ async def _normalize_response_stream(response_stream: Any) -> AsyncIterable[Any]
|
||||
if isinstance(resolved_stream, AsyncIterable):
|
||||
return cast(AsyncIterable[Any], resolved_stream)
|
||||
resolved_type = f"{type(resolved_stream).__module__}.{type(resolved_stream).__name__}"
|
||||
raise AgentExecutionException(
|
||||
raise AgentInvalidResponseException(
|
||||
"Agent did not return a streaming AsyncIterable response. "
|
||||
f"Awaitable resolved to unsupported type: {resolved_type}."
|
||||
)
|
||||
@@ -220,7 +220,7 @@ async def _normalize_response_stream(response_stream: Any) -> AsyncIterable[Any]
|
||||
return cast(AsyncIterable[Any], response_stream)
|
||||
|
||||
stream_type = f"{type(response_stream).__module__}.{type(response_stream).__name__}"
|
||||
raise AgentExecutionException(
|
||||
raise AgentInvalidResponseException(
|
||||
f"Agent did not return a streaming AsyncIterable response. Received unsupported type: {stream_type}."
|
||||
)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from ag_ui.core import (
|
||||
TextMessageStartEvent,
|
||||
)
|
||||
from agent_framework import AgentResponseUpdate, Content, Message, ResponseStream
|
||||
from agent_framework.exceptions import AgentExecutionException
|
||||
from agent_framework.exceptions import AgentInvalidResponseException
|
||||
|
||||
from agent_framework_ag_ui._run import (
|
||||
FlowState,
|
||||
@@ -226,7 +226,7 @@ class TestNormalizeResponseStream:
|
||||
|
||||
async def test_rejects_non_stream_values(self):
|
||||
"""Reject unsupported stream return values."""
|
||||
with pytest.raises(AgentExecutionException):
|
||||
with pytest.raises(AgentInvalidResponseException):
|
||||
await _normalize_response_stream("not-a-stream")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user