Introduction
When an AI agent uses tools, it needs to understand and use the results correctly to make good decisions.
Jump into concepts and practice - no test required
result = tool.execute(input_data) process(result)
weather_result = weather_tool.execute('New York') print(weather_result)
calc_result = calculator.execute('2 + 2') if calc_result is not None: print(f'Result is {calc_result}')
class SimpleTool: def execute(self, input_data): # Simulate a tool that returns input reversed return input_data[::-1] # Create tool instance reverse_tool = SimpleTool() # Use the tool input_text = 'hello' result = reverse_tool.execute(input_text) # Handle the result print(f'Input: {input_text}') print(f'Result from tool: {result}')
tool_result = {'status': 'success', 'data': [1, 2, 3]}
if tool_result.get('status') == 'success':
print(len(tool_result['data']))
else:
print(0)result = tool.run()
if result != None:
print(result['value'])
else:
print('No result')