parent
01c670f687
commit
05d3caa8ae
@ -0,0 +1,57 @@
|
|||||||
|
# Advanced Research
|
||||||
|
|
||||||
|
An enhanced implementation of the orchestrator-worker pattern from Anthropic's paper, "How we built our multi-agent research system", built on top of the bleeding-edge multi-agent framework [swarms](https://github.com/kyegomez/swarms). Our implementation of this advanced research system leverages parallel execution, LLM-as-judge evaluation, and professional report generation with export capabilities.
|
||||||
|
|
||||||
|
**Repository**: [AdvancedResearch](https://github.com/The-Swarm-Corporation/AdvancedResearch)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install -U advanced-research
|
||||||
|
|
||||||
|
# uv pip install -U advanced-research
|
||||||
|
```
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
```txt
|
||||||
|
# Exa Search API Key (Required for web search functionality)
|
||||||
|
EXA_API_KEY="your_exa_api_key_here"
|
||||||
|
|
||||||
|
# Anthropic API Key (For Claude models)
|
||||||
|
ANTHROPIC_API_KEY="your_anthropic_api_key_here"
|
||||||
|
|
||||||
|
# OpenAI API Key (For GPT models)
|
||||||
|
OPENAI_API_KEY="your_openai_api_key_here"
|
||||||
|
|
||||||
|
# Worker Agent Configuration
|
||||||
|
WORKER_MODEL_NAME="gpt-4.1"
|
||||||
|
WORKER_MAX_TOKENS=8000
|
||||||
|
|
||||||
|
# Exa Search Configuration
|
||||||
|
EXA_SEARCH_NUM_RESULTS=2
|
||||||
|
EXA_SEARCH_MAX_CHARACTERS=100
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: At minimum, you need `EXA_API_KEY` for web search functionality. For LLM functionality, you need either `ANTHROPIC_API_KEY` or `OPENAI_API_KEY`.
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Basic Usage
|
||||||
|
|
||||||
|
```python
|
||||||
|
from advanced_research import AdvancedResearch
|
||||||
|
|
||||||
|
# Initialize the research system
|
||||||
|
research_system = AdvancedResearch(
|
||||||
|
name="AI Research Team",
|
||||||
|
description="Specialized AI research system",
|
||||||
|
max_loops=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run research and get results
|
||||||
|
result = research_system.run(
|
||||||
|
"What are the latest developments in quantum computing?"
|
||||||
|
)
|
||||||
|
print(result)
|
||||||
|
```
|
@ -0,0 +1,111 @@
|
|||||||
|
# Browser Automation with Swarms
|
||||||
|
|
||||||
|
This example demonstrates how to use browser automation capabilities within the Swarms framework. The `BrowserUseAgent` class provides a powerful interface for web scraping, navigation, and automated browser interactions using the `browser_use` library. This is particularly useful for tasks that require real-time web data extraction, form filling, or web application testing.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install -U swarms browser-use python-dotenv langchain-openai
|
||||||
|
```
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
```txt
|
||||||
|
# OpenAI API Key (Required for LLM functionality)
|
||||||
|
OPENAI_API_KEY="your_openai_api_key_here"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Main Code
|
||||||
|
|
||||||
|
```python
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from browser_use import Agent as BrowserAgent
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from langchain_openai import ChatOpenAI
|
||||||
|
|
||||||
|
from swarms import Agent
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
|
class BrowserUseAgent:
|
||||||
|
def __init__(self, agent_name: str = "BrowserAgent", agent_description: str = "A browser agent that can navigate the web and perform tasks."):
|
||||||
|
"""
|
||||||
|
Initialize a BrowserAgent with a given name.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
agent_name (str): The name of the browser agent.
|
||||||
|
"""
|
||||||
|
self.agent_name = agent_name
|
||||||
|
self.agent_description = agent_description
|
||||||
|
|
||||||
|
async def browser_agent_test(self, task: str):
|
||||||
|
"""
|
||||||
|
Asynchronously run the browser agent on a given task.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
task (str): The task prompt for the agent.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Any: The result of the agent's run method.
|
||||||
|
"""
|
||||||
|
agent = BrowserAgent(
|
||||||
|
task=task,
|
||||||
|
llm=ChatOpenAI(model="gpt-4.1"),
|
||||||
|
)
|
||||||
|
result = await agent.run()
|
||||||
|
return result.model_dump_json(indent=4)
|
||||||
|
|
||||||
|
def run(self, task: str):
|
||||||
|
"""
|
||||||
|
Run the browser agent synchronously on a given task.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
task (str): The task prompt for the agent.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Any: The result of the agent's run method.
|
||||||
|
"""
|
||||||
|
return asyncio.run(self.browser_agent_test(task))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def browser_agent_tool(task: str):
|
||||||
|
"""
|
||||||
|
Executes a browser automation agent as a callable tool.
|
||||||
|
|
||||||
|
This function instantiates a `BrowserAgent` and runs it synchronously on the provided task prompt.
|
||||||
|
The agent will use a language model to interpret the task, control a browser, and return the results
|
||||||
|
as a JSON-formatted string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
task (str):
|
||||||
|
A detailed instruction or prompt describing the browser-based task to perform.
|
||||||
|
For example, you can instruct the agent to navigate to a website, extract information,
|
||||||
|
or interact with web elements.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str:
|
||||||
|
The result of the browser agent's execution, formatted as a JSON string. The output
|
||||||
|
typically includes the agent's findings, extracted data, and any relevant observations
|
||||||
|
from the automated browser session.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
result = browser_agent_tool(
|
||||||
|
"Please navigate to https://www.coingecko.com and identify the best performing cryptocurrency coin over the past 24 hours."
|
||||||
|
)
|
||||||
|
print(result)
|
||||||
|
"""
|
||||||
|
return BrowserAgent().run(task)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
agent = Agent(
|
||||||
|
name = "Browser Agent",
|
||||||
|
model_name = "gpt-4.1",
|
||||||
|
tools = [browser_agent_tool],
|
||||||
|
)
|
||||||
|
|
||||||
|
agent.run("Please navigate to https://www.coingecko.com and identify the best performing cryptocurrency coin over the past 24 hours.")
|
||||||
|
```
|
@ -0,0 +1,48 @@
|
|||||||
|
# Web Search with Exa
|
||||||
|
|
||||||
|
|
||||||
|
Exa is a powerful web search API that provides real-time access to current web information. It allows AI agents to search the internet and retrieve up-to-date information on any topic, making it an essential tool for agents that need current knowledge beyond their training data.
|
||||||
|
|
||||||
|
Key features of Exa:
|
||||||
|
|
||||||
|
| Feature | Description |
|
||||||
|
|--------------------------|--------------------------------------------------------------------|
|
||||||
|
| **Real-time search** | Access the latest information from the web |
|
||||||
|
| **Semantic search** | Find relevant results using natural language queries |
|
||||||
|
| **Comprehensive coverage** | Search across billions of web pages |
|
||||||
|
| **Structured results** | Get clean, formatted search results for easy processing |
|
||||||
|
| **API integration** | Simple REST API for seamless integration with AI applications |
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip3 install -U swarms swarms-tools
|
||||||
|
```
|
||||||
|
|
||||||
|
## ENV
|
||||||
|
|
||||||
|
```txt
|
||||||
|
# Get your API key from exa
|
||||||
|
EXA_SEARCH_API=""
|
||||||
|
|
||||||
|
OPENAI_API_KEY=""
|
||||||
|
|
||||||
|
WORKSPACE_DIR=""
|
||||||
|
```
|
||||||
|
|
||||||
|
## Code
|
||||||
|
|
||||||
|
```python
|
||||||
|
from swarms import Agent
|
||||||
|
from swarms_tools import exa_search
|
||||||
|
|
||||||
|
|
||||||
|
agent = Agent(
|
||||||
|
name="Exa Search Agent",
|
||||||
|
llm="gpt-4o-mini",
|
||||||
|
tools=[exa_search],
|
||||||
|
)
|
||||||
|
|
||||||
|
out = agent.run("What are the latest experimental treatments for diabetes?")
|
||||||
|
print(out)
|
||||||
|
```
|
@ -0,0 +1,11 @@
|
|||||||
|
from swarms import Agent
|
||||||
|
from swarms_tools import exa_search
|
||||||
|
|
||||||
|
|
||||||
|
agent = Agent(
|
||||||
|
name="Exa Search Agent",
|
||||||
|
llm="gpt-4o-mini",
|
||||||
|
tools=[exa_search],
|
||||||
|
)
|
||||||
|
|
||||||
|
agent.run("What are the latest experimental treatments for diabetes?")
|
@ -0,0 +1,90 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
from browser_use import Agent as BrowserAgent
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from langchain_openai import ChatOpenAI
|
||||||
|
|
||||||
|
from swarms import Agent
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
|
class BrowserUseAgent:
|
||||||
|
def __init__(self, agent_name: str = "BrowserAgent", agent_description: str = "A browser agent that can navigate the web and perform tasks."):
|
||||||
|
"""
|
||||||
|
Initialize a BrowserAgent with a given name.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
agent_name (str): The name of the browser agent.
|
||||||
|
"""
|
||||||
|
self.agent_name = agent_name
|
||||||
|
self.agent_description = agent_description
|
||||||
|
|
||||||
|
async def browser_agent_test(self, task: str):
|
||||||
|
"""
|
||||||
|
Asynchronously run the browser agent on a given task.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
task (str): The task prompt for the agent.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Any: The result of the agent's run method.
|
||||||
|
"""
|
||||||
|
agent = BrowserAgent(
|
||||||
|
task=task,
|
||||||
|
llm=ChatOpenAI(model="gpt-4.1"),
|
||||||
|
)
|
||||||
|
result = await agent.run()
|
||||||
|
return result.model_dump_json(indent=4)
|
||||||
|
|
||||||
|
def run(self, task: str):
|
||||||
|
"""
|
||||||
|
Run the browser agent synchronously on a given task.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
task (str): The task prompt for the agent.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Any: The result of the agent's run method.
|
||||||
|
"""
|
||||||
|
return asyncio.run(self.browser_agent_test(task))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def browser_agent_tool(task: str):
|
||||||
|
"""
|
||||||
|
Executes a browser automation agent as a callable tool.
|
||||||
|
|
||||||
|
This function instantiates a `BrowserAgent` and runs it synchronously on the provided task prompt.
|
||||||
|
The agent will use a language model to interpret the task, control a browser, and return the results
|
||||||
|
as a JSON-formatted string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
task (str):
|
||||||
|
A detailed instruction or prompt describing the browser-based task to perform.
|
||||||
|
For example, you can instruct the agent to navigate to a website, extract information,
|
||||||
|
or interact with web elements.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str:
|
||||||
|
The result of the browser agent's execution, formatted as a JSON string. The output
|
||||||
|
typically includes the agent's findings, extracted data, and any relevant observations
|
||||||
|
from the automated browser session.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
result = browser_agent_tool(
|
||||||
|
"Please navigate to https://www.coingecko.com and identify the best performing cryptocurrency coin over the past 24 hours."
|
||||||
|
)
|
||||||
|
print(result)
|
||||||
|
"""
|
||||||
|
return BrowserAgent().run(task)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
agent = Agent(
|
||||||
|
name = "Browser Agent",
|
||||||
|
model_name = "gpt-4.1",
|
||||||
|
tools = [browser_agent_tool],
|
||||||
|
)
|
||||||
|
|
||||||
|
agent.run("Please navigate to https://www.coingecko.com and identify the best performing cryptocurrency coin over the past 24 hours.")
|
Loading…
Reference in new issue