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
@@ -59,17 +59,17 @@ async def run_agent_framework() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
researcher = client.create_agent(
|
||||
researcher = client.as_agent(
|
||||
name="researcher",
|
||||
instructions="You are a researcher. Provide facts and data about the topic.",
|
||||
)
|
||||
|
||||
writer = client.create_agent(
|
||||
writer = client.as_agent(
|
||||
name="writer",
|
||||
instructions="You are a writer. Turn research into engaging content.",
|
||||
)
|
||||
|
||||
editor = client.create_agent(
|
||||
editor = client.as_agent(
|
||||
name="editor",
|
||||
instructions="You are an editor. Review and finalize the content.",
|
||||
)
|
||||
@@ -109,17 +109,17 @@ async def run_agent_framework_with_cycle() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
researcher = client.create_agent(
|
||||
researcher = client.as_agent(
|
||||
name="researcher",
|
||||
instructions="You are a researcher. Provide facts and data about the topic.",
|
||||
)
|
||||
|
||||
writer = client.create_agent(
|
||||
writer = client.as_agent(
|
||||
name="writer",
|
||||
instructions="You are a writer. Turn research into engaging content.",
|
||||
)
|
||||
|
||||
editor = client.create_agent(
|
||||
editor = client.as_agent(
|
||||
name="editor",
|
||||
instructions="You are an editor. Review and finalize the content. End with APPROVED if satisfied.",
|
||||
)
|
||||
|
||||
@@ -65,19 +65,19 @@ async def run_agent_framework() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
python_expert = client.create_agent(
|
||||
python_expert = client.as_agent(
|
||||
name="python_expert",
|
||||
instructions="You are a Python programming expert. Answer Python-related questions.",
|
||||
description="Expert in Python programming",
|
||||
)
|
||||
|
||||
javascript_expert = client.create_agent(
|
||||
javascript_expert = client.as_agent(
|
||||
name="javascript_expert",
|
||||
instructions="You are a JavaScript programming expert. Answer JavaScript-related questions.",
|
||||
description="Expert in JavaScript programming",
|
||||
)
|
||||
|
||||
database_expert = client.create_agent(
|
||||
database_expert = client.as_agent(
|
||||
name="database_expert",
|
||||
instructions="You are a database expert. Answer SQL and database-related questions.",
|
||||
description="Expert in databases and SQL",
|
||||
@@ -87,7 +87,7 @@ async def run_agent_framework() -> None:
|
||||
GroupChatBuilder()
|
||||
.participants([python_expert, javascript_expert, database_expert])
|
||||
.set_manager(
|
||||
manager=client.create_agent(
|
||||
manager=client.as_agent(
|
||||
name="selector_manager",
|
||||
instructions="Based on the conversation, select the most appropriate expert to respond next.",
|
||||
),
|
||||
|
||||
@@ -108,7 +108,7 @@ async def run_agent_framework() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create triage agent
|
||||
triage_agent = client.create_agent(
|
||||
triage_agent = client.as_agent(
|
||||
name="triage",
|
||||
instructions=(
|
||||
"You are a triage agent. Analyze the user's request and route to the appropriate specialist:\n"
|
||||
@@ -119,14 +119,14 @@ async def run_agent_framework() -> None:
|
||||
)
|
||||
|
||||
# Create billing specialist
|
||||
billing_agent = client.create_agent(
|
||||
billing_agent = client.as_agent(
|
||||
name="billing_agent",
|
||||
instructions="You are a billing specialist. Help with payment and billing questions. Provide clear assistance.",
|
||||
description="Handles billing and payment questions",
|
||||
)
|
||||
|
||||
# Create technical support specialist
|
||||
tech_support = client.create_agent(
|
||||
tech_support = client.as_agent(
|
||||
name="technical_support",
|
||||
instructions="You are technical support. Help with technical issues. Provide clear assistance.",
|
||||
description="Handles technical support questions",
|
||||
|
||||
@@ -69,19 +69,19 @@ async def run_agent_framework() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized agents
|
||||
researcher = client.create_agent(
|
||||
researcher = client.as_agent(
|
||||
name="researcher",
|
||||
instructions="You are a research analyst. Gather and analyze information.",
|
||||
description="Research analyst for data gathering",
|
||||
)
|
||||
|
||||
coder = client.create_agent(
|
||||
coder = client.as_agent(
|
||||
name="coder",
|
||||
instructions="You are a programmer. Write code based on requirements.",
|
||||
description="Software developer for implementation",
|
||||
)
|
||||
|
||||
reviewer = client.create_agent(
|
||||
reviewer = client.as_agent(
|
||||
name="reviewer",
|
||||
instructions="You are a code reviewer. Review code for quality and correctness.",
|
||||
description="Code reviewer for quality assurance",
|
||||
|
||||
@@ -33,7 +33,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
# AF constructs a lightweight ChatAgent backed by OpenAIChatClient
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
agent = client.create_agent(
|
||||
agent = client.as_agent(
|
||||
name="assistant",
|
||||
instructions="You are a helpful assistant. Answer in one sentence.",
|
||||
)
|
||||
|
||||
@@ -65,7 +65,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
# Create agent with tool
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
agent = client.create_agent(
|
||||
agent = client.as_agent(
|
||||
name="assistant",
|
||||
instructions="You are a helpful assistant. Use available tools to answer questions.",
|
||||
tools=[get_weather],
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
agent = client.create_agent(
|
||||
agent = client.as_agent(
|
||||
name="assistant",
|
||||
instructions="You are a helpful math tutor.",
|
||||
)
|
||||
|
||||
@@ -54,7 +54,7 @@ async def run_agent_framework() -> None:
|
||||
client = OpenAIChatClient(model_id="gpt-4.1-mini")
|
||||
|
||||
# Create specialized writer agent
|
||||
writer = client.create_agent(
|
||||
writer = client.as_agent(
|
||||
name="writer",
|
||||
instructions="You are a creative writer. Write short, engaging content.",
|
||||
)
|
||||
@@ -68,7 +68,7 @@ async def run_agent_framework() -> None:
|
||||
)
|
||||
|
||||
# Create coordinator agent with writer tool
|
||||
coordinator = client.create_agent(
|
||||
coordinator = client.as_agent(
|
||||
name="coordinator",
|
||||
instructions="You coordinate with specialized agents. Delegate writing tasks to the writer agent.",
|
||||
tools=[writer_tool],
|
||||
|
||||
Reference in New Issue
Block a user