Shekarss commited on
Commit
0ec6073
·
verified ·
1 Parent(s): c040abb

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +44 -1
agent.py CHANGED
@@ -126,7 +126,50 @@ def wikipedia_fetcher(query:str)->str:
126
  doc = docs[0].page_content
127
  return doc
128
 
129
- tools = [read_file, wikipedia_fetcher, web_search, add, subtract, divide, multiply, modulus, power, square_root]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  class AgentState(TypedDict):
132
  messages: Annotated[List[AnyMessage], add_messages]
 
126
  doc = docs[0].page_content
127
  return doc
128
 
129
+ @tool
130
+ def query_csv_first_match(csv_file: str, filters: dict, column: str) -> str:
131
+ """
132
+ Returns the first value from `column` in CSV matching the filters.
133
+
134
+ Args:
135
+ csv_file (str): Path to CSV
136
+ filters (dict): Column-value filters, e.g. {"Year": 1983, "Country": "SU"}
137
+ column (str): Column to return value from
138
+
139
+ Returns:
140
+ str: First matching value
141
+ """
142
+ df = pd.read_csv(csv_file)
143
+ for key, val in filters.items():
144
+ if val is not None:
145
+ df = df[df[key] == val]
146
+ if not df.empty:
147
+ return str(df.iloc[0][column])
148
+ return "Unknown"
149
+
150
+ @tool
151
+ def query_csv_min(csv_file: str, column_min: str, return_column: str, tie_break_column: str = None) -> str:
152
+ """
153
+ Returns the value of `return_column` from the row with the minimum `column_min`.
154
+ If tie, use `tie_break_column` to select first alphabetically.
155
+
156
+ Args:
157
+ csv_file (str): Path to CSV
158
+ column_min (str): Column to find minimum
159
+ return_column (str): Column to return
160
+ tie_break_column (str, optional): Column to break tie alphabetically
161
+
162
+ Returns:
163
+ str: Result value
164
+ """
165
+ df = pd.read_csv(csv_file)
166
+ min_value = df[column_min].min()
167
+ candidates = df[df[column_min] == min_value]
168
+ if tie_break_column:
169
+ candidates = candidates.sort_values(tie_break_column)
170
+ return str(candidates.iloc[0][return_column])
171
+
172
+ tools = [read_file, wikipedia_fetcher, web_search, add, subtract, divide, multiply, modulus, power, square_root, query_csv_first_match, query_csv_min]
173
 
174
  class AgentState(TypedDict):
175
  messages: Annotated[List[AnyMessage], add_messages]