Functions can be either sync or async. Keep them focused and single-purpose.
Copy
from openoperator import Controller, ActionResult# Initialize the controllercontroller = Controller()@controller.action('Ask user for information')def ask_human(question: str) -> str: answer = input(f'\n{question}\nInput: ') return ActionResult(extracted_content=answer)
Basic Controller has all basic functionality you might need to interact with
the browser already implemented.
Copy
# ... then pass controller to the agentagent = Agent( llm=llm, controller=controller)
Keep the function name and description short and concise. The Agent use the
function solely based on the name and description. The stringified output of
the action is passed to the Agent.
You can use the same controller for multiple agents.
Copy
controller = Controller()# ... register actions to the controlleragent = Agent( llm=llm, controller=controller)agent.add_task("Go to website X and find the latest news")# Run the agentawait agent.run()agent2 = Agent( llm=llm, controller=controller)agent2.add_task("Go to website Y and find the latest news")await agent2.run()
The controller is stateless and can be used to register multiple actions and
multiple agents.