mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Renamed create_agent to as_agent (#3249)
* Renamed create_agent to as_agent * Override for as_agent * Added override
This commit is contained in:
committed by
GitHub
Unverified
parent
a151f10cc2
commit
5687e13221
@@ -27,7 +27,7 @@ Prerequisites:
|
||||
|
||||
|
||||
def create_writer_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
return client.create_agent(
|
||||
return client.as_agent(
|
||||
name="Writer",
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
@@ -36,7 +36,7 @@ def create_writer_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
|
||||
|
||||
def create_reviewer_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
return client.create_agent(
|
||||
return client.as_agent(
|
||||
name="Reviewer",
|
||||
instructions=(
|
||||
"You are an excellent content reviewer. "
|
||||
|
||||
+2
-2
@@ -87,7 +87,7 @@ async def enrich_with_references(
|
||||
|
||||
|
||||
def create_research_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="research_agent",
|
||||
instructions=(
|
||||
"Produce a short, bullet-style briefing with two actionable ideas. Label the section as 'Initial Draft'."
|
||||
@@ -96,7 +96,7 @@ def create_research_agent():
|
||||
|
||||
|
||||
def create_final_editor_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="final_editor_agent",
|
||||
instructions=(
|
||||
"Use all conversation context (including external notes) to produce the final answer. "
|
||||
|
||||
@@ -27,7 +27,7 @@ Prerequisites:
|
||||
|
||||
|
||||
def create_writer_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
),
|
||||
@@ -36,7 +36,7 @@ def create_writer_agent():
|
||||
|
||||
|
||||
def create_reviewer_agent():
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content reviewer."
|
||||
"Provide actionable feedback to the writer about the provided content."
|
||||
|
||||
+2
-2
@@ -168,7 +168,7 @@ class Coordinator(Executor):
|
||||
|
||||
def create_writer_agent() -> ChatAgent:
|
||||
"""Creates a writer agent with tools."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="writer_agent",
|
||||
instructions=(
|
||||
"You are a marketing writer. Call the available tools before drafting copy so you are precise. "
|
||||
@@ -182,7 +182,7 @@ def create_writer_agent() -> ChatAgent:
|
||||
|
||||
def create_final_editor_agent() -> ChatAgent:
|
||||
"""Creates a final editor agent."""
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
name="final_editor_agent",
|
||||
instructions=(
|
||||
"You are an editor who polishes marketing copy after human approval. "
|
||||
|
||||
@@ -28,7 +28,7 @@ async def main() -> None:
|
||||
# 1) Create three domain agents using AzureOpenAIChatClient
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
researcher = chat_client.create_agent(
|
||||
researcher = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're an expert market and product researcher. Given a prompt, provide concise, factual insights,"
|
||||
" opportunities, and risks."
|
||||
@@ -36,7 +36,7 @@ async def main() -> None:
|
||||
name="researcher",
|
||||
)
|
||||
|
||||
marketer = chat_client.create_agent(
|
||||
marketer = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a creative marketing strategist. Craft compelling value propositions and target messaging"
|
||||
" aligned to the prompt."
|
||||
@@ -44,7 +44,7 @@ async def main() -> None:
|
||||
name="marketer",
|
||||
)
|
||||
|
||||
legal = chat_client.create_agent(
|
||||
legal = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You're a cautious legal/compliance reviewer. Highlight constraints, disclaimers, and policy concerns"
|
||||
" based on the prompt."
|
||||
|
||||
@@ -43,7 +43,7 @@ class Writer(Executor):
|
||||
|
||||
def __init__(self, id: str = "writer"):
|
||||
# Create a domain specific agent using your configured AzureOpenAIChatClient.
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content writer. You create new content and edit contents based on the feedback."
|
||||
),
|
||||
@@ -85,7 +85,7 @@ class Reviewer(Executor):
|
||||
|
||||
def __init__(self, id: str = "reviewer"):
|
||||
# Create a domain specific agent that evaluates and refines content.
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
|
||||
self.agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
|
||||
instructions=(
|
||||
"You are an excellent content reviewer. You review the content and provide feedback to the writer."
|
||||
),
|
||||
|
||||
@@ -35,7 +35,7 @@ async def main() -> None:
|
||||
workflow = (
|
||||
GroupChatBuilder()
|
||||
.with_agent_orchestrator(
|
||||
OpenAIChatClient().create_agent(
|
||||
OpenAIChatClient().as_agent(
|
||||
name="Orchestrator",
|
||||
instructions="You coordinate a team conversation to solve the user's task.",
|
||||
)
|
||||
|
||||
@@ -66,7 +66,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
Tuple of (triage_agent, refund_agent, order_agent, return_agent)
|
||||
"""
|
||||
# Triage agent: Acts as the frontline dispatcher
|
||||
triage_agent = chat_client.create_agent(
|
||||
triage_agent = chat_client.as_agent(
|
||||
instructions=(
|
||||
"You are frontline support triage. Route customer issues to the appropriate specialist agents "
|
||||
"based on the problem described."
|
||||
@@ -75,7 +75,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Refund specialist: Handles refund requests
|
||||
refund_agent = chat_client.create_agent(
|
||||
refund_agent = chat_client.as_agent(
|
||||
instructions="You process refund requests.",
|
||||
name="refund_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -83,7 +83,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Order/shipping specialist: Resolves delivery issues
|
||||
order_agent = chat_client.create_agent(
|
||||
order_agent = chat_client.as_agent(
|
||||
instructions="You handle order and shipping inquiries.",
|
||||
name="order_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
@@ -91,7 +91,7 @@ def create_agents(chat_client: AzureOpenAIChatClient) -> tuple[ChatAgent, ChatAg
|
||||
)
|
||||
|
||||
# Return specialist: Handles return requests
|
||||
return_agent = chat_client.create_agent(
|
||||
return_agent = chat_client.as_agent(
|
||||
instructions="You manage product return requests.",
|
||||
name="return_agent",
|
||||
# In a real application, an agent can have multiple tools; here we keep it simple
|
||||
|
||||
@@ -82,7 +82,7 @@ def create_coding_agent(client: AzureAIAgentClient) -> ChatAgent:
|
||||
Returns:
|
||||
A ChatAgent configured with coding instructions and tools
|
||||
"""
|
||||
return client.create_agent(
|
||||
return client.as_agent(
|
||||
name="CodingAgent",
|
||||
instructions=("You are a helpful assistant that can write and execute Python code to solve problems."),
|
||||
tools=HostedCodeInterpreterTool(),
|
||||
|
||||
@@ -29,12 +29,12 @@ async def main() -> None:
|
||||
# 1) Create agents
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
writer = chat_client.create_agent(
|
||||
writer = chat_client.as_agent(
|
||||
instructions=("You are a concise copywriter. Provide a single, punchy marketing sentence based on the prompt."),
|
||||
name="writer",
|
||||
)
|
||||
|
||||
reviewer = chat_client.create_agent(
|
||||
reviewer = chat_client.as_agent(
|
||||
instructions=("You are a thoughtful reviewer. Give brief feedback on the previous assistant message."),
|
||||
name="reviewer",
|
||||
)
|
||||
|
||||
@@ -79,7 +79,7 @@ async def main() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
# Create agent with tools that use kwargs
|
||||
agent = chat_client.create_agent(
|
||||
agent = chat_client.as_agent(
|
||||
name="assistant",
|
||||
instructions=(
|
||||
"You are a helpful assistant. Use the available tools to help users. "
|
||||
|
||||
@@ -40,7 +40,7 @@ async def main() -> None:
|
||||
|
||||
# Define factory functions for workflow participants
|
||||
def create_assistant() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="assistant",
|
||||
instructions=(
|
||||
"You are a helpful assistant. Answer questions based on the conversation "
|
||||
@@ -49,7 +49,7 @@ async def main() -> None:
|
||||
)
|
||||
|
||||
def create_summarizer() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="summarizer",
|
||||
instructions=(
|
||||
"You are a summarizer. After the assistant responds, provide a brief "
|
||||
@@ -124,7 +124,7 @@ async def demonstrate_thread_serialization() -> None:
|
||||
chat_client = OpenAIChatClient()
|
||||
|
||||
def create_assistant() -> ChatAgent:
|
||||
return chat_client.create_agent(
|
||||
return chat_client.as_agent(
|
||||
name="memory_assistant",
|
||||
instructions="You are a helpful assistant with good memory. Remember details from our conversation.",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user