ReasonKit Web Integration Patterns
Version: 0.1.0 Focus: Common use cases and architectural patterns for integrating ReasonKit Web.
Pattern 1: The Research Agent
This pattern uses ReasonKit Web as the primary information gathering tool for a research agent. The agent alternates between searching/navigating and reading/extracting.
Workflow
- Search: Agent uses
web_navigateto a search engine (e.g., Google, Bing). - Analyze Results: Agent uses
web_extract_linksto find relevant result URLs. - Deep Dive: For each relevant URL:
web_navigateto the URL.web_extract_content(Markdown format) to read the page.web_extract_metadatato get author/date info.
- Synthesize: Agent combines extracted content into a summary.
Example Sequence (JSON-RPC)
// 1. Navigate to search
{"method": "tools/call", "params": {"name": "web_navigate", "arguments": {"url": "https://www.google.com/search?q=rust+mcp+server"}}}
// 2. Extract links
{"method": "tools/call", "params": {"name": "web_extract_links", "arguments": {"url": "current", "selector": "#search"}}}
// 3. Navigate to result
{"method": "tools/call", "params": {"name": "web_navigate", "arguments": {"url": "https://modelcontextprotocol.io"}}}
// 4. Extract content
{"method": "tools/call", "params": {"name": "web_extract_content", "arguments": {"url": "current", "format": "markdown"}}}
Pattern 2: The Visual Validator
This pattern is useful for frontend testing or design validation agents. It relies heavily on screenshots and visual data.
Workflow
- Navigate: Go to the target web application.
- Capture State: Take a
web_screenshotof the initial state. - Action: Use
web_execute_jsto trigger an interaction (e.g., click a button, fill a form). - Wait: Implicitly handled by
web_execute_jspromise resolution or explicitwaitForin navigation. - Verify: Take another
web_screenshotto verify the UI change.
Best Practices
- Use
fullPage: truefor design reviews. - Use specific
selectorscreenshots for component testing. - Combine with a Vision-Language Model (VLM) like Claude 3.5 Sonnet to analyze the images.
Pattern 3: The Archivist
This pattern is for compliance, auditing, or data preservation agents. It focuses on capturing high-fidelity records of web pages.
Workflow
- Discovery: Agent identifies a list of URLs to archive.
- Forensic Capture: For each URL:
web_navigateto ensure the page loads.web_capture_mhtmlto get a single-file archive of all resources (HTML, CSS, Images).web_pdfto get a printable, immutable document version.web_extract_metadatato log the timestamp and original metadata.
- Storage: Save the artifacts (MHTML, PDF, JSON metadata) to long-term storage (S3, reasonkit-mem, etc.).
Pattern 4: The Data Scraper (Structured)
This pattern extracts structured data (tables, lists, specific fields) from unstructured web pages.
Workflow
- Navigate: Go to the page containing data.
- Schema Injection: Agent constructs a JavaScript function to traverse the DOM and extract specific fields into a JSON object.
- Execution: Use
web_execute_jsto run the extraction script.- Why JS? It’s often more reliable/precise for structured data than converting the whole page to Markdown and asking the LLM to parse it back out.
- Validation: Agent validates the returned JSON structure.
Example JS Payload
// Passed to web_execute_js
Array.from(document.querySelectorAll('table.data tr')).map(row => {
const cells = row.querySelectorAll('td');
return {
id: cells[0]?.innerText,
name: cells[1]?.innerText,
status: cells[2]?.innerText
};
})
Pattern 5: The Session Manager (Authenticated)
Handling authenticated sessions (login walls).
Approaches
-
Pre-authenticated Profile:
- Launch Chrome manually with a specific user data directory.
- Log in to the required services.
- Point
reasonkit-webto use that existing user data directory via environment variables or arguments (if supported by your specific deployment) or by ensuring theCHROME_PATHuses the profile. - Note: Currently,
reasonkit-webstarts fresh sessions by default. For persistent sessions, you may need to modify the browser launch arguments insrc/browser/mod.rsto point to a user data dir.
-
Agent Login:
- Agent navigates to login page.
- Agent uses
web_execute_jsto fill username/password fields (retrieved securely from env/secrets, NEVER hardcoded). - Agent submits form.
- Agent handles 2FA (if possible, or flags for human intervention).
Error Handling Patterns
- Retry Logic: If
web_navigatefails (timeout/network), implement an exponential backoff retry in the agent logic. - Fallback: If
web_extract_content(Markdown) is messy/empty, tryweb_extract_content(Text) orweb_screenshot+ OCR. - Stealth: If blocked (403/Captcha), ensure the underlying browser is using stealth plugins (ReasonKit Web does this by default, but aggressive blocking may require slower interactions).