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
@@ -1,6 +1,6 @@
## Purview Policy Enforcement Sample (Python)
This getting-started sample shows how to attach Microsoft Purview policy evaluation to an Agent Framework `ChatAgent` using the **middleware** approach.
This getting-started sample shows how to attach Microsoft Purview policy evaluation to an Agent Framework `Agent` using the **middleware** approach.
**What this sample demonstrates:**
1. Configure an Azure OpenAI chat client
@@ -99,8 +99,8 @@ Prompt blocks set a system-level message: `Prompt blocked by policy` and termina
### Agent Middleware Injection
```python
agent = ChatAgent(
chat_client=chat_client,
agent = Agent(
client=client,
instructions="You are good at telling jokes.",
name="Joker",
middleware=[
@@ -25,7 +25,7 @@ import asyncio
import os
from typing import Any
from agent_framework import AgentResponse, ChatAgent, ChatMessage
from agent_framework import Agent, AgentResponse, Message
from agent_framework.azure import AzureOpenAIChatClient
from agent_framework.microsoft import (
PurviewChatPolicyMiddleware,
@@ -141,7 +141,7 @@ async def run_with_agent_middleware() -> None:
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", "gpt-4o-mini")
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
chat_client = AzureOpenAIChatClient(deployment_name=deployment, endpoint=endpoint, credential=AzureCliCredential())
client = AzureOpenAIChatClient(deployment_name=deployment, endpoint=endpoint, credential=AzureCliCredential())
purview_agent_middleware = PurviewPolicyMiddleware(
build_credential(),
@@ -150,8 +150,8 @@ async def run_with_agent_middleware() -> None:
),
)
agent = ChatAgent(
chat_client=chat_client,
agent = Agent(
client=client,
instructions=JOKER_INSTRUCTIONS,
name=JOKER_NAME,
middleware=[purview_agent_middleware],
@@ -159,12 +159,12 @@ async def run_with_agent_middleware() -> None:
print("-- Agent MiddlewareTypes Path --")
first: AgentResponse = await agent.run(
ChatMessage("user", ["Tell me a joke about a pirate."], additional_properties={"user_id": user_id})
Message("user", ["Tell me a joke about a pirate."], additional_properties={"user_id": user_id})
)
print("First response (agent middleware):\n", first)
second: AgentResponse = await agent.run(
ChatMessage(
Message(
role="user", text="That was funny. Tell me another one.", additional_properties={"user_id": user_id}
)
)
@@ -180,7 +180,7 @@ async def run_with_chat_middleware() -> None:
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", default="gpt-4o-mini")
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
chat_client = AzureOpenAIChatClient(
client = AzureOpenAIChatClient(
deployment_name=deployment,
endpoint=endpoint,
credential=AzureCliCredential(),
@@ -194,15 +194,15 @@ async def run_with_chat_middleware() -> None:
],
)
agent = ChatAgent(
chat_client=chat_client,
agent = Agent(
client=client,
instructions=JOKER_INSTRUCTIONS,
name=JOKER_NAME,
)
print("-- Chat MiddlewareTypes Path --")
first: AgentResponse = await agent.run(
ChatMessage(
Message(
role="user",
text="Give me a short clean joke.",
additional_properties={"user_id": user_id},
@@ -211,7 +211,7 @@ async def run_with_chat_middleware() -> None:
print("First response (chat middleware):\n", first)
second: AgentResponse = await agent.run(
ChatMessage(
Message(
role="user",
text="One more please.",
additional_properties={"user_id": user_id},
@@ -229,7 +229,7 @@ async def run_with_custom_cache_provider() -> None:
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", "gpt-4o-mini")
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
chat_client = AzureOpenAIChatClient(deployment_name=deployment, endpoint=endpoint, credential=AzureCliCredential())
client = AzureOpenAIChatClient(deployment_name=deployment, endpoint=endpoint, credential=AzureCliCredential())
custom_cache = SimpleDictCacheProvider()
@@ -241,8 +241,8 @@ async def run_with_custom_cache_provider() -> None:
cache_provider=custom_cache,
)
agent = ChatAgent(
chat_client=chat_client,
agent = Agent(
client=client,
instructions=JOKER_INSTRUCTIONS,
name=JOKER_NAME,
middleware=[purview_agent_middleware],
@@ -252,14 +252,14 @@ async def run_with_custom_cache_provider() -> None:
print("Using SimpleDictCacheProvider")
first: AgentResponse = await agent.run(
ChatMessage(
Message(
role="user", text="Tell me a joke about a programmer.", additional_properties={"user_id": user_id}
)
)
print("First response (custom provider):\n", first)
second: AgentResponse = await agent.run(
ChatMessage("user", ["That's hilarious! One more?"], additional_properties={"user_id": user_id})
Message("user", ["That's hilarious! One more?"], additional_properties={"user_id": user_id})
)
print("Second response (custom provider):\n", second)
@@ -271,7 +271,7 @@ async def run_with_custom_cache_provider() -> None:
deployment = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME", "gpt-4o-mini")
user_id = os.environ.get("PURVIEW_DEFAULT_USER_ID")
chat_client = AzureOpenAIChatClient(deployment_name=deployment, endpoint=endpoint, credential=AzureCliCredential())
client = AzureOpenAIChatClient(deployment_name=deployment, endpoint=endpoint, credential=AzureCliCredential())
# No cache_provider specified - uses default InMemoryCacheProvider
purview_agent_middleware = PurviewPolicyMiddleware(
@@ -283,8 +283,8 @@ async def run_with_custom_cache_provider() -> None:
),
)
agent = ChatAgent(
chat_client=chat_client,
agent = Agent(
client=client,
instructions=JOKER_INSTRUCTIONS,
name=JOKER_NAME,
middleware=[purview_agent_middleware],
@@ -294,12 +294,12 @@ async def run_with_custom_cache_provider() -> None:
print("Using default InMemoryCacheProvider with settings-based configuration")
first: AgentResponse = await agent.run(
ChatMessage("user", ["Tell me a joke about AI."], additional_properties={"user_id": user_id})
Message("user", ["Tell me a joke about AI."], additional_properties={"user_id": user_id})
)
print("First response (default cache):\n", first)
second: AgentResponse = await agent.run(
ChatMessage("user", ["Nice! Another AI joke please."], additional_properties={"user_id": user_id})
Message("user", ["Nice! Another AI joke please."], additional_properties={"user_id": user_id})
)
print("Second response (default cache):\n", second)