An AI coding agent that researches before writing code — so it never recommends deprecated libraries or hallucinated APIs.
Instead of generating code from stale training data, this agent uses BrowseAI to search the web, verify that recommended packages actually exist on PyPI, check for deprecation notices, and only then generates code using verified libraries.
The agent runs three phases for every coding task:
The agent uses session.ask() with depth="thorough" to search the web for the best libraries and frameworks for your task. Thorough mode automatically rephrases and retries the query when initial confidence is below 60%, ensuring high-quality results.
The output includes:
- Recommended libraries with their features
- Confidence score (evidence-based algorithm)
- Number of verified claims and sources consulted
- Any contradictions found in the research
Every library mentioned in the research is individually verified:
- Does the package exist on PyPI?
- Is it deprecated or archived?
- What is the latest version?
- When was the last release?
Libraries that fail verification are flagged and excluded from code generation.
The agent generates code using ONLY verified, actively maintained libraries. Each library choice is backed by citations showing why it was selected, with consensus levels and source counts.
Traditional coding agents generate code from LLM training data, which leads to:
- Recommending packages that don't exist (hallucinated package names)
- Using deprecated libraries (training data is months or years old)
- Calling APIs that were removed in newer versions
- Missing better alternatives released after the training cutoff
With BrowseAI, every import in the generated code maps to a real, maintained package.
pip install -r requirements.txtSet your API key:
export BROWSEAI_API_KEY=bai_xxxOr the script will prompt you for it.
python agent.py "Build a WebSocket server in Python"python agent.py
# What should I build? Build a rate limiter in PythonThe agent uses BrowseAI sessions, so knowledge accumulates. After the first task completes, you can enter another task that builds on what the agent already learned:
python agent.py "Build a WebSocket server in Python"
# After it finishes:
# Another task? (enter to quit): Add JWT authentication to the WebSocket serverThe second task benefits from the session's prior knowledge about WebSocket libraries.
python agent.py "Build a WebSocket server in Python"Phase 1 — Research:
The agent searches the web and finds that websockets is the standard async WebSocket library for Python. It also discovers aiohttp as an alternative with broader HTTP support, and notes that socket.io (via python-socketio) is popular for real-time apps.
Research Findings
The most popular Python WebSocket libraries are:
- `websockets` — Pure Python, async, standards-compliant (RFC 6455)
- `aiohttp` — Full HTTP client/server with WebSocket support
- `python-socketio` — Socket.IO protocol implementation
...
Confidence: ████████████░░░ 78%
Verified claims: 5/6
Sources consulted: 7
Phase 2 — Verification: Each library is checked against PyPI and the web:
Library Verification Results
┌──────────────────┬──────────┬────────────┬──────────────────────────┐
│ Library │ Status │ Confidence │ Notes │
├──────────────────┼──────────┼────────────┼──────────────────────────┤
│ websockets │ VERIFIED │ ████████ … │ Latest 13.x, actively… │
│ aiohttp │ VERIFIED │ ███████░ … │ Latest 3.x, maintained… │
│ python-socketio │ VERIFIED │ ███████░ … │ Latest 5.x, active… │
└──────────────────┴──────────┴────────────┴──────────────────────────┘
Phase 3 — Code Generation:
The agent generates a working WebSocket server using websockets (the top-verified choice):
import asyncio
import websockets
import json
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("websocket-server")
CONNECTIONS: set[websockets.WebSocketServerProtocol] = set()
async def handler(websocket: websockets.WebSocketServerProtocol) -> None:
CONNECTIONS.add(websocket)
logger.info(f"Client connected ({len(CONNECTIONS)} total)")
try:
async for message in websocket:
data = json.loads(message)
logger.info(f"Received: {data}")
response = json.dumps({"echo": data, "clients": len(CONNECTIONS)})
await websocket.send(response)
except websockets.ConnectionClosed:
logger.info("Client disconnected")
finally:
CONNECTIONS.remove(websocket)
async def main() -> None:
async with websockets.serve(handler, "localhost", 8765):
logger.info("WebSocket server running on ws://localhost:8765")
await asyncio.Future() # run forever
if __name__ == "__main__":
asyncio.run(main())Why websockets?
- Most downloaded async WebSocket library for Python (consensus: high, 5 sources)
- Standards-compliant RFC 6455 implementation (consensus: medium, 3 sources)
Comparison — Without vs With BrowseAI:
┌─────────────────────────┐ ┌─────────────────────────┐
│ Without BrowseAI │ │ With BrowseAI │
│ │ │ │
│ 1. Agent receives task │ │ 1. Agent receives task │
│ 2. LLM generates code │ │ 2. Researches libraries │
│ 3. Might recommend │ │ 3. Verifies on PyPI │
│ deprecated packages │ │ 4. Checks deprecation │
│ 4. Might hallucinate │ │ 5. Confirms latest APIs │
│ non-existent APIs │ │ 6. Generates with cites │
│ 5. No verification │ │ │
│ │ │ Result: Every import │
│ Risk: Code breaks at │ │ maps to a real package │
│ install or runtime │ │ with verified APIs │
└─────────────────────────┘ └─────────────────────────┘
The agent creates a BrowseAI session called coding-agent. Each research query adds verified claims to the session's knowledge graph. When you ask a follow-up task, the session recalls relevant prior knowledge automatically.
This means:
- The agent doesn't re-research libraries it already verified
- Follow-up tasks can reference prior findings
- You can export the session's accumulated knowledge
python agent.py "Build a rate limiter in Python"
python agent.py "Create a REST API with JWT authentication"
python agent.py "Build a CLI tool with auto-complete"
python agent.py "Create a background task queue"
python agent.py "Build a database migration system"
python agent.py "Create a real-time chat application"- Python 3.10+
- A BrowseAI API key (
bai_xxxprefix) - Dependencies:
browseaidev,rich
Apache 2.0 — part of the BrowseAI Dev project.