(tool_use_behavior: Literal["default", "first_tool", "custom"] = "default")
| 59 | |
| 60 | |
| 61 | async 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 | |
| 85 | async def auto_demo() -> None: |
no test coverage detected