MCPcopy Create free account
hub / github.com/openai/openai-agents-python / main

Function main

examples/agent_patterns/forcing_tool_use.py:61–82  ·  view source on GitHub ↗
(tool_use_behavior: Literal["default", "first_tool", "custom"] = "default")

Source from the content-addressed store, hash-verified

59
60
61async def main(tool_use_behavior: Literal["default", "first_tool", "custom"] = "default"):
62 if tool_use_behavior == "default":
63 behavior: Literal["run_llm_again", "stop_on_first_tool"] | ToolsToFinalOutputFunction = (
64 "run_llm_again"
65 )
66 elif tool_use_behavior == "first_tool":
67 behavior = "stop_on_first_tool"
68 elif tool_use_behavior == "custom":
69 behavior = custom_tool_use_behavior
70
71 agent = Agent(
72 name="Weather agent",
73 instructions="You are a helpful agent.",
74 tools=[get_weather],
75 tool_use_behavior=behavior,
76 model_settings=ModelSettings(
77 tool_choice="required" if tool_use_behavior != "default" else None
78 ),
79 )
80
81 result = await Runner.run(agent, input="What's the weather in Tokyo?")
82 print(result.final_output)
83
84
85async def auto_demo() -> None:

Callers 2

auto_demoFunction · 0.70

Calls 3

AgentClass · 0.90
ModelSettingsClass · 0.90
runMethod · 0.45

Tested by

no test coverage detected