Last active
February 26, 2026 06:17
-
-
Save akshaykarnawat/61109c7c18a45fdb39bad2bcddcfda7b to your computer and use it in GitHub Desktop.
web search agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import date | |
| from time import sleep | |
| from selenium import webdriver | |
| from selenium.webdriver.common.by import By | |
| from selenium.webdriver.support import expected_conditions as EC | |
| from selenium.webdriver.support.ui import WebDriverWait | |
| from agents import (Agent, AsyncOpenAI, OpenAIChatCompletionsModel, Runner, | |
| function_tool, set_tracing_disabled) | |
| from agents.model_settings import ModelSettings | |
| # disable tracing | |
| set_tracing_disabled(disabled=True) | |
| # Qwen3 model running on Ollama | |
| qwen_client = AsyncOpenAI(base_url="http://localhost:11434/v1", api_key="secret_key") | |
| qwen3_model = OpenAIChatCompletionsModel(model="qwen3", openai_client=qwen_client) | |
| # web search tool | |
| @function_tool | |
| def web_search(query: str, number_of_pages_to_search: int = 1) -> dict: | |
| """Search the web using a query""" | |
| print(f"Search Query: {query}, num of pages to search: {number_of_pages_to_search}") | |
| op = webdriver.ChromeOptions() | |
| # op.add_argument("headless") | |
| dr = webdriver.Chrome(keep_alive=False, options=op) | |
| dr.get(f"https://duckduckgo.com/?q={query}&ia=web") | |
| WebDriverWait(dr, 10).until( | |
| EC.presence_of_element_located( | |
| (By.XPATH, "//ol[contains(@class, 'react-results--main')]") | |
| ) | |
| ) | |
| # get all the organic results, skipping ads results or promos | |
| results = dr.find_elements(By.XPATH, "//li[contains(@data-layout, 'organic')]") | |
| # print(results) | |
| # for the first 5 results | |
| page_results = {} | |
| for i in range(number_of_pages_to_search): | |
| # get the results in page | |
| sleep(2) | |
| a_tags = [a for a in results[i].find_elements(By.TAG_NAME, 'a') if a.text] | |
| url = a_tags[0].get_attribute("href") | |
| print(f"Getting details from page: {url}") | |
| a_tags[0].click() | |
| # get the text in the page | |
| sleep(2) | |
| p_tags = dr.find_elements(By.TAG_NAME, "p") | |
| text_in_page = ''.join([p.text for p in p_tags]) | |
| page_results[url] = text_in_page | |
| dr.back() | |
| dr.close() | |
| # print(page_results) | |
| return page_results | |
| INSTRUCTIONS = f"""You are an expert at researching topics. | |
| Given a search query, you search the web for that query (atleast 3 pages or less) and produce a concise summary of the results. | |
| The summary must be 2-3 paragraphs and less than 300 words. Capture the main points and ignore any fluff. | |
| Do not include any additional commentary other than the summary itself. | |
| The current date is {date.today().strftime("%m/%d/%Y")} | |
| """ | |
| # research agent with tools | |
| search_agent = Agent( | |
| name="Search agent", | |
| instructions=INSTRUCTIONS, | |
| tools=[web_search], | |
| model=qwen3_model, | |
| model_settings=ModelSettings(tool_choice="required"), | |
| ) | |
| # run the agent to get the result summary | |
| message = "Latest trends in robotics and its applications on the factory floor" | |
| result = await Runner.run(search_agent, message) | |
| print("Research Summary:\n\n", result.final_output) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sysout:
Search Query: latest trends in robotics factory floor applications 2026, num of pages to search: 3
Getting details from page: https://apera.ai/learn/articles/2026-vision-checklist/
Getting details from page: https://ifr.org/ifr-press-releases/news/top-5-global-robotics-trends-2026
Getting details from page: https://oxmaint.com/industries/manufacturing-plant/top-manufacturing-plant-automation-trends-watch-2026
Research Summary:
In 2026, robotics on the factory floor is driven by AI integration, collaborative robots (cobots), and digital twins. Vision-guided robotics (VGR) with AI, such as 4D Vision, enables real-time adaptability to varying production conditions, critical for retrofitting legacy systems and handling complex tasks. Natural language interfaces are reducing total cost of ownership (TCO), while pre-engineered solutions simplify deployment. Humanoid robots like Hyundai’s Atlas are being tested in assembly lines, and cobots, now affordable for mid-sized plants, improve efficiency by 15–20% in sectors like food processing. Digital twins, projected to reach $34B, offer predictive maintenance and real-time optimization, cutting downtime by 20% and accelerating development cycles.
Cybersecurity threats loom large as interconnected systems expand attack surfaces, with incidents like Jaguar Land Rover’s $260M outage highlighting vulnerabilities. Predictive maintenance powered by AI sensors and CMMS (Computerized Maintenance Management Systems) is now a baseline, forecasting failures and reducing unplanned downtime by 45%. Autonomous Mobile Robots (AMRs), such as DHL’s 7,500-unit fleet, streamline logistics, while IT/OT convergence enhances versatility but demands strict security protocols.
The shift requires a maintenance-first strategy, pairing automation with centralized CMMS to track assets, automate work orders, and manage multi-site operations. Plants adopting phased automation—starting with digitizing maintenance and layering complexity—outperform those neglecting infrastructure. As labor shortages persist, robotics and AI are not just tools but allies, reshaping workplaces and necessitating upskilling programs. The industry’s success hinges on balancing innovation with robust oversight, ensuring automation’s ROI through seamless integration of technology and maintenance protocols.