naman1102 commited on
Commit
43b41d6
·
1 Parent(s): b15267e
Files changed (2) hide show
  1. app.py +13 -9
  2. tools.py +1 -1
app.py CHANGED
@@ -139,11 +139,14 @@ class BasicAgent:
139
  def _use_calculator(self, state: AgentState) -> AgentState:
140
  """Use the calculator tool."""
141
  try:
142
- result = self.calculator.invoke({"input": eval(state.tool_output)})
 
 
 
143
  state.history.append({
144
  'step': 'calculator',
145
  'input': state.tool_output,
146
- 'output': str(result['output'].result)
147
  })
148
  state.current_step = 'final_answer'
149
  except Exception as e:
@@ -157,16 +160,17 @@ class BasicAgent:
157
  def _use_search(self, state: AgentState) -> AgentState:
158
  """Use the search tool."""
159
  try:
160
- result = self.search_tool.invoke({
161
- "input": {
162
- "query": state.search_query,
163
- "max_results": 3
164
- }
165
- })
 
166
  state.history.append({
167
  'step': 'search',
168
  'query': state.search_query,
169
- 'results': [str(r) for r in result['output'].results]
170
  })
171
  state.needs_more_info = False
172
  state.current_step = 'final_answer'
 
139
  def _use_calculator(self, state: AgentState) -> AgentState:
140
  """Use the calculator tool."""
141
  try:
142
+ # Create calculator state with input from tool_output
143
+ calc_input = eval(state.tool_output)
144
+ result_state = self.calculator.invoke(CalculatorState(input=calc_input))
145
+
146
  state.history.append({
147
  'step': 'calculator',
148
  'input': state.tool_output,
149
+ 'output': str(result_state.output.result)
150
  })
151
  state.current_step = 'final_answer'
152
  except Exception as e:
 
160
  def _use_search(self, state: AgentState) -> AgentState:
161
  """Use the search tool."""
162
  try:
163
+ # Create search state with input from search_query
164
+ search_input = SearchInput(
165
+ query=state.search_query,
166
+ max_results=3
167
+ )
168
+ result_state = self.search_tool.invoke(SearchState(input=search_input))
169
+
170
  state.history.append({
171
  'step': 'search',
172
  'query': state.search_query,
173
+ 'results': [str(r) for r in result_state.output.results]
174
  })
175
  state.needs_more_info = False
176
  state.current_step = 'final_answer'
tools.py CHANGED
@@ -35,7 +35,7 @@ class SearchState(BaseModel):
35
 
36
  def create_calculator_tool() -> Graph:
37
  """Creates a calculator tool using LangGraph that can perform basic arithmetic operations."""
38
-
39
  def calculator_function(state: CalculatorState) -> CalculatorState:
40
  if len(state.input.numbers) < 2:
41
  raise ValueError("At least two numbers are required for calculation")
 
35
 
36
  def create_calculator_tool() -> Graph:
37
  """Creates a calculator tool using LangGraph that can perform basic arithmetic operations."""
38
+ print("Creating calculator tool")
39
  def calculator_function(state: CalculatorState) -> CalculatorState:
40
  if len(state.input.numbers) < 2:
41
  raise ValueError("At least two numbers are required for calculation")