Python: [BREAKING] Renamed AgentProtocol to SupportsAgentRun (#3717)

* Renamed AgentProtocol to AgentLike

* Resolved comments

* Renamed AgentLike to SupportsAgentRun

* Resolved comments
This commit is contained in:
Dmytro Struk
2026-02-06 09:53:21 -08:00
committed by GitHub
Unverified
parent ac17adb595
commit 15256bb616
55 changed files with 354 additions and 354 deletions
@@ -6,7 +6,7 @@ from collections.abc import AsyncGenerator
from typing import Any, cast
from ag_ui.core import BaseEvent
from agent_framework import AgentProtocol
from agent_framework import SupportsAgentRun
from ._run import run_agent_stream
@@ -65,13 +65,13 @@ class AgentConfig:
class AgentFrameworkAgent:
"""Wraps Agent Framework agents for AG-UI protocol compatibility.
Translates between Agent Framework's AgentProtocol and AG-UI's event-based
Translates between Agent Framework's SupportsAgentRun and AG-UI's event-based
protocol. Follows a simple linear flow: RunStarted -> content events -> RunFinished.
"""
def __init__(
self,
agent: AgentProtocol,
agent: SupportsAgentRun,
name: str | None = None,
description: str | None = None,
state_schema: Any | None = None,
@@ -8,7 +8,7 @@ from collections.abc import AsyncGenerator, Sequence
from typing import Any
from ag_ui.encoder import EventEncoder
from agent_framework import AgentProtocol
from agent_framework import SupportsAgentRun
from fastapi import FastAPI
from fastapi.params import Depends
from fastapi.responses import StreamingResponse
@@ -21,7 +21,7 @@ logger = logging.getLogger(__name__)
def add_agent_framework_fastapi_endpoint(
app: FastAPI,
agent: AgentProtocol | AgentFrameworkAgent,
agent: SupportsAgentRun | AgentFrameworkAgent,
path: str = "/",
state_schema: Any | None = None,
predict_state_config: dict[str, dict[str, str]] | None = None,
@@ -34,7 +34,7 @@ def add_agent_framework_fastapi_endpoint(
Args:
app: The FastAPI application
agent: The agent to expose (can be raw AgentProtocol or wrapped)
agent: The agent to expose (can be raw SupportsAgentRun or wrapped)
path: The endpoint path
state_schema: Optional state schema for shared state management; accepts dict or Pydantic model/class
predict_state_config: Optional predictive state update configuration.
@@ -47,7 +47,7 @@ def add_agent_framework_fastapi_endpoint(
authentication checks, rate limiting, or other middleware-like behavior.
Example: `dependencies=[Depends(verify_api_key)]`
"""
if isinstance(agent, AgentProtocol):
if isinstance(agent, SupportsAgentRun):
wrapped_agent = AgentFrameworkAgent(
agent=agent,
state_schema=state_schema,
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any
from agent_framework import BaseChatClient
if TYPE_CHECKING:
from agent_framework import AgentProtocol
from agent_framework import SupportsAgentRun
logger = logging.getLogger(__name__)
@@ -29,7 +29,7 @@ def _collect_mcp_tool_functions(mcp_tools: list[Any]) -> list[Any]:
return functions
def collect_server_tools(agent: "AgentProtocol") -> list[Any]:
def collect_server_tools(agent: "SupportsAgentRun") -> list[Any]:
"""Collect server tools from an agent.
This includes both regular tools from default_options and MCP tools.
@@ -64,7 +64,7 @@ def collect_server_tools(agent: "AgentProtocol") -> list[Any]:
return server_tools
def register_additional_client_tools(agent: "AgentProtocol", client_tools: list[Any] | None) -> None:
def register_additional_client_tools(agent: "SupportsAgentRun", client_tools: list[Any] | None) -> None:
"""Register client tools as additional declaration-only tools to avoid server execution.
Args:
@@ -25,10 +25,10 @@ from ag_ui.core import (
ToolCallStartEvent,
)
from agent_framework import (
AgentProtocol,
AgentThread,
ChatMessage,
Content,
SupportsAgentRun,
prepare_function_call_results,
)
from agent_framework._middleware import FunctionMiddlewarePipeline
@@ -579,7 +579,7 @@ def _handle_step_based_approval(messages: list[Any]) -> list[BaseEvent]:
async def _resolve_approval_responses(
messages: list[Any],
tools: list[Any],
agent: AgentProtocol,
agent: SupportsAgentRun,
run_kwargs: dict[str, Any],
) -> None:
"""Execute approved function calls and replace approval content with results.
@@ -741,7 +741,7 @@ def _build_messages_snapshot(
async def run_agent_stream(
input_data: dict[str, Any],
agent: AgentProtocol,
agent: SupportsAgentRun,
config: "AgentConfig",
) -> "AsyncGenerator[BaseEvent, None]":
"""Run agent and yield AG-UI events.
@@ -9,7 +9,6 @@ from typing import Any, Generic, Literal, cast, overload
import pytest
from agent_framework import (
AgentProtocol,
AgentResponse,
AgentResponseUpdate,
AgentThread,
@@ -20,6 +19,7 @@ from agent_framework import (
ChatResponse,
ChatResponseUpdate,
Content,
SupportsAgentRun,
)
from agent_framework._clients import TOptions_co
from agent_framework._middleware import ChatMiddlewareLayer
@@ -149,8 +149,8 @@ def stream_from_updates(updates: list[ChatResponseUpdate]) -> StreamFn:
return _stream
class StubAgent(AgentProtocol):
"""Minimal AgentProtocol stub for orchestrator tests."""
class StubAgent(SupportsAgentRun):
"""Minimal SupportsAgentRun stub for orchestrator tests."""
def __init__(
self,
@@ -238,6 +238,6 @@ def stream_from_updates_fixture() -> Callable[[list[ChatResponseUpdate]], Stream
@pytest.fixture
def stub_agent() -> type[AgentProtocol]:
def stub_agent() -> type[SupportsAgentRun]:
"""Return the StubAgent class for creating test instances."""
return StubAgent # type: ignore[return-value]
@@ -26,7 +26,7 @@ def build_chat_client(streaming_chat_client_stub, stream_from_updates_fixture):
async def test_add_endpoint_with_agent_protocol(build_chat_client):
"""Test adding endpoint with raw AgentProtocol."""
"""Test adding endpoint with raw SupportsAgentRun."""
app = FastAPI()
agent = ChatAgent(name="test", instructions="Test agent", chat_client=build_chat_client())