Notice: The Dendrite SDK is not under active development anymore. However, the project will remain fully open source so that you and others can learn from it. Feel free to fork, study, or adapt this code for your own projects as you wish β reach out to us on Discord if you have questions! We love chatting about web AI agents. π€
Dendrite is a framework that makes it easy for web AI agents to browse the internet just like humans do. Use Dendrite to:
- ππΌ Interact with elements
- πΏ Extract structured data
- π Authenticate on websites
βοΈ Download/upload files- π« Browse without getting blocked
With Dendrite it's easy to create web interaction tools for your agent.
Here's how you can send an email:
from dendrite import AsyncDendrite
async def send_email(to, subject, message):
client = AsyncDendrite(auth="outlook.live.com")
# Navigate
await client.goto(
"https://outlook.live.com/mail/0/", expected_page="An email inbox"
)
# Create new email and populate fields
await client.click("The new email button")
await client.fill("The recipient field", to)
await client.press("Enter")
await client.fill("The subject field", subject)
await client.fill("The message field", message)
# Send email
await client.press("Enter", hold_cmd=True)
if __name__ == "__main__":
import asyncio
asyncio.run(send_email("[email protected]", "Hello", "This is a test email"))
You'll need to add your own Anthropic key or configure which LLMs to use yourself.
ANTHROPIC_API_KEY=sk-...
To authenticate on any web service with Dendrite, follow these steps:
- Run the authentication command
dendrite auth --url outlook.live.com
-
This command will open a browser that you'll be able to login with.
-
After you've logged in, press enter in your terminal. This will save your cookies locally so that they can be used in your code.
Read more about authentication in our docs.
pip install dendrite && dendrite install
from dendrite import AsyncDendrite
async def main():
client = AsyncDendrite()
await client.goto("https://google.com")
await client.fill("Search field", "Hello world")
await client.press("Enter")
if __name__ == "__main__":
import asyncio
asyncio.run(main())
In the example above, we simply go to Google, populate the search field with "Hello world" and simulate a keypress on Enter. It's a simple example that starts to explore the endless possibilities with Dendrite. Now you can create tools for your agents that have access to the full web without depending on APIs.
This is a simple example of how to get any page as markdown, great for feeding to an LLM.
from dendrite import AsyncDendrite
from dotenv import load_dotenv
async def main():
browser = AsyncDendrite()
await browser.goto("https://dendrite.systems")
await browser.wait_for("the page to load")
# Get the entire page as markdown
md = await browser.markdown()
print(md)
print("=" * 200)
# Only get a certain part of the page as markdown
data_extraction_md = await browser.markdown("the part about data extraction")
print(data_extraction_md)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
The classic web data extraction test, made easy:
from dendrite import AsyncDendrite
import pprint
import asyncio
async def main():
browser = AsyncDendrite()
# Navigate
await browser.goto("https://www.ycombinator.com/companies")
# Find and fill the search field with "AI agent"
await browser.fill(
"Search field", value="AI agent"
) # Element selector cached since before
await browser.press("Enter")
# Extract startups with natural language description
# Once created by our agent, the same script will be cached and reused
startups = await browser.extract(
"All companies. Return a list of dicts with name, location, description and url"
)
pprint.pprint(startups, indent=2)
if __name__ == "__main__":
asyncio.run(main())
returns
[ { 'description': 'Book accommodations around the world.',
'location': 'San Francisco, CA, USA',
'name': 'Airbnb',
'url': 'https://www.ycombinator.com/companies/airbnb'},
{ 'description': 'Digital Analytics Platform',
'location': 'San Francisco, CA, USA',
'name': 'Amplitude',
'url': 'https://www.ycombinator.com/companies/amplitude'},
...
] }
Here's how to get the amount of monthly visitors from Google Analytics using the extract
function:
async def get_visitor_count() -> int:
client = AsyncDendrite(auth="analytics.google.com")
await client.goto(
"https://analytics.google.com/analytics/web",
expected_page="Google Analytics dashboard"
)
# The Dendrite extract agent will create a web script that is cached
# and reused. It will self-heal when the website updates
visitor_count = await client.extract("The amount of visitors this month", int)
return visitor_count
Here's tool that allows our AI agent to download our bank's monthly transactions so that they can be analyzed and compiled into a report.
from dendrite import AsyncDendrite
async def get_transactions() -> str:
client = AsyncDendrite(auth="mercury.com")
# Navigate and wait for loading
await client.goto(
"https://app.mercury.com/transactions",
expected_page="Dashboard with transactions"
)
await client.wait_for("The transactions to finish loading")
# Modify filters
await client.click("The 'add filter' button")
await client.click("The 'show transactions for' dropdown")
await client.click("The 'this month' option")
# Download file
await client.click("The 'export filtered' button")
transactions = await client.get_download()
# Save file locally
path = "files/transactions.xlsx"
await transactions.save_as(path)
return path
async def analyze_transactions(path: str):
... # Analyze the transactions with LLM of our choice
Find more advanced examples in our docs.
When you want to scale up your AI agents, we support using browsers hosted by Browserbase. This way you can run many agents in parallel without having to worry about the infrastructure.
To start using Browserbase just swap out the AsyncDendrite
class with AsyncDendriteRemoteBrowser
and add your Browserbase API key and project id, either in the code or in a .env
file like this:
# ... previous keys
BROWSERBASE_API_KEY=
BROWSERBASE_PROJECT_ID=
# from dendrite import AsyncDendrite
from dendrite import AsyncDendriteRemoteBrowser
async def main():
# client = AsyncDendrite(...)
client = AsyncDendriteRemoteBrowser(
# Use interchangeably with the AsyncDendrite class
browserbase_api_key="...", # or specify the browsebase keys in the .env file
browserbase_project_id="..."
)
...
if __name__ == "__main__":
import asyncio
asyncio.run(main())