ZeroTimo commited on
Commit
5aa21de
·
verified ·
1 Parent(s): 7d74ca3

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +13 -12
agent.py CHANGED
@@ -7,12 +7,12 @@ agent.py – LangGraph-Agent mit
7
  import os, base64, mimetypes, subprocess, json, tempfile
8
  from typing import Any
9
 
10
- from langgraph.graph import START, StateGraph, MessagesState
11
- from langgraph.prebuilt import tools_condition, ToolNode
12
- from langchain_core.tools import tool
13
- from langchain_core.messages import SystemMessage, HumanMessage
14
- from langchain_google_genai import ChatGoogleGenerativeAI
15
- from langchain_community.tools.duckduckgo_search import DuckDuckGoSearchResults as DDGS
16
 
17
  # ----------------------------------------------------------------------
18
  # 1 ── ENV / LLM
@@ -134,13 +134,14 @@ def ocr_image(file_path: str, lang: str = "eng") -> str:
134
  # ----------------------------------------------------------------------
135
  @tool
136
  @error_guard
137
- def web_search(query: str) -> str:
138
- """DuckDuckGo text search – top 5 results."""
139
- with DDGS() as ddgs:
140
- results = ddgs.text(query, max_results=5)
141
- if not results:
142
  return "ERROR: no results."
143
- return "\n\n".join(f"{r['title']} – {r['href']}" for r in results)
 
144
 
145
  # ----------------------------------------------------------------------
146
  # 7 ── SYSTEM-PROMPT
 
7
  import os, base64, mimetypes, subprocess, json, tempfile
8
  from typing import Any
9
 
10
+ from langgraph.graph import START, StateGraph, MessagesState
11
+ from langgraph.prebuilt import tools_condition, ToolNode
12
+ from langchain_core.tools import tool
13
+ from langchain_core.messages import SystemMessage, HumanMessage
14
+ from langchain_google_genai import ChatGoogleGenerativeAI
15
+ from langchain_community.tools.tavily_search import TavilySearchResults
16
 
17
  # ----------------------------------------------------------------------
18
  # 1 ── ENV / LLM
 
134
  # ----------------------------------------------------------------------
135
  @tool
136
  @error_guard
137
+ def web_search(query: str, max_results: int = 5) -> str:
138
+ """Tavily web search – returns markdown list of results."""
139
+ search = TavilySearchResults(max_results=max_results)
140
+ hits = search.invoke(query)
141
+ if not hits:
142
  return "ERROR: no results."
143
+ return "\n\n".join(f"{hit['title']} – {hit['url']}" for hit in hits)
144
+
145
 
146
  # ----------------------------------------------------------------------
147
  # 7 ── SYSTEM-PROMPT