Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/ROLLOUT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ This guide shows how to run rollouts for the three environments using a single u

Data path default: `data/gaia/val.json`

On Python 3.10+, unconfigured GAIA runs use free, keyless Parallel Search MCP.
Configured Google credentials and explicit `--gaia_tools` lists keep their
choices. See [GAIA web search](../openmanus_rl/tools/README.md#gaia-web-search)
for installation, provider selection and page fetching.

- Dry‑run (no model calls):
- `python scripts/rollout/openmanus_rollout.py --env gaia --batch_size 2 --total_envs 4 --dry_run`

Expand Down
10 changes: 7 additions & 3 deletions openmanus_rl/environments/env_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,13 @@ def make_envs(config):
tasks_data = json.load(f)

# Get available tools from config
available_tools = getattr(config.env, 'available_tools', [
'google_search', 'wikipedia_knowledge_searcher', 'arxiv_paper_searcher'
])
from openmanus_rl.tools.search_defaults import default_search_tool
if hasattr(config.env, 'available_tools'):
available_tools = config.env.available_tools
else:
available_tools = [
default_search_tool(), 'wikipedia_knowledge_searcher', 'arxiv_paper_searcher'
]

# Build environments
_envs = build_tool_use_envs(
Expand Down
8 changes: 8 additions & 0 deletions openmanus_rl/environments/env_package/tool_use/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def reset(self, task_idx: int = None) -> Tuple[str, Dict]:
elif self.current_task_idx >= len(self.tasks_data):
self.current_task_idx = 0

self.tool_manager.start_session()
task_data = self.tasks_data[self.current_task_idx]
self.current_task_idx += 1

Expand Down Expand Up @@ -140,6 +141,7 @@ def _load_tool(self, tool_name: str):
# Map tool names to their module paths
tool_mapping = {
'google_search': 'openmanus_rl.tools.google_search.tool.Google_Search_Tool',
'parallel_search': 'openmanus_rl.tools.parallel_search.tool.ParallelSearchTool',
'wikipedia_knowledge_searcher': 'openmanus_rl.tools.wikipedia_knowledge_searcher.tool.Wikipedia_Knowledge_Searcher_Tool',
'arxiv_paper_searcher': 'openmanus_rl.tools.arxiv_paper_searcher.tool.ArXiv_Paper_Searcher_Tool',
'pubmed_search': 'openmanus_rl.tools.pubmed_search.tool.Pubmed_Search_Tool',
Expand Down Expand Up @@ -168,6 +170,12 @@ def _load_tool(self, tool_name: str):

self.available_tools[tool_name] = tool_instance

def start_session(self):
"""Start a research conversation for this environment's next task."""
tool = self.available_tools.get('parallel_search')
if tool is not None:
tool.start_session()

def get_tools_metadata(self) -> str:
"""Generate formatted metadata for all available tools"""
if not self.available_tools:
Expand Down
44 changes: 44 additions & 0 deletions openmanus_rl/tools/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@

## GAIA web search

On Python 3.10+, GAIA/tool-use runs use [Parallel Search MCP](https://docs.parallel.ai/integrations/mcp/search-mcp)
when neither `GOOGLE_API_KEY` nor `GOOGLE_CX` is set. Search uses Fast mode and
needs no account or API key. The anonymous service has usage limits; errors are
returned to the agent without switching providers or retrying automatically.
Existing Google credentials, including credentials loaded from `.env`, keep
Google selected. Set both Google variables for a working Google configuration.

Install the search dependencies in your existing rollout environment from the
repository root (they are also declared in the main dependency manifests):

```sh
pip install -r requirements-search.txt
```

`scripts/rollout/gaia.py` and `scripts/rollout/openmanus_rollout.py --env gaia`
select this default automatically. To select it explicitly, use
`--tools parallel_search wikipedia_knowledge_searcher python_code_generator`
with `gaia.py`, or `--gaia_tools` with `openmanus_rollout.py`. Explicit tool lists
and `config.env.available_tools` are used as supplied. Omit search tools from
those lists to disable web search; an empty configuration list disables all tools.
`google_search` remains available explicitly, with no fallback after an error.
Python versions before 3.10 retain the Google default.

The agent can search or fetch page excerpts using the same tool:

```text
<tool_call>
tool: parallel_search
parameters: {"query": "2024 Nobel chemistry winners"}
</tool_call>

<tool_call>
tool: parallel_search
parameters: {"urls": ["https://www.nobelprize.org/prizes/chemistry/2024/summary/"], "query": "Who won?"}
</tool_call>
```

Results include source URLs and excerpts in the next agent observation. Each
environment reset creates a new research session; related searches and fetches
within one task share it. Requests have a 30-second total timeout. This provider
does not configure the separate modular-stage `search` wrapper.

## Testing the Tools

To test the text detection tool, follow these steps:
Expand Down
Empty file.
113 changes: 113 additions & 0 deletions openmanus_rl/tools/parallel_search/tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""Anonymous Parallel Search MCP tool for one GAIA research task."""

import asyncio
import uuid
from urllib.parse import urlsplit

import anyio
import httpx
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client

from openmanus_rl.tools.base import BaseTool

MCP_URL = "https://search.parallel.ai/mcp"
USER_AGENT = "OpenManus-RL/parallel-search (+https://github.com/OpenManus/OpenManus-RL)"


class ParallelSearchTool(BaseTool):
"""Search and fetch using the same conversation ID until the task resets."""

def __init__(self, timeout=30):
super().__init__(
tool_name="parallel_search",
tool_description=(
"Search the web without an API key, or fetch relevant excerpts "
"from HTTP/HTTPS URLs. Supply query for search, urls for fetch."
),
tool_version="1.0.0",
input_types={
"query": "str - Search query, or optional focus for fetching URLs.",
"urls": "list[str] - Optional HTTP/HTTPS URLs to fetch (up to 20).",
},
output_type="dict - Source URLs, titles and excerpts, or an error.",
)
self.timeout = timeout
self.start_session()

def start_session(self):
"""Called by the owning ToolUseEnv when it starts a new task."""
self.session_id = uuid.uuid4().hex

async def _call(self, name, arguments):
# Connections are short lived; conversation identity is supplied by the
# task-owned tool, independently of the MCP transport's session ID.
with anyio.fail_after(self.timeout):
async with httpx.AsyncClient(
headers={"User-Agent": USER_AGENT},
timeout=self.timeout,
) as client, streamable_http_client(
MCP_URL,
http_client=client,
) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.call_tool(name, arguments)
if result.isError:
return {
"error": "\n".join(
block.text
for block in result.content
if block.type == "text"
)
}
if result.structuredContent is not None:
return result.structuredContent
return {
"output": "\n".join(
block.text
for block in result.content
if block.type == "text"
)
}

def execute(self, query="", urls=None):
if not isinstance(query, str):
return {"error": "query must be a string"}
if urls is not None:
if not isinstance(urls, list) or not 1 <= len(urls) <= 20:
return {"error": "urls must contain 1 to 20 HTTP/HTTPS URLs"}
for url in urls:
try:
parsed = urlsplit(url) if isinstance(url, str) else None
if (
parsed is None
or parsed.scheme not in ("http", "https")
or not parsed.hostname
or parsed.username
or parsed.password
):
return {
"error": "Only HTTP/HTTPS URLs without credentials are accepted"
}
except ValueError:
return {"error": "Invalid URL"}
name = "web_fetch"
arguments = {"urls": urls}
if query.strip():
arguments["objective"] = query[:200]
else:
if not query.strip():
return {"error": "A nonempty query is required for search"}
name = "web_search"
arguments = {"objective": query, "search_queries": [query]}
arguments["session_id"] = self.session_id
try:
return asyncio.run(self._call(name, arguments))
except TimeoutError:
return {"error": "Parallel request timed out"}
except Exception as exc:
# Do not retry another provider or regenerate the conversation ID.
while getattr(exc, "exceptions", None) and len(exc.exceptions) == 1:
exc = exc.exceptions[0]
return {"error": f"Parallel request failed: {exc}"}
19 changes: 19 additions & 0 deletions openmanus_rl/tools/search_defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Search selection for unconfigured GAIA/tool-use environments."""

import os
import sys


def default_search_tool():
# Match the existing Google tool's .env support, without overriding the
# environment. Explicit tool lists bypass this default entirely.
from dotenv import load_dotenv

load_dotenv()
if (
sys.version_info < (3, 10)
or os.getenv("GOOGLE_API_KEY")
or os.getenv("GOOGLE_CX")
):
return "google_search"
return "parallel_search"
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ authors = [

# Dependencies corresponding to install_requires in setup.py
dependencies = [
"mcp>=1.26,<2; python_version >= '3.10'",
"python-dotenv>=1,<2",
"accelerate",
"codetiming",
"datasets",
Expand Down
3 changes: 3 additions & 0 deletions requirements-search.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Optional GAIA/tool-use search dependencies (Python 3.10+).
mcp>=1.26,<2
python-dotenv>=1,<2
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
accelerate
mcp>=1.26,<2; python_version >= '3.10'
python-dotenv>=1,<2
codetiming
datasets
dill
Expand All @@ -21,4 +23,4 @@ wandb
packaging>=20.0
uvicorn
fastapi
qwen-vl-utils[decord]
qwen-vl-utils[decord]
1 change: 1 addition & 0 deletions requirements_docker.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Core dependencies for OpenManus-RL in AMD vllm Docker
mcp>=1.26,<2; python_version >= '3.10'
gymnasium==0.29.1
stable-baselines3==2.6.0
alfworld
Expand Down
1 change: 1 addition & 0 deletions scripts/docker_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ uv pip install -U openai
uv pip install Ray
uv pip install together
uv pip install wikipedia python-dotenv requests
uv pip install -r requirements-search.txt

echo "Environment setup complete!"
'
Expand Down
3 changes: 2 additions & 1 deletion scripts/rollout/gaia.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from openmanus_rl.environments.env_manager import *
from openai import OpenAI
from together import Together
from openmanus_rl.tools.search_defaults import default_search_tool


def build_env(env_name, tasks_data, available_tools, env_num=1, seed=1, history_length=2, max_steps=30):
Expand Down Expand Up @@ -143,7 +144,7 @@ def load_gaia_tasks(data_path: str, max_tasks: int = None) -> List[dict]:
parser.add_argument("--base_url", default=None, help="OpenAI-compatible base URL (e.g., vLLM http://127.0.0.1:8000/v1)")
parser.add_argument("--chat_root", default=None, help="If set, save per-episode chat histories under this root")
parser.add_argument("--data_path", default="data/gaia/val.json", help="Path to GAIA dataset")
parser.add_argument("--tools", nargs='+', default=['google_search', 'wikipedia_knowledge_searcher', 'python_code_generator'],
parser.add_argument("--tools", nargs='+', default=[default_search_tool(), 'wikipedia_knowledge_searcher', 'python_code_generator'],
help="List of available tools")
parser.add_argument("--dry_run", action="store_true", help="仅打印任务分配,不创建环境、不调用模型")
args = parser.parse_args()
Expand Down
3 changes: 2 additions & 1 deletion scripts/rollout/openmanus_rollout.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from openmanus_rl.environments.env_manager import *
from openai import OpenAI
from together import Together
from openmanus_rl.tools.search_defaults import default_search_tool

try:
import dotenv
Expand Down Expand Up @@ -361,7 +362,7 @@ def main():
parser.add_argument("--gaia_data_path", default="data/gaia/val.json",
help="Path to GAIA dataset")
parser.add_argument("--gaia_tools", nargs='+',
default=['google_search', 'wikipedia_knowledge_searcher', 'python_code_generator'],
default=[default_search_tool(), 'wikipedia_knowledge_searcher', 'python_code_generator'],
help="List of available tools for GAIA")
parser.add_argument("--webshop_train", action="store_true",
help="Use WebShop training set instead of test set")
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
__version__ = f.read().strip()

install_requires = [
"mcp>=1.26,<2; python_version >= '3.10'",
"python-dotenv>=1,<2",
"accelerate",
"codetiming",
"datasets",
Expand Down Expand Up @@ -90,4 +92,4 @@
include_package_data=True,
long_description=long_description,
long_description_content_type="text/markdown",
)
)
Loading