Skip to content

Commit 0d98f48

Browse files
authored
Merge pull request #822 from dmytrostruk/python-as-agent-updates
Python: Renamed create_agent to as_agent
2 parents c8b9130 + be52bca commit 0d98f48

36 files changed

Lines changed: 120 additions & 120 deletions

agent-framework/migration-guide/from-autogen/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ async def example():
234234
)
235235

236236
# Factory method (more convenient)
237-
agent = client.create_agent(
237+
agent = client.as_agent(
238238
name="assistant",
239239
instructions="You are a helpful assistant.",
240240
tools=[get_weather],

agent-framework/migration-guide/from-semantic-kernel/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ Or, with the convenience methods provided by chat clients:
381381
```python
382382
from agent_framework.azure import AzureOpenAIChatClient
383383
from azure.identity import AzureCliCredential
384-
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(instructions="You are a helpful assistant")
384+
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(instructions="You are a helpful assistant")
385385
```
386386

387387
The direct method exposes all possible parameters you can set for your agent. While the convenience method has a subset, you can still pass in the same set of parameters, because it calls the direct method internally.
@@ -467,7 +467,7 @@ def get_weather(location: str) -> str:
467467
"""Get the weather for a given location."""
468468
return f"The weather in {location} is sunny."
469469

470-
agent = chat_client.create_agent(tools=get_weather)
470+
agent = chat_client.as_agent(tools=get_weather)
471471
```
472472

473473
> [!NOTE]
@@ -516,7 +516,7 @@ class Plugin:
516516
return f"The weather in {location} is sunny with a high of 25°C and a low of 15°C."
517517

518518
plugin = Plugin("Initial state")
519-
agent = chat_client.create_agent(tools=[plugin.get_weather, plugin.get_weather_details])
519+
agent = chat_client.as_agent(tools=[plugin.get_weather, plugin.get_weather_details])
520520

521521
... # use the agent
522522

@@ -575,7 +575,7 @@ kernel_function = KernelFunctionFromPrompt(
575575
agent_tool = kernel_function.as_agent_framework_tool(kernel=kernel)
576576

577577
# Use the tool with an Agent Framework agent
578-
agent = OpenAIResponsesClient(model_id="gpt-4o").create_agent(tools=agent_tool)
578+
agent = OpenAIResponsesClient(model_id="gpt-4o").as_agent(tools=agent_tool)
579579
response = await agent.run("What kind of day is it?")
580580
print(response.text)
581581
```
@@ -595,7 +595,7 @@ def get_weather(self, location: str) -> str:
595595
agent_tool = get_weather.as_agent_framework_tool()
596596

597597
# Use the tool with an Agent Framework agent
598-
agent = OpenAIResponsesClient(model_id="gpt-4o").create_agent(tools=agent_tool)
598+
agent = OpenAIResponsesClient(model_id="gpt-4o").as_agent(tools=agent_tool)
599599
response = await agent.run("What's the weather in Seattle?")
600600
print(response.text)
601601
```
@@ -663,7 +663,7 @@ async with collection:
663663
search_tool = search_function.as_agent_framework_tool()
664664

665665
# Use the tool with an Agent Framework agent
666-
agent = OpenAIResponsesClient(model_id="gpt-4o").create_agent(
666+
agent = OpenAIResponsesClient(model_id="gpt-4o").as_agent(
667667
instructions="You are a travel agent that helps people find hotels.",
668668
tools=search_tool
669669
)
@@ -779,7 +779,7 @@ from agent_framework.openai import OpenAIChatClient
779779
client = OpenAIChatClient()
780780

781781
# Set default options at agent creation
782-
agent = client.create_agent(
782+
agent = client.as_agent(
783783
instructions="You are a helpful assistant.",
784784
default_options={
785785
"max_tokens": 1000,

agent-framework/support/upgrade/typed-options-guide-python.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ response = await client.get_response(
5454
)
5555
```
5656

57-
> **Note:** For **Agents**, the `instructions` and `tools` parameters remain available as direct keyword arguments on `ChatAgent.__init__()` and `client.create_agent()`. For `agent.run()`, only `tools` is available as a keyword argument:
57+
> **Note:** For **Agents**, the `instructions` and `tools` parameters remain available as direct keyword arguments on `ChatAgent.__init__()` and `client.as_agent()`. For `agent.run()`, only `tools` is available as a keyword argument:
5858
>
5959
> ```python
6060
> # Agent creation accepts both tools and instructions as keyword arguments

agent-framework/tutorials/agents/agent-as-function-tool.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Create a `ChatAgent` that uses the function tool.
103103
from agent_framework.azure import AzureOpenAIChatClient
104104
from azure.identity import AzureCliCredential
105105

106-
weather_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
106+
weather_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
107107
name="WeatherAgent",
108108
description="An agent that answers questions about the weather.",
109109
instructions="You answer questions about the weather.",
@@ -114,7 +114,7 @@ weather_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_ag
114114
Now, create a main agent and provide the `weather_agent` as a function tool by calling `.as_tool()` to convert `weather_agent` to a function tool.
115115

116116
```python
117-
main_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
117+
main_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
118118
instructions="You are a helpful assistant who responds in French.",
119119
tools=weather_agent.as_tool()
120120
)
@@ -138,7 +138,7 @@ weather_tool = weather_agent.as_tool(
138138
arg_description="The weather query or location"
139139
)
140140

141-
main_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
141+
main_agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
142142
instructions="You are a helpful assistant who responds in French.",
143143
tools=weather_tool
144144
)

agent-framework/tutorials/agents/agent-as-mcp-tool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_item_price(
114114
return "$9.99"
115115

116116
# Create an agent with tools
117-
agent = OpenAIResponsesClient().create_agent(
117+
agent = OpenAIResponsesClient().as_agent(
118118
name="RestaurantAgent",
119119
description="Answer questions about the menu.",
120120
tools=[get_specials, get_item_price],

agent-framework/tutorials/agents/create-and-run-durable-agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ agent = AzureOpenAIChatClient(
222222
endpoint=endpoint,
223223
deployment_name=deployment_name,
224224
credential=DefaultAzureCredential()
225-
).create_agent(
225+
).as_agent(
226226
instructions="You are a helpful assistant that can answer questions and provide information.",
227227
name="MyDurableAgent"
228228
)

agent-framework/tutorials/agents/function-tools.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ import asyncio
117117
from agent_framework.azure import AzureOpenAIChatClient
118118
from azure.identity import AzureCliCredential
119119

120-
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
120+
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
121121
instructions="You are a helpful assistant",
122122
tools=get_weather
123123
)
@@ -163,7 +163,7 @@ When creating the agent, you can now provide all the methods of the class as fun
163163

164164
```python
165165
tools = WeatherTools()
166-
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
166+
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
167167
instructions="You are a helpful assistant",
168168
tools=[tools.get_weather, tools.get_weather_details]
169169
)

agent-framework/tutorials/agents/images.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import asyncio
6666
from agent_framework.azure import AzureOpenAIChatClient
6767
from azure.identity import AzureCliCredential
6868

69-
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).create_agent(
69+
agent = AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
7070
name="VisionAgent",
7171
instructions="You are a helpful agent that can analyze images"
7272
)

agent-framework/tutorials/agents/middleware.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ from azure.identity.aio import AzureCliCredential
217217
async def main():
218218
credential = AzureCliCredential()
219219

220-
async with AzureAIAgentClient(credential=credential).create_agent(
220+
async with AzureAIAgentClient(credential=credential).as_agent(
221221
name="GreetingAgent",
222222
instructions="You are a friendly greeting assistant.",
223223
) as agent:
@@ -256,7 +256,7 @@ Add the middleware when creating your agent:
256256
async def main():
257257
credential = AzureCliCredential()
258258

259-
async with AzureAIAgentClient(credential=credential).create_agent(
259+
async with AzureAIAgentClient(credential=credential).as_agent(
260260
name="GreetingAgent",
261261
instructions="You are a friendly greeting assistant.",
262262
middleware=logging_agent_middleware, # Add your middleware here
@@ -289,7 +289,7 @@ async def logging_function_middleware(
289289
print(f"Function result: {context.result}")
290290

291291
# Add both the function and middleware to your agent
292-
async with AzureAIAgentClient(credential=credential).create_agent(
292+
async with AzureAIAgentClient(credential=credential).as_agent(
293293
name="TimeAgent",
294294
instructions="You can tell the current time.",
295295
tools=[get_time],

agent-framework/tutorials/agents/orchestrate-durable-agents.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,18 @@ chat_client = AzureOpenAIChatClient(
125125
)
126126

127127
# Create the main agent from the first tutorial
128-
main_agent = chat_client.create_agent(
128+
main_agent = chat_client.as_agent(
129129
instructions="You are a helpful assistant that can answer questions and provide information.",
130130
name="MyDurableAgent"
131131
)
132132

133133
# Create translation agents
134-
french_agent = chat_client.create_agent(
134+
french_agent = chat_client.as_agent(
135135
instructions="You are a translator. Translate the following text to French. Return only the translation, no explanations.",
136136
name="FrenchTranslator"
137137
)
138138

139-
spanish_agent = chat_client.create_agent(
139+
spanish_agent = chat_client.as_agent(
140140
instructions="You are a translator. Translate the following text to Spanish. Return only the translation, no explanations.",
141141
name="SpanishTranslator"
142142
)

0 commit comments

Comments
 (0)