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
@@ -26,7 +26,7 @@ async def non_streaming_example() -> None:
|
||||
"""Example of non-streaming response (get the complete result at once)."""
|
||||
print("=== Non-streaming Response Example ===")
|
||||
|
||||
agent = OpenAIChatClient().create_agent(
|
||||
agent = OpenAIChatClient().as_agent(
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
@@ -42,7 +42,7 @@ async def streaming_example() -> None:
|
||||
"""Example of streaming response (get results as they are generated)."""
|
||||
print("=== Streaming Response Example ===")
|
||||
|
||||
agent = OpenAIChatClient().create_agent(
|
||||
agent = OpenAIChatClient().as_agent(
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ async def main() -> None:
|
||||
agent = OpenAIChatClient(
|
||||
model_id=os.environ["OPENAI_CHAT_MODEL_ID"],
|
||||
api_key=os.environ["OPENAI_API_KEY"],
|
||||
).create_agent(
|
||||
).as_agent(
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
)
|
||||
|
||||
@@ -55,7 +55,7 @@ async def mcp_tools_on_agent_level() -> None:
|
||||
# Tools are provided when creating the agent
|
||||
# The agent can use these tools for any query during its lifetime
|
||||
# The agent will connect to the MCP server through its context manager.
|
||||
async with OpenAIChatClient().create_agent(
|
||||
async with OpenAIChatClient().as_agent(
|
||||
name="DocsAgent",
|
||||
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
|
||||
tools=MCPStreamableHTTPTool( # Tools defined at agent creation
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ runtime_schema = {
|
||||
async def non_streaming_example() -> None:
|
||||
print("=== Non-streaming runtime JSON schema example ===")
|
||||
|
||||
agent = OpenAIChatClient[OpenAIChatOptions]().create_agent(
|
||||
agent = OpenAIChatClient[OpenAIChatOptions]().as_agent(
|
||||
name="RuntimeSchemaAgent",
|
||||
instructions="Return only JSON that matches the provided schema. Do not add commentary.",
|
||||
)
|
||||
@@ -65,7 +65,7 @@ async def non_streaming_example() -> None:
|
||||
async def streaming_example() -> None:
|
||||
print("=== Streaming runtime JSON schema example ===")
|
||||
|
||||
agent = OpenAIChatClient().create_agent(
|
||||
agent = OpenAIChatClient().as_agent(
|
||||
name="RuntimeSchemaAgent",
|
||||
instructions="Return only JSON that matches the provided schema. Do not add commentary.",
|
||||
)
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ async def main():
|
||||
print("=== OpenAI Responses Agent with Image Analysis ===")
|
||||
|
||||
# 1. Create an OpenAI Responses agent with vision capabilities
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="VisionAgent",
|
||||
instructions="You are a helpful agent that can analyze images.",
|
||||
)
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ async def main() -> None:
|
||||
print("=== OpenAI Responses Image Generation Agent Example ===")
|
||||
|
||||
# Create an agent with customized image generation options
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
instructions="You are a helpful AI that can generate images.",
|
||||
tools=[
|
||||
HostedImageGenerationTool(
|
||||
|
||||
@@ -19,7 +19,7 @@ In this case they are here: https://platform.openai.com/docs/api-reference/respo
|
||||
"""
|
||||
|
||||
|
||||
agent = OpenAIResponsesClient[OpenAIResponsesOptions](model_id="gpt-5").create_agent(
|
||||
agent = OpenAIResponsesClient[OpenAIResponsesOptions](model_id="gpt-5").as_agent(
|
||||
name="MathHelper",
|
||||
instructions="You are a personal math tutor. When asked a math question, "
|
||||
"reason over how best to approach the problem and share your thought process.",
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ async def main():
|
||||
print("=== OpenAI Streaming Image Generation Example ===\n")
|
||||
|
||||
# Create agent with streaming image generation enabled
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
instructions="You are a helpful agent that can generate images.",
|
||||
tools=[
|
||||
HostedImageGenerationTool(
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ async def main() -> None:
|
||||
agent = OpenAIResponsesClient(
|
||||
model_id=os.environ["OPENAI_RESPONSES_MODEL_ID"],
|
||||
api_key=os.environ["OPENAI_API_KEY"],
|
||||
).create_agent(
|
||||
).as_agent(
|
||||
instructions="You are a helpful weather agent.",
|
||||
tools=get_weather,
|
||||
)
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ runtime_schema = {
|
||||
async def non_streaming_example() -> None:
|
||||
print("=== Non-streaming runtime JSON schema example ===")
|
||||
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="RuntimeSchemaAgent",
|
||||
instructions="Return only JSON that matches the provided schema. Do not add commentary.",
|
||||
)
|
||||
@@ -65,7 +65,7 @@ async def non_streaming_example() -> None:
|
||||
async def streaming_example() -> None:
|
||||
print("=== Streaming runtime JSON schema example ===")
|
||||
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="RuntimeSchemaAgent",
|
||||
instructions="Return only JSON that matches the provided schema. Do not add commentary.",
|
||||
)
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ async def non_streaming_example() -> None:
|
||||
print("=== Non-streaming example ===")
|
||||
|
||||
# Create an OpenAI Responses agent
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="CityAgent",
|
||||
instructions="You are a helpful agent that describes cities in a structured format.",
|
||||
)
|
||||
@@ -51,7 +51,7 @@ async def streaming_example() -> None:
|
||||
print("=== Streaming example ===")
|
||||
|
||||
# Create an OpenAI Responses agent
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="CityAgent",
|
||||
instructions="You are a helpful agent that describes cities in a structured format.",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user