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
@@ -9,8 +9,8 @@ from agent_framework import (
|
||||
AgentExecutorResponse,
|
||||
AgentResponse,
|
||||
AgentResponseUpdate,
|
||||
ChatMessage,
|
||||
Executor,
|
||||
Message,
|
||||
WorkflowBuilder,
|
||||
WorkflowContext,
|
||||
WorkflowEvent,
|
||||
@@ -47,7 +47,7 @@ class DraftFeedbackRequest:
|
||||
"""Payload sent for human review."""
|
||||
|
||||
prompt: str = ""
|
||||
conversation: list[ChatMessage] = field(default_factory=lambda: [])
|
||||
conversation: list[Message] = field(default_factory=lambda: [])
|
||||
|
||||
|
||||
class Coordinator(Executor):
|
||||
@@ -71,7 +71,7 @@ class Coordinator(Executor):
|
||||
|
||||
# Writer agent response; request human feedback.
|
||||
# Preserve the full conversation so that the final editor has context.
|
||||
conversation: list[ChatMessage]
|
||||
conversation: list[Message]
|
||||
if draft.full_conversation is not None:
|
||||
conversation = list(draft.full_conversation)
|
||||
else:
|
||||
@@ -100,7 +100,7 @@ class Coordinator(Executor):
|
||||
# Human approved the draft as-is; forward it unchanged.
|
||||
await ctx.send_message(
|
||||
AgentExecutorRequest(
|
||||
messages=original_request.conversation + [ChatMessage("user", text="The draft is approved as-is.")],
|
||||
messages=original_request.conversation + [Message("user", text="The draft is approved as-is.")],
|
||||
should_respond=True,
|
||||
),
|
||||
target_id=self.final_editor_name,
|
||||
@@ -108,14 +108,14 @@ class Coordinator(Executor):
|
||||
return
|
||||
|
||||
# Human provided feedback; prompt the writer to revise.
|
||||
conversation: list[ChatMessage] = list(original_request.conversation)
|
||||
conversation: list[Message] = list(original_request.conversation)
|
||||
instruction = (
|
||||
"A human reviewer shared the following guidance:\n"
|
||||
f"{note or 'No specific guidance provided.'}\n\n"
|
||||
"Rewrite the draft from the previous assistant message into a polished final version. "
|
||||
"Keep the response under 120 words and reflect any requested tone adjustments."
|
||||
)
|
||||
conversation.append(ChatMessage("user", text=instruction))
|
||||
conversation.append(Message("user", text=instruction))
|
||||
await ctx.send_message(
|
||||
AgentExecutorRequest(messages=conversation, should_respond=True), target_id=self.writer_name
|
||||
)
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ from typing import Any
|
||||
|
||||
from agent_framework import (
|
||||
AgentExecutorResponse,
|
||||
ChatMessage,
|
||||
Message,
|
||||
WorkflowEvent,
|
||||
)
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
@@ -76,7 +76,7 @@ async def aggregate_with_synthesis(results: list[AgentExecutorResponse]) -> Any:
|
||||
# Build prompt with human guidance if provided
|
||||
guidance_text = f"\n\nHuman guidance: {human_guidance}" if human_guidance else ""
|
||||
|
||||
system_msg = ChatMessage(
|
||||
system_msg = Message(
|
||||
"system",
|
||||
text=(
|
||||
"You are a synthesis expert. Consolidate the following analyst perspectives "
|
||||
@@ -84,7 +84,7 @@ async def aggregate_with_synthesis(results: list[AgentExecutorResponse]) -> Any:
|
||||
"prioritize aspects as directed."
|
||||
),
|
||||
)
|
||||
user_msg = ChatMessage("user", text="\n\n".join(expert_sections) + guidance_text)
|
||||
user_msg = Message("user", text="\n\n".join(expert_sections) + guidance_text)
|
||||
|
||||
response = await _chat_client.get_response([system_msg, user_msg])
|
||||
return response.messages[-1].text if response.messages else ""
|
||||
|
||||
+7
-7
@@ -28,7 +28,7 @@ from typing import cast
|
||||
|
||||
from agent_framework import (
|
||||
AgentExecutorResponse,
|
||||
ChatMessage,
|
||||
Message,
|
||||
WorkflowEvent,
|
||||
)
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
@@ -51,7 +51,7 @@ async def process_event_stream(stream: AsyncIterable[WorkflowEvent]) -> dict[str
|
||||
print("=" * 60)
|
||||
print("Final discussion summary:")
|
||||
# To make the type checker happy, we cast event.data to the expected type
|
||||
outputs = cast(list[ChatMessage], event.data)
|
||||
outputs = cast(list[Message], event.data)
|
||||
for msg in outputs:
|
||||
speaker = msg.author_name or msg.role
|
||||
print(f"[{speaker}]: {msg.text}")
|
||||
@@ -91,10 +91,10 @@ async def process_event_stream(stream: AsyncIterable[WorkflowEvent]) -> dict[str
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create agents for a group discussion
|
||||
optimist = chat_client.as_agent(
|
||||
optimist = client.as_agent(
|
||||
name="optimist",
|
||||
instructions=(
|
||||
"You are an optimistic team member. You see opportunities and potential "
|
||||
@@ -103,7 +103,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
pragmatist = chat_client.as_agent(
|
||||
pragmatist = client.as_agent(
|
||||
name="pragmatist",
|
||||
instructions=(
|
||||
"You are a pragmatic team member. You focus on practical implementation "
|
||||
@@ -112,7 +112,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
creative = chat_client.as_agent(
|
||||
creative = client.as_agent(
|
||||
name="creative",
|
||||
instructions=(
|
||||
"You are a creative team member. You propose innovative solutions and "
|
||||
@@ -122,7 +122,7 @@ async def main() -> None:
|
||||
)
|
||||
|
||||
# Orchestrator coordinates the discussion
|
||||
orchestrator = chat_client.as_agent(
|
||||
orchestrator = client.as_agent(
|
||||
name="orchestrator",
|
||||
instructions=(
|
||||
"You are a discussion manager coordinating a team conversation between participants. "
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ from agent_framework import (
|
||||
AgentExecutorRequest,
|
||||
AgentExecutorResponse,
|
||||
AgentResponseUpdate,
|
||||
ChatMessage,
|
||||
Executor,
|
||||
Message,
|
||||
WorkflowBuilder,
|
||||
WorkflowContext,
|
||||
WorkflowEvent,
|
||||
@@ -84,7 +84,7 @@ class TurnManager(Executor):
|
||||
- Input is a simple starter token (ignored here).
|
||||
- Output is an AgentExecutorRequest that triggers the agent to produce a guess.
|
||||
"""
|
||||
user = ChatMessage("user", text="Start by making your first guess.")
|
||||
user = Message("user", text="Start by making your first guess.")
|
||||
await ctx.send_message(AgentExecutorRequest(messages=[user], should_respond=True))
|
||||
|
||||
@handler
|
||||
@@ -136,7 +136,7 @@ class TurnManager(Executor):
|
||||
f"Feedback: {reply}. Your last guess was {last_guess}. "
|
||||
f"Use this feedback to adjust and make your next guess (1-10)."
|
||||
)
|
||||
user_msg = ChatMessage("user", text=feedback_text)
|
||||
user_msg = Message("user", text=feedback_text)
|
||||
await ctx.send_message(AgentExecutorRequest(messages=[user_msg], should_respond=True))
|
||||
|
||||
|
||||
|
||||
+6
-6
@@ -27,7 +27,7 @@ from typing import cast
|
||||
|
||||
from agent_framework import (
|
||||
AgentExecutorResponse,
|
||||
ChatMessage,
|
||||
Message,
|
||||
WorkflowEvent,
|
||||
)
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
@@ -49,7 +49,7 @@ async def process_event_stream(stream: AsyncIterable[WorkflowEvent]) -> dict[str
|
||||
print("WORKFLOW COMPLETE")
|
||||
print("=" * 60)
|
||||
print("Final output:")
|
||||
outputs = cast(list[ChatMessage], event.data)
|
||||
outputs = cast(list[Message], event.data)
|
||||
for message in outputs:
|
||||
print(f"[{message.author_name or message.role}]: {message.text}")
|
||||
|
||||
@@ -88,15 +88,15 @@ async def process_event_stream(stream: AsyncIterable[WorkflowEvent]) -> dict[str
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
# Create agents for a sequential document review workflow
|
||||
drafter = chat_client.as_agent(
|
||||
drafter = client.as_agent(
|
||||
name="drafter",
|
||||
instructions=("You are a document drafter. When given a topic, create a brief draft (2-3 sentences)."),
|
||||
)
|
||||
|
||||
editor = chat_client.as_agent(
|
||||
editor = client.as_agent(
|
||||
name="editor",
|
||||
instructions=(
|
||||
"You are an editor. Review the draft and make improvements. "
|
||||
@@ -104,7 +104,7 @@ async def main() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
finalizer = chat_client.as_agent(
|
||||
finalizer = client.as_agent(
|
||||
name="finalizer",
|
||||
instructions=(
|
||||
"You are a finalizer. Take the edited content and create a polished final version. "
|
||||
|
||||
Reference in New Issue
Block a user