Custom Functions
Extend default agent and write custom function calls
Basic Function Registration
Functions can be either sync or async. Keep them focused and single-purpose.
Copy
from swift_web.controller.service import Controller
# Initialize the controller
controller = Controller()
@controller.action('Ask user for information')
def ask_human(question: str, display_question: bool) -> str:
return input(f'\n{question}\nInput: ')Basic Controller has all basic functionality you might need to interact with the browser already implemented.
Copy
# ... then pass controller to the agent
agent = Agent(
task=task,
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.
Browser-Aware Functions
For actions that need browser access, use the requires_browser=True parameter:
Copy
Structured Parameters with Pydantic
For complex actions, you can define parameter schemas using Pydantic models:
Copy
Using Custom Actions with multiple agents
You can use the same controller for multiple agents.
Copy
Last updated