Skip to main content
Smashing!

Lacking a good title since 1999

Making an AI Agent

Submitted by george on

I just watched the "I gave an AI agent edit access to my site" video that Dries published on writing a simple AI Agent and I thought I'd give it a go as it seemed really easy.  For my Agent I didn't want to use ChatGPT as I would probably need to pay for an API key so I've opted to use Ollama locally instead.

The demo uses the browser_use Python library module, and the docs for that show an example using ChatGPT which Dries has opted for. There's a Python library/module called LangChain which provides other AI services to Python, so I can use ChatOllama with that instead.

I have Ollama installed locally, and wanted to use the mistral model but it's a little out of date so I ran:

ollama pull mistral:latest

Seems like the best virtual environment for python these days is uv, so I installed that with homebrew:

brew install uv

Start a new project and initialise the Python virtual environment:

❯ mkdir ~/Development/ghazlewood/testing_browser_use
~ via 💎 v3.3.6
❯ cd ~/Development/ghazlewood/testing_browser_use
❯ uv venv --python 3.11
Using CPython 3.11.11 interpreter at: /usr/local/opt/python@3.11/bin/python3.11
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
Development/ghazlewood/testing_browser_use via 💎 v3.3.6 took 3s
❯ source .venv/bin/activate

Then I installed the browser_use and langchain-ollama library

Development/ghazlewood/testing_browser_use via 🐍 v3.11.11 (testing_browser_use) via 💎 v3.3.6
❯ uv pip install browser-use
Resolved 125 packages in 3.86s
  Built html2text==2024.2.26
Prepared 124 packages in 15.32s
Installed 125 packages in 734ms
+ aiohappyeyeballs==2.4.4
+ aiohttp==3.11.11
+ aiosignal==1.3.2
+ annotated-types==0.7.0
+ anthropic==0.44.0
+ anyio==4.8.0
+ argparse==1.4.0
+ attrs==24.3.0
+ babel==2.16.0
+ backoff==2.2.1
+ beautifulsoup4==4.12.3
+ boto3==1.36.3
+ botocore==1.36.3
+ browser-use==0.1.27
+ cachetools==5.5.1
+ certifi==2024.12.14
+ charset-normalizer==3.4.1
+ courlan==1.3.2
+ dateparser==1.2.0
+ defusedxml==0.7.1
+ deprecated==1.2.15
+ distro==1.9.0
+ filetype==1.2.0
+ fireworks-ai==0.15.12
+ frozenlist==1.5.0
+ google-ai-generativelanguage==0.6.15
+ google-api-core==2.24.0
+ google-api-python-client==2.159.0
+ google-auth==2.37.0
+ google-auth-httplib2==0.2.0
+ google-generativeai==0.8.4
+ googleapis-common-protos==1.66.0
+ greenlet==3.1.1
+ grpcio==1.67.1
+ grpcio-status==1.67.1
+ h11==0.14.0
+ html2text==2024.2.26
+ htmldate==1.9.3
+ httpcore==1.0.7
+ httplib2==0.22.0
+ httpx==0.28.1
+ httpx-sse==0.4.0
+ httpx-ws==0.7.1
+ idna==3.10
+ importlib-metadata==8.5.0
+ jiter==0.8.2
+ jmespath==1.0.1
+ jsonpatch==1.33
+ jsonpointer==3.0.0
+ justext==3.0.1
+ langchain==0.3.14
+ langchain-anthropic==0.3.3
+ langchain-aws==0.2.11
+ langchain-core==0.3.31
+ langchain-fireworks==0.2.6
+ langchain-google-genai==2.0.8
+ langchain-ollama==0.2.2
+ langchain-openai==0.3.1
+ langchain-text-splitters==0.3.5
+ langsmith==0.2.11
+ lmnr==0.4.55
+ lxml==5.3.0
+ lxml-html-clean==0.4.1
+ maincontentextractor==0.0.4
+ monotonic==1.6
+ multidict==6.1.0
+ numpy==1.26.4
+ ollama==0.4.7
+ openai==1.59.9
+ opentelemetry-api==1.29.0
+ opentelemetry-exporter-otlp-proto-common==1.29.0
+ opentelemetry-exporter-otlp-proto-grpc==1.29.0
+ opentelemetry-exporter-otlp-proto-http==1.29.0
+ opentelemetry-instrumentation==0.50b0
+ opentelemetry-instrumentation-langchain==0.36.1
+ opentelemetry-instrumentation-requests==0.50b0
+ opentelemetry-instrumentation-sqlalchemy==0.50b0
+ opentelemetry-instrumentation-threading==0.50b0
+ opentelemetry-instrumentation-urllib3==0.50b0
+ opentelemetry-proto==1.29.0
+ opentelemetry-sdk==1.29.0
+ opentelemetry-semantic-conventions==0.50b0
+ opentelemetry-semantic-conventions-ai==0.4.2
+ opentelemetry-util-http==0.50b0
+ orjson==3.10.15
+ packaging==24.2
+ pillow==11.1.0
+ playwright==1.49.1
+ posthog==3.9.0
+ propcache==0.2.1
+ proto-plus==1.25.0
+ protobuf==5.29.3
+ pyasn1==0.6.1
+ pyasn1-modules==0.4.1
+ pydantic==2.10.5
+ pydantic-core==2.27.2
+ pyee==12.0.0
+ pyparsing==3.2.1
+ python-dateutil==2.9.0.post0
+ python-dotenv==1.0.1
+ pytz==2024.2
+ pyyaml==6.0.2
+ regex==2024.11.6
+ requests==2.32.3
+ requests-toolbelt==1.0.0
+ rsa==4.9
+ s3transfer==0.11.1
+ setuptools==75.8.0
+ six==1.17.0
+ sniffio==1.3.1
+ soupsieve==2.6
+ sqlalchemy==2.0.37
+ tenacity==9.0.0
+ tiktoken==0.8.0
+ tld==0.13
+ tqdm==4.67.1
+ trafilatura==2.0.0
+ typing-extensions==4.12.2
+ tzlocal==5.2
+ uritemplate==4.1.1
+ urllib3==2.3.0
+ wrapt==1.17.2
+ wsproto==1.2.0
+ yarl==1.18.3
+ zipp==3.21.0
Development/ghazlewood/testing_browser_use via 🐍 v3.11.11 (testing_browser_use) via 💎 v3.3.6 took 20s
❯ playwright install
Downloading Chromium 131.0.6778.33 (playwright build v1148) from https://playwright.azureedge.net/builds/chromium/1148/chromium-mac.zip
127.1 MiB [====================] 100% 0.0s
Chromium 131.0.6778.33 (playwright build v1148) downloaded to /Users/george.hazlewood/Library/Caches/ms-playwright/chromium-1148
Downloading Chromium Headless Shell 131.0.6778.33 (playwright build v1148) from https://playwright.azureedge.net/builds/chromium/1148/chromium-headless-shell-mac.zip
79.8 MiB [====================] 100% 0.0s
Chromium Headless Shell 131.0.6778.33 (playwright build v1148) downloaded to /Users/george.hazlewood/Library/Caches/ms-playwright/chromium_headless_shell-1148
Downloading Firefox 132.0 (playwright build v1466) from https://playwright.azureedge.net/builds/firefox/1466/firefox-mac.zip
87.5 MiB [====================] 100% 0.0s
Firefox 132.0 (playwright build v1466) downloaded to /Users/george.hazlewood/Library/Caches/ms-playwright/firefox-1466
Downloading Webkit 18.2 (playwright build v2104) from https://playwright.azureedge.net/builds/webkit/2104/webkit-mac-14.zip
73 MiB [====================] 100% 0.0s
Webkit 18.2 (playwright build v2104) downloaded to /Users/george.hazlewood/Library/Caches/ms-playwright/webkit-2104
Downloading FFMPEG playwright build v1010 from https://playwright.azureedge.net/builds/ffmpeg/1010/ffmpeg-mac.zip
1.3 MiB [====================] 100% 0.0s
FFMPEG playwright build v1010 downloaded to /Users/george.hazlewood/Library/Caches/ms-playwright/ffmpeg-1010

I probably didn't need this as it was already installed by browser_use but I also ran:

Development/ghazlewood/testing_browser_use via 🐍 v3.11.11 (testing_browser_use) via 💎 v3.3.6
❯ uv pip install -U langchain-ollama
Resolved 26 packages in 454ms
Prepared 2 packages in 184ms
Uninstalled 1 package in 33ms
Installed 2 packages in 8ms
- langsmith==0.2.11
+ langsmith==0.3.0
+ zstandard==0.23.0

Now I can start writing my own agent to test with (based on a super simple example from the docs):

from langchain_ollama import ChatOllama
from browser_use import Agent
import asyncio
async def main():
   llm = ChatOllama(
       model = "mistral",
       temperature = 0.8,
       num_predict = 256,
       # other params ...
   )
   agent = Agent(
       task="Find a return flight from Dublin to New York on 1st February 2025 on Google Flights. Return me the cheapest option.",
       llm=llm,
   )
   result = await agent.run()
   print(result)
asyncio.run(main())

And run it:

uv run agent.py

boo