100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.
fix(ai_deep_research_agent): update Firecrawl calls for firecrawl-py v4
Juampi86076345daf2
diff --git a/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/README.md b/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/README.mdindex 08aa7ec1..dda34a78 100644--- a/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/README.md+++ b/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/README.md@@ -3,7 +3,7 @@### π FREE Step-by-Step Tutorial**π [Click here to follow our complete step-by-step tutorial](https://www.theunwindai.com/p/build-a-deep-research-agent-with-openai-agents-sdk-and-firecrawl) and learn how to build this from scratch with detailed code walkthroughs, explanations, and best practices.**-A powerful research assistant that leverages OpenAI's Agents SDK and Firecrawl's deep research capabilities to perform comprehensive web research on any topic and any question.+A powerful research assistant that leverages OpenAI's Agents SDK and Firecrawl's search to perform comprehensive web research on any topic and any question.## Features@@ -69,9 +69,9 @@ A powerful research assistant that leverages OpenAI's Agents SDK and Firecrawl'sThe application uses two specialized agents:-1. **Research Agent**: Utilizes Firecrawl's deep research endpoint to gather comprehensive information from multiple web sources.+1. **Research Agent**: Utilizes [Firecrawl Search](https://docs.firecrawl.dev/features/search?utm_source=awesome-llm-apps&utm_medium=integration) to gather comprehensive information from multiple web sources.2. **Elaboration Agent**: Enhances the initial research by adding detailed explanations, examples, case studies, and practical implications.-The Firecrawl deep research tool performs multiple iterations of web searches, content extraction, and analysis to provide thorough coverage of the topic.+The research agent runs several Firecrawl searches from different angles. Each search returns the result pages as markdown, and the agent runs follow-up searches where it finds gaps before writing the report.diff --git a/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/deep_research_openai.py b/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/deep_research_openai.pyindex db897c33..78589686 100644--- a/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/deep_research_openai.py+++ b/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/deep_research_openai.py@@ -3,7 +3,8 @@ import streamlit as stfrom typing import Dict, Any, Listfrom agents import Agent, Runner, tracefrom agents import set_default_openai_key-from firecrawl import FirecrawlApp+from firecrawl import AsyncFirecrawl+from firecrawl.types import Document, ScrapeOptionsfrom agents.tool import function_tool# Set page configuration@@ -46,43 +47,45 @@ st.markdown("This OpenAI Agent from the OpenAI Agents SDK performs deep research# Research topic inputresearch_topic = st.text_input("Enter your research topic:", placeholder="e.g., Latest developments in AI")-# Keep the original deep_research tool+# Firecrawl search tool: finds sources and returns each page as markdown@function_tool-async def deep_research(query: str, max_depth: int, time_limit: int, max_urls: int) -> Dict[str, Any]:+async def search_web(query: str) -> Dict[str, Any]:"""- Perform comprehensive web research using Firecrawl's deep research endpoint.+ Search the web with Firecrawl and return the title, URL and page content of the top 5 results."""try:- # Initialize FirecrawlApp with the API key from session state- firecrawl_app = FirecrawlApp(api_key=st.session_state.firecrawl_api_key)-- # Define research parameters- params = {- "maxDepth": max_depth,- "timeLimit": time_limit,- "maxUrls": max_urls- }-- # Set up a callback for real-time updates- def on_activity(activity):- st.write(f"[{activity['type']}] {activity['message']}")-- # Run deep research- with st.spinner("Performing deep research..."):- results = firecrawl_app.deep_research(- query=query,- params=params,- on_activity=on_activity+ # Initialize Firecrawl with the API key from session state+ firecrawl_app = AsyncFirecrawl(api_key=st.session_state.firecrawl_api_key, origin="awesome-llm-apps")++ # Search and scrape the result pages in one call+ with st.spinner(f"Searching: {query}"):+ results = await firecrawl_app.search(+ query,+ limit=5,+ scrape_options=ScrapeOptions(formats=["markdown"], only_main_content=True))-++ sources = []+ for result in results.web or []:+ if isinstance(result, Document): # page was scraped+ meta = result.metadata+ title = meta.title if meta else None+ url = (meta.url or meta.source_url) if meta else None+ content = result.markdown or ""+ else: # page could not be scraped, keep the search snippet+ title, url, content = result.title, result.url, result.description or ""+ if url:+ # Truncate each page so the agent's context stays bounded+ sources.append({"title": title, "url": url, "content": content[:4000]})++ st.write(f"[search] {query}: {len(sources)} sources")return {"success": True,- "final_analysis": results['data']['finalAnalysis'],- "sources_count": len(results['data']['sources']),- "sources": results['data']['sources']+ "sources_count": len(sources),+ "sources": sources}except Exception as e:- st.error(f"Deep research error: {str(e)}")+ st.error(f"Search error: {str(e)}")return {"error": str(e), "success": False}# Keep the original agents@@ -91,17 +94,16 @@ research_agent = Agent(instructions="""You are a research assistant that can perform deep web research on any topic.When given a research topic or question:- 1. Use the deep_research tool to gather comprehensive information- - Always use these parameters:- * max_depth: 3 (for moderate depth)- * time_limit: 180 (3 minutes)- * max_urls: 10 (sufficient sources)- 2. The tool will search the web, analyze multiple sources, and provide a synthesis- 3. Review the research results and organize them into a well-structured report- 4. Include proper citations for all sources+ 1. Break the topic into 3 to 5 focused search queries that cover different angles+ 2. Use the search_web tool for each query+ - Each result includes the page title, URL and page content+ - Run follow-up searches if the first results leave gaps+ - Run at most 6 searches in total+ 3. Read and compare the sources, then organize the findings into a well-structured report+ 4. Include proper citations (title and URL) for all sources5. Highlight key findings and insights""",- tools=[deep_research]+ tools=[search_web])elaboration_agent = Agent(diff --git a/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/requirements.txt b/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/requirements.txtindex 810e0d08..326eaeaa 100644--- a/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/requirements.txt+++ b/advanced_ai_agents/single_agent_apps/ai_deep_research_agent/requirements.txt@@ -1,4 +1,3 @@openai-agents-firecrawlstreamlit-firecrawl-py\ No newline at end of file+firecrawl-py>=4.46.0\ No newline at end of file