mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
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:
committed by
GitHub
Unverified
parent
a4c9e43afb
commit
0521f5bed8
@@ -4,7 +4,7 @@ import asyncio
|
||||
from random import randrange
|
||||
from typing import TYPE_CHECKING, Annotated, Any
|
||||
|
||||
from agent_framework import AgentResponse, ChatAgent, ChatMessage, tool
|
||||
from agent_framework import Agent, AgentResponse, Message, tool
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -59,14 +59,14 @@ async def handle_approvals(query: str, agent: "SupportsAgentRun") -> AgentRespon
|
||||
)
|
||||
|
||||
# Add the assistant message with the approval request
|
||||
new_inputs.append(ChatMessage("assistant", [user_input_needed]))
|
||||
new_inputs.append(Message("assistant", [user_input_needed]))
|
||||
|
||||
# Get user approval
|
||||
user_approval = await asyncio.to_thread(input, "\nApprove function call? (y/n): ")
|
||||
|
||||
# Add the user's approval response
|
||||
new_inputs.append(
|
||||
ChatMessage("user", [user_input_needed.to_function_approval_response(user_approval.lower() == "y")])
|
||||
Message("user", [user_input_needed.to_function_approval_response(user_approval.lower() == "y")])
|
||||
)
|
||||
|
||||
# Run again with all the context
|
||||
@@ -109,14 +109,14 @@ async def handle_approvals_streaming(query: str, agent: "SupportsAgentRun") -> N
|
||||
)
|
||||
|
||||
# Add the assistant message with the approval request
|
||||
new_inputs.append(ChatMessage("assistant", [user_input_needed]))
|
||||
new_inputs.append(Message("assistant", [user_input_needed]))
|
||||
|
||||
# Get user approval
|
||||
user_approval = await asyncio.to_thread(input, "\nApprove function call? (y/n): ")
|
||||
|
||||
# Add the user's approval response
|
||||
new_inputs.append(
|
||||
ChatMessage("user", [user_input_needed.to_function_approval_response(user_approval.lower() == "y")])
|
||||
Message("user", [user_input_needed.to_function_approval_response(user_approval.lower() == "y")])
|
||||
)
|
||||
|
||||
# Update input with all the context for next iteration
|
||||
@@ -127,8 +127,8 @@ async def run_weather_agent_with_approval(stream: bool) -> None:
|
||||
"""Example showing AI function with approval requirement."""
|
||||
print(f"\n=== Weather Agent with Approval Required ({'Streaming' if stream else 'Non-Streaming'}) ===\n")
|
||||
|
||||
async with ChatAgent(
|
||||
chat_client=OpenAIResponsesClient(),
|
||||
async with Agent(
|
||||
client=OpenAIResponsesClient(),
|
||||
name="WeatherAgent",
|
||||
instructions=("You are a helpful weather assistant. Use the get_weather tool to provide weather information."),
|
||||
tools=[get_weather, get_weather_detail],
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import asyncio
|
||||
from typing import Annotated
|
||||
|
||||
from agent_framework import ChatAgent, ChatMessage, tool
|
||||
from agent_framework import Agent, Message, tool
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
|
||||
"""
|
||||
@@ -28,8 +28,8 @@ async def approval_example() -> None:
|
||||
"""Example showing approval with threads."""
|
||||
print("=== Tool Approval with Thread ===\n")
|
||||
|
||||
agent = ChatAgent(
|
||||
chat_client=AzureOpenAIChatClient(),
|
||||
agent = Agent(
|
||||
client=AzureOpenAIChatClient(),
|
||||
name="CalendarAgent",
|
||||
instructions="You are a helpful calendar assistant.",
|
||||
tools=[add_to_calendar],
|
||||
@@ -55,7 +55,7 @@ async def approval_example() -> None:
|
||||
|
||||
# Step 2: Send approval response
|
||||
approval_response = request.to_function_approval_response(approved=approved)
|
||||
result = await agent.run(ChatMessage("user", [approval_response]), thread=thread)
|
||||
result = await agent.run(Message("user", [approval_response]), thread=thread)
|
||||
|
||||
print(f"Agent: {result}\n")
|
||||
|
||||
@@ -64,8 +64,8 @@ async def rejection_example() -> None:
|
||||
"""Example showing rejection with threads."""
|
||||
print("=== Tool Rejection with Thread ===\n")
|
||||
|
||||
agent = ChatAgent(
|
||||
chat_client=AzureOpenAIChatClient(),
|
||||
agent = Agent(
|
||||
client=AzureOpenAIChatClient(),
|
||||
name="CalendarAgent",
|
||||
instructions="You are a helpful calendar assistant.",
|
||||
tools=[add_to_calendar],
|
||||
@@ -88,7 +88,7 @@ async def rejection_example() -> None:
|
||||
|
||||
# Send rejection response
|
||||
rejection_response = request.to_function_approval_response(approved=False)
|
||||
result = await agent.run(ChatMessage("user", [rejection_response]), thread=thread)
|
||||
result = await agent.run(Message("user", [rejection_response]), thread=thread)
|
||||
|
||||
print(f"Agent: {result}\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user