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
@@ -16,7 +16,7 @@ async def run_semantic_kernel() -> None:
|
||||
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
|
||||
settings = AzureAIAgentSettings() # Reads env vars for region/deployment.
|
||||
# SK builds the remote agent definition then wraps it with AzureAIAgent.
|
||||
definition = await client.agents.create_agent(
|
||||
definition = await client.agents.as_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Support",
|
||||
instructions="Answer customer questions in one paragraph.",
|
||||
@@ -32,7 +32,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(credential=credential).create_agent(
|
||||
AzureAIAgentClient(credential=credential).as_agent(
|
||||
name="Support",
|
||||
instructions="Answer customer questions in one paragraph.",
|
||||
) as agent,
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ async def run_semantic_kernel() -> None:
|
||||
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
|
||||
settings = AzureAIAgentSettings()
|
||||
# Register the hosted code interpreter tool with the remote agent.
|
||||
definition = await client.agents.create_agent(
|
||||
definition = await client.agents.as_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Analyst",
|
||||
instructions="Use the code interpreter for numeric work.",
|
||||
@@ -35,7 +35,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(credential=credential).create_agent(
|
||||
AzureAIAgentClient(credential=credential).as_agent(
|
||||
name="Analyst",
|
||||
instructions="Use the code interpreter for numeric work.",
|
||||
tools=[HostedCodeInterpreterTool()],
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ async def run_semantic_kernel() -> None:
|
||||
|
||||
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
|
||||
settings = AzureAIAgentSettings()
|
||||
definition = await client.agents.create_agent(
|
||||
definition = await client.agents.as_agent(
|
||||
model=settings.model_deployment_name,
|
||||
name="Planner",
|
||||
instructions="Track follow-up questions within the same thread.",
|
||||
@@ -38,7 +38,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
async with (
|
||||
AzureCliCredential() as credential,
|
||||
AzureAIAgentClient(credential=credential).create_agent(
|
||||
AzureAIAgentClient(credential=credential).as_agent(
|
||||
name="Planner",
|
||||
instructions="Track follow-up questions within the same thread.",
|
||||
) as agent,
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# AF constructs a lightweight ChatAgent backed by OpenAIChatClient.
|
||||
chat_agent = OpenAIChatClient().create_agent(
|
||||
chat_agent = OpenAIChatClient().as_agent(
|
||||
name="Support",
|
||||
instructions="Answer in one sentence.",
|
||||
)
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ async def run_agent_framework() -> None:
|
||||
return "Clam chowder, Cobb salad, Chai tea"
|
||||
|
||||
# AF tools are provided as callables on each agent instance.
|
||||
chat_agent = OpenAIChatClient().create_agent(
|
||||
chat_agent = OpenAIChatClient().as_agent(
|
||||
name="Host",
|
||||
instructions="Answer menu questions accurately.",
|
||||
tools=[specials],
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# AF thread objects are requested explicitly from the agent.
|
||||
chat_agent = OpenAIChatClient().create_agent(
|
||||
chat_agent = OpenAIChatClient().as_agent(
|
||||
name="Writer",
|
||||
instructions="Keep answers short and friendly.",
|
||||
)
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
assistants_client = OpenAIAssistantsClient()
|
||||
# AF wraps the assistant lifecycle with an async context manager.
|
||||
async with assistants_client.create_agent(
|
||||
async with assistants_client.as_agent(
|
||||
name="Helper",
|
||||
instructions="Answer questions in one concise paragraph.",
|
||||
model=ASSISTANT_MODEL,
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
assistants_client = OpenAIAssistantsClient()
|
||||
# AF exposes the same tool configuration via create_agent.
|
||||
async with assistants_client.create_agent(
|
||||
async with assistants_client.as_agent(
|
||||
name="CodeRunner",
|
||||
instructions="Use the code interpreter when calculations are required.",
|
||||
model="gpt-4.1",
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ async def run_agent_framework() -> None:
|
||||
|
||||
assistants_client = OpenAIAssistantsClient()
|
||||
# AF converts the decorated function into an assistant-compatible tool.
|
||||
async with assistants_client.create_agent(
|
||||
async with assistants_client.as_agent(
|
||||
name="WeatherHelper",
|
||||
instructions="Call get_forecast to fetch weather details.",
|
||||
model=ASSISTANT_MODEL,
|
||||
|
||||
@@ -77,12 +77,12 @@ def _print_semantic_kernel_outputs(outputs: Sequence[ChatMessageContent]) -> Non
|
||||
async def run_agent_framework_example(prompt: str) -> Sequence[list[ChatMessage]]:
|
||||
chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
|
||||
physics = chat_client.create_agent(
|
||||
physics = chat_client.as_agent(
|
||||
instructions=("You are an expert in physics. Answer questions from a physics perspective."),
|
||||
name="physics",
|
||||
)
|
||||
|
||||
chemistry = chat_client.create_agent(
|
||||
chemistry = chat_client.as_agent(
|
||||
instructions=("You are an expert in chemistry. Answer questions from a chemistry perspective."),
|
||||
name="chemistry",
|
||||
)
|
||||
|
||||
@@ -234,7 +234,7 @@ async def run_agent_framework_example(task: str) -> str:
|
||||
workflow = (
|
||||
GroupChatBuilder()
|
||||
.set_manager(
|
||||
manager=AzureOpenAIChatClient(credential=credential).create_agent(),
|
||||
manager=AzureOpenAIChatClient(credential=credential).as_agent(),
|
||||
display_name="Coordinator",
|
||||
)
|
||||
.participants(researcher=researcher, planner=planner)
|
||||
|
||||
@@ -180,7 +180,7 @@ async def run_semantic_kernel_example(initial_task: str, scripted_responses: Seq
|
||||
|
||||
|
||||
def _create_af_agents(client: AzureOpenAIChatClient):
|
||||
triage = client.create_agent(
|
||||
triage = client.as_agent(
|
||||
name="triage_agent",
|
||||
instructions=(
|
||||
"You are a customer support triage agent. Route requests:\n"
|
||||
@@ -189,19 +189,19 @@ def _create_af_agents(client: AzureOpenAIChatClient):
|
||||
"- handoff_to_order_return_agent for returns"
|
||||
),
|
||||
)
|
||||
refund = client.create_agent(
|
||||
refund = client.as_agent(
|
||||
name="refund_agent",
|
||||
instructions=(
|
||||
"Handle refunds. Ask for order id and reason. If shipping info is needed, hand off to order_status_agent."
|
||||
),
|
||||
)
|
||||
status = client.create_agent(
|
||||
status = client.as_agent(
|
||||
name="order_status_agent",
|
||||
instructions=(
|
||||
"Provide order status, tracking, and timelines. If billing questions appear, hand off to refund_agent."
|
||||
),
|
||||
)
|
||||
returns = client.create_agent(
|
||||
returns = client.as_agent(
|
||||
name="order_return_agent",
|
||||
instructions=(
|
||||
"Coordinate returns, confirm addresses, and summarize next steps. Hand off to triage_agent if unsure."
|
||||
|
||||
@@ -63,12 +63,12 @@ async def sk_agent_response_callback(
|
||||
async def run_agent_framework_example(prompt: str) -> list[ChatMessage]:
|
||||
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",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user