-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Implementing a GoogleSearch Agent #19462
-
I'd like to implement a google search agent and insert it into my workflow, but there seemed to be an error with the creation of the tool. Firstly the tool itself:
from llama_index.tools.google.search.base import GoogleSearchToolSpec from llama_index.core.tools.tool_spec.load_and_search import LoadAndSearchToolSpec from utils.logger import logger from config.settings import load_config config = load_config() google_config = config.get("google", {}) API_KEY = google_config.get("google_api_key") CSE_ID = google_config.get("google_cse_id") google_tools = [] try: google_spec = GoogleSearchToolSpec(key=API_KEY, engine=CSE_ID, num=5) google_tools = LoadAndSearchToolSpec.from_defaults( google_spec.to_tool_list()[0] ).to_tool_list() logger.info( f"Loaded Google search tools: {[t.metadata.name for t in google_tools]}" ) except Exception as e: logger.error(f"Failed to initialize GoogleSearchToolSpec: {e}") # Export to web_search_agent web_search_tools_llama = google_tools
then the agent:
from llama_index.core.agent.workflow import FunctionAgent from tools.web_search_tool import web_search_tools_llama from utils.logger import logger def build_web_search_agent(llm): logger.info("Initializing Web Search agent and tool...") if not web_search_tools_llama: raise ValueError("Web search tool is not loaded.") agent = FunctionAgent( name="WebSearchAgent", description="Performs live web searches and returns summarized results.", system_prompt=( "You are a web search specialist. Use the provided tools to search online " "and deliver concise findings." ), llm=llm, tools=web_search_tools_llama, ) logger.info("Web Search agent initialized successfully.") return agent
This the call into the workflow:
class ClinicalCDSSWorkflow(Workflow): def __init__(self, llm, query_engine, **kwargs): super().__init__(**kwargs) # Directly use the tools or specialized agents self.guideline_tool = guideline_query_tool_factory(query_engine) self.survival_prediction_tool = survival_prediction_tool self.web_search_agent = build_web_search_agent(llm) self.image_analysis_tool = all_image_analysis_tool self.papers_search_agent = build_papers_search_agent(llm)
finally this is the error:
Traceback (most recent call last):
File "/path/to/your/project/main.py", line 86, in <module>
asyncio.run(main())
File "/usr/local/lib/python3.12/asyncio/runners.py", line 195, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/path/to/your/project/main.py", line 56, in main
await run_clinical_agentic_workflow(llm, query_engine, q1)
File "/path/to/your/project/core/clinical_agentic_workflow.py", line 188, in run_clinical_agentic_workflow
workflow = ClinicalCDSSWorkflow(llm, query_engine, timeout=120)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/your/project/core/clinical_agentic_workflow.py", line 62, in __init__
self.web_search_agent = build_web_search_agent(llm)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/your/project/agents/web_search_agent.py", line 9, in build_web_search_agent
raise ValueError("Web search tool is not loaded.")
ValueError: Web search tool is not loaded.
Any help would be much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
A few things to check:
- Make sure API_KEY and CSE_ID are actually loaded from your config and are not None or empty. Try printing them right before you create GoogleSearchToolSpec.
- The num parameter must be between 1 and 10—recent versions of llama-index-tools-google enforce this strictly and will raise a ValueError otherwise (see PR #19250).
- Ensure you have llama-index-tools-google >=0.5.0 and httpx installed, as the tool now uses httpx for HTTP requests (see PR #19250).
- If you’re still getting the error, check your logs for the exact exception message from the failed initialization—this will pinpoint if it’s a config, dependency, or parameter issue.
- Try hardcoding the API key and CSE ID to rule out config loading issues.
Recent updates to the tool also changed how results are parsed and returned, so keeping your dependencies up to date is important (see PR #19246). If you follow these steps and still hit the error, share the specific log message from the failed initialization for more targeted help.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other Join Discord Share on X
Beta Was this translation helpful? Give feedback.