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
@@ -80,7 +80,7 @@ class MyTools:
|
||||
|
||||
# Create instance and use methods as tools
|
||||
tools = MyTools(mode="safe")
|
||||
agent = client.create_agent(tools=tools.process)
|
||||
agent = client.as_agent(tools=tools.process)
|
||||
|
||||
# Change behavior dynamically
|
||||
tools.mode = "normal"
|
||||
|
||||
@@ -19,7 +19,7 @@ async def main():
|
||||
description="Get the current time in ISO 8601 format.",
|
||||
)
|
||||
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="DeclarationOnlyToolAgent",
|
||||
instructions="You are a helpful agent that uses tools.",
|
||||
tools=function_declaration,
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ async def main() -> None:
|
||||
# - "func": the parameter name that will receive the injected function
|
||||
tool = AIFunction.from_dict(definition, dependencies={"ai_function": {"name:add_numbers": {"func": func}}})
|
||||
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="FunctionToolAgent", instructions="You are a helpful assistant.", tools=tool
|
||||
)
|
||||
response = await agent.run("What is 5 + 3?")
|
||||
|
||||
@@ -36,7 +36,7 @@ def safe_divide(
|
||||
|
||||
async def main():
|
||||
# tools = Tools()
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="ToolAgent",
|
||||
instructions="Use the provided tools.",
|
||||
tools=[greet, safe_divide],
|
||||
|
||||
@@ -36,7 +36,7 @@ def get_weather(
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="WeatherAgent",
|
||||
instructions="You are a helpful weather assistant.",
|
||||
tools=[get_weather],
|
||||
|
||||
@@ -31,7 +31,7 @@ def safe_divide(
|
||||
|
||||
async def main():
|
||||
# tools = Tools()
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="ToolAgent",
|
||||
instructions="Use the provided tools.",
|
||||
tools=[safe_divide],
|
||||
|
||||
@@ -20,7 +20,7 @@ def unicorn_function(times: Annotated[int, "The number of unicorns to return."])
|
||||
|
||||
async def main():
|
||||
# tools = Tools()
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="ToolAgent",
|
||||
instructions="Use the provided tools.",
|
||||
tools=[unicorn_function],
|
||||
|
||||
@@ -35,7 +35,7 @@ async def get_weather(
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
agent = OpenAIChatClient().create_agent(
|
||||
agent = OpenAIChatClient().as_agent(
|
||||
name="WeatherAgent", instructions="You are a helpful weather assistant.", tools=[get_weather]
|
||||
)
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ async def main():
|
||||
# Applying the ai_function decorator to one of the methods of the class
|
||||
add_function = ai_function(description="Add two numbers.")(tools.add)
|
||||
|
||||
agent = OpenAIResponsesClient().create_agent(
|
||||
agent = OpenAIResponsesClient().as_agent(
|
||||
name="ToolAgent",
|
||||
instructions="Use the provided tools.",
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ async def main():
|
||||
client.function_invocation_configuration.max_iterations = 40
|
||||
print(f"Function invocation configured as: \n{client.function_invocation_configuration.to_json(indent=2)}")
|
||||
|
||||
agent = client.create_agent(name="ToolAgent", instructions="Use the provided tools.", tools=add)
|
||||
agent = client.as_agent(name="ToolAgent", instructions="Use the provided tools.", tools=add)
|
||||
|
||||
print("=" * 60)
|
||||
print("Call add(239847293, 29834)")
|
||||
|
||||
Reference in New Issue
Block a user