Python: [BREAKING] Simplify API: ChatAgent -> Agent, ChatMessage -> Message (#3747)

* [BREAKING] Rename ChatAgent -> Agent, ChatMessage -> Message, ChatClientProtocol -> SupportsChatGetResponse

Simplify the public API by removing redundant 'Chat' prefix from core types:
- ChatAgent -> Agent
- RawChatAgent -> RawAgent
- ChatMessage -> Message
- ChatClientProtocol -> SupportsChatGetResponse

Also renamed internal WorkflowMessage (was Message in _runner_context) to avoid collision.

No backward compatibility aliases - this is a clean breaking change.

* [BREAKING] Rename Agent chat_client parameter to client

* Fix rebase issues: WorkflowMessage references and broken markdown links

* Fix formatting and lint issues from code quality checks

* Fix import ordering in workflow sample files

* fixed rebase

* Fix test failures: use WorkflowMessage and A2AMessage after ChatMessage→Message rename

- Replace Message(data=..., source_id=...) with WorkflowMessage(...) in workflow tests
- Fix isinstance check in A2A agent to use A2AMessage instead of Message
- Fix import in test_workflow_observability.py (Message→WorkflowMessage)

* Fix lint, fmt, and sample errors after ChatMessage→Message rename

- Auto-fix 70+ ruff lint issues across samples (ChatMessage→Message refs)
- Fix HostedVectorStoreContent→Content.from_hosted_vector_store in file search sample
- Fix _normalize_messages→normalize_messages in custom agent sample
- Fix context.terminate→raise MiddlewareTermination in middleware samples
- Fix with_update_hook→with_transform_hook in override middleware sample
- Add TOptions_co import back to custom_chat_client sample
- Add noqa for FastAPI File() default in chatkit sample
- Fix B023 loop variable capture in weather agent sample

* fix: update Agent constructor calls from chat_client to client in declaration-only tool tests

* fix: add register_cleanup to devui lazy-loading proxy and type stub

* fixed tests and updated new pieces

* fix agui typevar

* fix merge errors

* fix merge conflicts

* fiux merge

* Remove unused links

---------

Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
This commit is contained in:
Eduard van Valkenburg
2026-02-11 00:04:32 +01:00
committed by GitHub
Unverified
parent a4c9e43afb
commit 0521f5bed8
418 changed files with 5385 additions and 5389 deletions
@@ -4,7 +4,7 @@
Tests include:
- Entity discovery and info retrieval
- Agent execution (sync and streaming) using real ChatAgent with mock LLM
- Agent execution (sync and streaming) using real Agent with mock LLM
- Workflow execution using real WorkflowBuilder with FunctionExecutor
- Edge cases like non-streaming agents
"""
@@ -15,7 +15,7 @@ from pathlib import Path
from typing import Any
import pytest
from agent_framework import AgentExecutor, ChatAgent, FunctionExecutor, WorkflowBuilder
from agent_framework import Agent, AgentExecutor, FunctionExecutor, WorkflowBuilder
# Import mock classes from conftest for direct use in some tests
from conftest import MockBaseChatClient
@@ -77,15 +77,15 @@ async def test_executor_get_entity_info(executor):
# =============================================================================
# Agent Execution Tests (using real ChatAgent with mock LLM)
# Agent Execution Tests (using real Agent with mock LLM)
# =============================================================================
async def test_agent_sync_execution(executor_with_real_agent):
"""Test synchronous agent execution with REAL ChatAgent (mock LLM).
"""Test synchronous agent execution with REAL Agent (mock LLM).
This tests the full execution pipeline without needing an API key:
- Real ChatAgent class with middleware
- Real Agent class with middleware
- Real message normalization
- Mock chat client for LLM calls
"""
@@ -130,7 +130,7 @@ async def test_agent_sync_execution_respects_model_field(executor_with_real_agen
async def test_chat_client_receives_correct_messages(executor_with_real_agent):
"""Verify the mock chat client receives properly formatted messages.
This tests that the REAL ChatAgent properly:
This tests that the REAL Agent properly:
- Normalizes input messages
- Formats messages for the chat client
"""
@@ -297,18 +297,18 @@ async def test_full_pipeline_workflow_events_are_json_serializable():
This is particularly important for workflows with AgentExecutor because:
- AgentExecutor produces executor_completed event (type='executor_completed') with AgentExecutorResponse
- AgentExecutorResponse contains AgentResponse and ChatMessage objects
- AgentExecutorResponse contains AgentResponse and Message objects
- These are SerializationMixin objects, not Pydantic, which caused the original bug
This test ensures the ENTIRE streaming pipeline works end-to-end.
"""
# Create a workflow with AgentExecutor (the problematic case)
mock_client = MockBaseChatClient()
agent = ChatAgent(
agent = Agent(
id="serialization_test_agent",
name="Serialization Test Agent",
description="Agent for testing serialization",
chat_client=mock_client,
client=mock_client,
system_message="You are a test assistant.",
)
@@ -466,15 +466,15 @@ async def test_executor_parse_raw_string_for_string_workflow():
@pytest.mark.asyncio
async def test_executor_parse_converts_to_chat_message_for_sequential_workflow(sequential_workflow):
"""Sequential workflows convert string input to ChatMessage."""
from agent_framework import ChatMessage
"""Sequential workflows convert string input to Message."""
from agent_framework import Message
executor, _entity_id, _mock_client, workflow = sequential_workflow
# Sequential workflows expect ChatMessage, so raw string becomes ChatMessage
# Sequential workflows expect Message, so raw string becomes Message
parsed = executor._parse_raw_workflow_input(workflow, "hello")
assert isinstance(parsed, ChatMessage)
assert isinstance(parsed, Message)
assert parsed.text == "hello"
@@ -538,7 +538,7 @@ def test_extract_workflow_hil_responses_handles_stringified_json():
async def test_executor_handles_streaming_agent():
"""Test executor handles agents with run(stream=True) method."""
from agent_framework import AgentResponse, AgentResponseUpdate, AgentThread, ChatMessage, Content
from agent_framework import AgentResponse, AgentResponseUpdate, AgentThread, Content, Message
class StreamingAgent:
"""Agent with run() method supporting stream parameter."""
@@ -556,7 +556,7 @@ async def test_executor_handles_streaming_agent():
async def _run_impl(self, messages):
return AgentResponse(
messages=[ChatMessage(role="assistant", contents=[Content.from_text(text=f"Processed: {messages}")])],
messages=[Message(role="assistant", contents=[Content.from_text(text=f"Processed: {messages}")])],
response_id="test_123",
)