Skip to content

#25. Stop On Tool Name

Source code in OpAgentsOlympus/practice/#25. stop_on_tool_name.py
OpAgentsOlympus/practice/#25. stop_on_tool_name.py
from open_router_config import config
from agents import Agent, Runner, function_tool
import asyncio


@function_tool
def hello() -> str:
    """Used to say hello"""
    print("hello was called")
    return "hello"


@function_tool
def bye() -> str:
    """Used to say bye"""
    print("bye was called")
    return "bye"


assistant = Agent(
    name="assistant",
    instructions="You are a helpful assistant.",
    tools=[hello, bye],
    tool_use_behavior={"stop_at_tool_names": ["hello"]},  # stop on hello
)


async def main():
    result = await Runner.run(assistant, input="say hello and bye", run_config=config)
    print(result.final_output)


asyncio.run(main())

# <== Output ==>
# hello was called
# bye was called
# hello