Skip to main content

What are Python Agents?

Python Agents are code-based automations that run directly in the browser using the Narada Python SDK. Unlike GUI workflow agents (which use a visual step-by-step editor), Python Agents give you the full flexibility of Python code to build complex automations with loops, conditions, data processing, and API calls.

Full Python

Write real Python code with access to the Narada SDK, Pydantic, and common libraries

AI-Generated

Created automatically by Agent Maker and Imitation Learning

SDK-Powered

Use all Narada SDK methods: agent(), go_to_url(), agentic_selector(), and more

How Python Agents Are Created

There are three ways to create a Python Agent in Agent Studio: Describe your goal in natural language, and Agent Maker generates a complete Python Agent for you:
/agentMaker Create an agent that extracts product prices from amazon.com and saves them to a Google Sheet

2. Imitation Learning

Record yourself performing a task in the browser, and Imitation Learning generates an agent from your recording.

3. Manual Creation

Create a Python Agent from scratch in Agent Studio:
1

Open Agent Studio

Navigate to Agent Studio and click + Create.
2

Select Python Agent

Choose the Python Agent option from the creation dialog.
Python Agent option in the Agent Studio create dialog
3

Write your code

The editor opens with a starter template. Write your automation using the Narada SDK.

Writing Python Agent Code

Python Agents have access to the Narada SDK through a pre-initialized window object of type LocalBrowserWindow. Here’s the typical structure:
from narada import Agent, LocalBrowserWindow
from pydantic import BaseModel, Field

# The browser window is pre-initialized. Target the current browser window.
window = LocalBrowserWindow()

# Navigate to a starting page (use new_tab=True for the first navigation)
await window.go_to_url(url="https://example.com", new_tab=True)

# Use the Operator agent for web automation
response = await window.agent(
    prompt="Extract the main heading from this page",
    agent=Agent.OPERATOR,
)

print(response.text)
Always use new_tab=True for the first go_to_url() call. This ensures the workflow runs in a new tab, preventing the current tab (which executes the workflow) from being closed.

Using Structured Output

Extract typed data using Pydantic models:
from narada import Agent, LocalBrowserWindow
from pydantic import BaseModel, Field

class ProductInfo(BaseModel):
    name: str = Field(description="Product name")
    price: str = Field(description="Product price with currency")
    rating: str = Field(description="Product rating out of 5")

window = LocalBrowserWindow()
await window.go_to_url(url="https://example.com/product", new_tab=True)

response = await window.agent(
    prompt="Extract the product information from this page",
    agent=Agent.GENERALIST,
    output_schema=ProductInfo,
)

product = response.structured_output
print(f"{product.name}: {product.price} ({product.rating})")

Using Input Variables

Python Agents can accept input variables when invoked, making them reusable with different data:
from narada import Agent, LocalBrowserWindow

window = LocalBrowserWindow()

# Access input variables with sensible defaults
search_term = variables.get("searchTerm", "machine learning")
max_results = variables.get("maxResults", 5)

await window.go_to_url(
    url=f"https://www.google.com/search?q={search_term}",
    new_tab=True
)

response = await window.agent(
    prompt=f"Extract the top {max_results} search result titles",
    agent=Agent.GENERALIST,
)

print(response.text)
Always use variables.get("key", default) instead of variables["key"] so your agent can run standalone without input variables.

Google Sheets Integration

Read from and write to Google Sheets:
from narada import LocalBrowserWindow

window = LocalBrowserWindow()

# Read company names from a spreadsheet
sheet_data = await window.read_google_sheet(
    spreadsheet_id="your-spreadsheet-id",
    range="Sheet1!A2:A10",
)
companies = [row[0] for row in sheet_data.values]

# Process each company...
results = []
for company in companies:
    await window.go_to_url(
        url=f"https://www.google.com/search?q={company}+valuation"
    )
    response = await window.agent(
        prompt=f"What is {company}'s latest valuation?",
    )
    results.append([company, response.text])

# Write results back
await window.write_google_sheet(
    spreadsheet_id="your-spreadsheet-id",
    range="Sheet1!B2",
    values=results,
)

await window.print_message(message="Done! Results written to Google Sheet.")

Available SDK Methods

Python Agents have access to all Narada SDK methods:
MethodDescription
agent()Execute AI-powered automation tasks
go_to_url()Navigate to a URL
agentic_selector()Interact with specific UI elements
get_screenshot()Capture a screenshot
get_full_html()Get the page’s full HTML
get_simplified_html()Get cleaned/simplified HTML
print_message()Show a message in the side panel chat
upload_file()Upload a file for use in agent requests
read_google_sheet()Read data from Google Sheets
write_google_sheet()Write data to Google Sheets
close()Close the browser window

Agent Types

When calling window.agent(), choose the right agent for the task:

OPERATOR

Web automation: clicks, navigation, form filling, data extraction from pages

CORE_AGENT

Read-only observation: extracting visible data, answering questions about page content, and web searches without taking browser actions
from narada import Agent

# Web automation (default)
await window.agent(prompt="Click the Submit button", agent=Agent.OPERATOR)

# Read-only observation
await window.agent(prompt="What products are listed?", agent=Agent.CORE_AGENT)

Running Python Agents

From Agent Studio

Click the Run button in the Agent Studio editor to execute your Python Agent in the current browser.

From the SDK

Invoke a custom Python Agent from the SDK using the namespaced format:
response = await window.agent(
    prompt="Search for machine learning papers",
    agent="/$USER/my-research-agent"
)

From Chat

Type the agent shortcut in the Narada chat:
/$USER/my-research-agent Search for machine learning papers

Best Practices

Use new_tab=True First

Always open a new tab for the first navigation to avoid closing the workflow tab

Handle Errors

Wrap agent() calls in try/except for NaradaTimeoutError to handle slow pages

Use Structured Output

Define Pydantic models for reliable data extraction instead of parsing text responses

Print Progress

Use print_message() to show progress updates in the side panel during long workflows

Next Steps

Agent Maker

Generate Python Agents from natural language descriptions

Imitation Learning

Record your actions to generate agents

Agent Studio

Manage and organize all your agents

Python SDK Reference

Full API reference for the agent() method