After an agent completes a task, you can extract the steps as function code:
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: agent = client.Agent(session=session) result = agent.run(task="Navigate to pricing page and extract plans") if result.success: # Convert to function code function_code = agent.workflow.code() print(function_code.python_script)
agent = client.Agent(session=session)result = agent.run(task="Login and navigate to dashboard")if result.success: # Get function code code = agent.workflow.code(as_workflow=True) print(code.python_script)
Example output:
from notte_sdk import NotteClientclient = NotteClient()with client.Session() as session: # Step 1: Navigate to login page session.execute(type="goto", url="https://example.com/login") # Step 2: Fill email field session.execute(type="fill", selector="input[name='email']", value="user@example.com") # Step 3: Fill password field session.execute(type="fill", selector="input[name='password']", value="********") # Step 4: Click login button session.execute(type="click", selector="button[type='submit']") # Step 5: Wait for dashboard session.execute(type="goto", url="https://example.com/dashboard")
result = agent.run(task="Extract product data")if result.success: # Create function from agent function = agent.workflow.create_function() print(f"Created function: {function.function_id}") # Run function later function_result = function.run()
agent.run(task="Complete task")# Create function from successful agentfunction = agent.workflow.create_function()# Run multiple timesfor query in ["laptop", "phone", "tablet"]:
Use agents to figure out the automation, then convert:
prototyping-with-agents.py
# Phase 1: Prototype with agentagent = client.Agent(session=session)result = agent.run(task="Find all products under $100")if result.success: # Phase 2: Convert to function for production code = agent.workflow.code() # Save for production use with open("production_function.py", "w") as f: f.write(code.python_script)
agent = client.Agent(session=session)result = agent.run(task="Complex data extraction")# Recurring: Use function ($0.05 per run)function = agent.workflow.create_function()# Run 100 times - save $15 vs running agent each timefor i in range(100): function.run()
# Base workflow from agentagent = client.Agent(session=session)result = agent.run(task="Search and extract results")code = agent.workflow.code()# Modify code for variations# - Different search queries# - Different extraction logic# - Different URLs
agent.run(task="Complete task") # Generate function code code = agent.workflow.code()# Test in fresh sessionwith client.Session() as session: exec(code.python_script)
from datetime import datetimedef run_monitored_function(): try: function = client.Function(function_id="func_abc123") result = function.run() if result.status == "closed": log_success(datetime.now()) else: alert_failure(result.result) except Exception as e: # Function broken - maybe page changed? # Time to re-run agent and regenerate alert_function_broken(e)
# Old function failingtry: old_function.run()except Exception: print("Function broken, regenerating...") with client.Session() as session: # Use agent to figure out new function agent = client.Agent(session=session) result = agent.run(task=original_task_description) if result.success: # Generate new function