Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
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
|
11 |
-
from langgraph.prebuilt
|
12 |
-
from langchain_core.tools
|
13 |
-
from langchain_core.messages
|
14 |
-
from langchain_google_genai
|
15 |
-
from langchain_community.tools.
|
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 |
-
"""
|
139 |
-
|
140 |
-
|
141 |
-
if not
|
142 |
return "ERROR: no results."
|
143 |
-
return "\n\n".join(f"{
|
|
|
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
|