Code Examples
Learn by example. Copy, paste, and modify these working Agent Forge examples to jumpstart your AI agent development.
Simple Navigation Agent
Navigate to URLs and extract basic page information
NavigationBasic
from agent_forge import BaseAgent
class NavigationAgent(BaseAgent):
async def run(self, url: str):
page = await self.browser_client.navigate(url)
return page.get('page_title')
Content Extraction Agent
Extract specific content using CSS selectors
ExtractionCSS Selectors
from agent_forge import BaseAgent
class ContentAgent(BaseAgent):
async def run(self, url: str):
content = await self.browser_client.extract_content(
url,
selectors={
'title': 'h1',
'description': 'meta[name="description"]'
}
)
return content
Form Automation Agent
Automate form filling and submission
FormsAutomation
from agent_forge import BaseAgent
class FormAgent(BaseAgent):
async def run(self, form_data: dict):
await self.browser_client.navigate("https://example.com/form")
for field, value in form_data.items():
await self.browser_client.type(f"input[name='{field}']", value)
await self.browser_client.click("button[type='submit']")
return "Form submitted successfully"
Multi-Page Scraper
Scrape data from multiple pages efficiently
Multi-pageConcurrency
from agent_forge import BaseAgent
import asyncio
class MultiPageAgent(BaseAgent):
async def run(self, urls: list):
tasks = [self.scrape_page(url) for url in urls]
results = await asyncio.gather(*tasks)
return results
async def scrape_page(self, url: str):
page = await self.browser_client.navigate(url)
return {
'url': url,
'title': page.get('page_title'),
'content_length': len(page.get('content', ''))
}
Want More Examples?
Check out our GitHub repository for additional examples and community contributions.