Execute automation tasks using the Narada Python SDK
Agent.run() executes a natural-language task in a Narada environment and returns an AgentResponse.Create an environment first, then bind an agent to it:
from narada import Agent, BrowserEnvironmentenv = BrowserEnvironment()agent = Agent(environment=env)response = await agent.run(prompt="Search for Narada AI and summarize the first result.")print(response.text)
Agent.run() is the current SDK interface. The older Narada().open_and_initialize_browser_window() and window.agent(...) pattern is no longer the recommended API.
Best for browser automation tasks like clicking, navigating, filling forms, and extracting data from pages.
from narada import Agent, AgentKindagent = Agent(environment=env, kind=AgentKind.OPERATOR)
Best for read-only reasoning, answering questions about page content, and conversation-style tasks.
from narada import Agent, AgentKindagent = Agent(environment=env, kind=AgentKind.CORE_AGENT)
Best for general productivity and non-browser-specific tasks.
from narada import Agent, AgentKindagent = Agent(environment=env, kind=AgentKind.PRODUCTIVITY)
Invoke custom agents created in Agent Studio using the namespaced format.
# Use $USER shorthand for your own account.agent = Agent(environment=env, kind="/$USER/my-data-analyst")# Or reference a shared agent explicitly.agent = Agent(environment=env, kind="/jane@company.com/sales-report-generator")
The same syntax works in the Narada chat side panel:
/$USER/my-agent Search for recent tech news/jane@company.com/research-bot Find papers on transformers
Agents must be shared or published in Agent Studio before other users can invoke them.
Controls how much reasoning the Core Agent uses before responding. This option is only valid with AgentKind.CORE_AGENT.
from narada import AgentKind, ReasoningEffortagent = Agent(environment=env, kind=AgentKind.CORE_AGENT)response = await agent.run( prompt="Analyze the page and explain the pricing model.", reasoning=ReasoningEffort.MEDIUM,)
first = await agent.run(prompt="Pick a lucky number.")second = await agent.run( prompt="What number did you pick?", previous_request_id=first.request_id,)
import asynciofrom narada import Agent, BrowserEnvironmentasync def main() -> None: env = BrowserEnvironment() agent = Agent(environment=env) try: response = await agent.run( prompt="Search for Python tutorials on Google and get the title of the first result", ) print(f"Status: {response.status}") print(f"Result: {response.text}") print(f"Actions used: {response.usage.actions}") finally: await env.close()if __name__ == "__main__": asyncio.run(main())
import asynciofrom narada import Agent, BrowserEnvironmentfrom pydantic import BaseModel, Fieldclass SearchResult(BaseModel): query: str = Field(description="The search query used") result_count: str = Field(description="Number of results found") top_result_title: str = Field(description="Title of the first result") top_result_url: str = Field(description="URL of the first result")async def main() -> None: env = BrowserEnvironment() agent = Agent(environment=env) try: response = await agent.run( prompt="Search for AI research papers and extract search details", output_schema=SearchResult, ) data = response.structured_output assert data is not None print(f"Query: {data.query}") print(f"Results: {data.result_count}") print(f"Top result: {data.top_result_title}") print(f"URL: {data.top_result_url}") finally: await env.close()if __name__ == "__main__": asyncio.run(main())
import asynciofrom narada import Agent, AgentKind, BrowserEnvironmentasync def main() -> None: env = BrowserEnvironment() agent = Agent(environment=env, kind=AgentKind.CORE_AGENT) try: response = await agent.run( prompt="Pick a lucky number between 1 and 100 for me.", ) print("Agent:", response.text) response = await agent.run( prompt="What did you pick again?", previous_request_id=response.request_id, ) print("Agent:", response.text) response = await agent.run( prompt="What's double that number?", previous_request_id=response.request_id, ) print("Agent:", response.text) finally: await env.close()if __name__ == "__main__": asyncio.run(main())
import asynciofrom narada import Agent, BrowserEnvironment, NaradaTimeoutErrorasync def main() -> None: env = BrowserEnvironment() agent = Agent(environment=env) try: max_attempts = 3 for attempt in range(max_attempts): try: response = await agent.run( prompt="Search for complex data analysis tutorials and summarize the top 3 results", timeout=60, generate_gif=True, ) print("Task completed successfully!") print(response.text) break except NaradaTimeoutError: if attempt == max_attempts - 1: raise print(f"Attempt {attempt + 1} timed out, retrying...") await agent.reset_agent_state() finally: await env.close()if __name__ == "__main__": asyncio.run(main())
import asynciofrom narada import Agent, AgentKind, BrowserEnvironmentfrom pydantic import BaseModel, Fieldclass InvoiceData(BaseModel): invoice_number: str = Field(description="Invoice number") date: str = Field(description="Invoice date") vendor_name: str = Field(description="Vendor or supplier name") total_amount: str = Field(description="Total amount with currency") line_items: list[str] = Field(description="List of items or services")async def main() -> None: env = BrowserEnvironment() agent = Agent(environment=env, kind=AgentKind.CORE_AGENT) try: with open("/path/to/invoice.pdf", "rb") as f: response = await agent.run( prompt="Extract the invoice details from the attached document.", attachment=f, output_schema=InvoiceData, ) invoice = response.structured_output assert invoice is not None print(f"Invoice: {invoice.invoice_number}") print(f"Date: {invoice.date}") print(f"Vendor: {invoice.vendor_name}") print(f"Total: {invoice.total_amount}") print(f"Items: {', '.join(invoice.line_items)}") finally: await env.close()if __name__ == "__main__": asyncio.run(main())
Older SDK examples used a Narada client and window object:
async with Narada() as narada: window = await narada.open_and_initialize_browser_window() response = await window.agent(prompt='search for "jobs" on Google')
Use an environment and agent instead:
env = BrowserEnvironment()agent = Agent(environment=env)try: response = await agent.run(prompt='search for "jobs" on Google') print(response.text)finally: await env.close()