Overview
After an agent completes a task, you can extract the steps as function code:Why Convert to Functions?
| Aspect | Agent | Function |
|---|---|---|
| Execution | AI decides each step | Predefined steps |
| Speed | Slower (LLM reasoning) | Faster (direct execution) |
| Cost | Higher (LLM tokens) | Lower (actions only) |
| Reliability | Can vary | Deterministic |
| Adaptability | Handles changes | Breaks if page changes |
- The task is well-defined and repeatable
- Page structure is stable
- Speed and cost matter
- You need predictable execution
Getting Function Code
As Python Script
Get executable Python code:As Function Object
Create a reusable function:Running Functions
Execute Generated Code
Copy and run the generated Python:Use Function API
Run via the function endpoint:Use Cases
1. Prototyping with Agents
Use agents to figure out the automation, then convert:2. Scheduled Tasks
Convert one-time agent runs to scheduled functions:3. Cost Optimization
Run agents once, then use cheaper functions:4. Testing Variations
Create function templates from agents:Customizing Generated Code
Add Parameters
Make functions reusable with parameters:Add Error Handling
Enhance with production-ready error handling:Optimize Selectors
Review and improve generated selectors:Best Practices
1. Test Generated Functions
Always test before production:2. Document the Source
Track which agent generated the function:3. Version Control
Store functions in git:4. Monitor Function Success
Track if functions continue to work:5. Regenerate When Pages Change
When functions break, use agents to update:Limitations
Functions work best for:- ✅ Stable, unchanging pages
- ✅ Deterministic tasks
- ✅ Known sequences of actions
- ❌ Pages that change frequently
- ❌ Tasks requiring adaptation
- ❌ Complex decision-making

