zBotta commited on
Commit
a7f132a
·
verified ·
1 Parent(s): 3a3f208

Upload 3 files

Browse files

agent folder added.

Files changed (3) hide show
  1. agent/__init__.py +3 -0
  2. agent/agent.py +29 -0
  3. agent/tools/search_tool.py +25 -0
agent/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ """
2
+ Agent module
3
+ """
agent/agent.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import TypedDict, List, Dict, Any, Optional
3
+ from lanchain_google_genai import ChatGoogleGenerativeAI
4
+ from langchain_core.messages import AnyMessage, SystemMessage, HumanMessage, AIMessage
5
+ from langgraph.grap.message import add_messages
6
+ from langgraph.graph import START, StateGraph
7
+ from langgraph.prebuilt import ToolNode, tools_condition
8
+
9
+ from tools.search_tool import search_tool
10
+
11
+
12
+ # --- zBottaAgent Definition ---
13
+
14
+ class zBottaAgent:
15
+ def __init__(self):
16
+ print("zBottaAgent initialized.")
17
+ chat = ChatGoogleGenerativeAI(model="gemini-2.0-flash", temperature=0.7)
18
+ tools = [search_tool]
19
+ self.chat_with_tools = chat.bind_tools(tools)
20
+
21
+ def __call__(self, question: str) -> str:
22
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
23
+ messages = [
24
+ SystemMessage(content="You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer. Your answer should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."),
25
+ HumanMessage(content=question)
26
+ ]
27
+ response = self.chat_with_tools.invoke(messages)
28
+ print(f"Agent returning response: {response}")
29
+ return response
agent/tools/search_tool.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.tools import DuckDuckGoSearchResults, DuckDuckGoSearchRun, BingSearchResults, BingSearchRun
2
+ from langchain.tools import tool
3
+
4
+ @tool(description="Use this tool to get search results for a query. Input should be a string representing the search query. Output will be a string containing the search results.")
5
+ def search_tool(query: str) -> str:
6
+ print(f"Invoking search tool with query: {query}")
7
+ try:
8
+ search_tool = DuckDuckGoSearchResults(engine="duckduckgo")
9
+ search_results = search_tool.run(query)
10
+ print(f"Search tool returned results: {search_results[:100]}...") # Print first 100 chars of results
11
+ return search_results
12
+ except Exception as e:
13
+ error_message = f"Error invoking search tool: {e}"
14
+ return error_message
15
+
16
+ # search_tool = Tool(
17
+ # name = "get_search_results",
18
+ # func = get_search_results,
19
+ # description = "Use this tool to get search results for a query. Input should be a string representing the search query. Output will be a string containing the search results."
20
+ # )
21
+
22
+
23
+ if __name__ == "__main__":
24
+ results = search_tool("Who's the current President of France?")
25
+ print(results)