docs/how_to/tool_results_pass_to_model/ #29825
Replies: 3 comments 4 replies
-
I am very new to using LangChain (and generative AI in general). I was able to follow this and get it working in a Jupyter notebook. I see it calling the tools (add, multiply) while debugging. Out of curiosity I modified the functions to return the wrong values. Those values are in the ToolMessage content, however the final AIMessage contains the correct values. The model appears to be discarding the values and doing the calculations on its own. Is this expected behaviour? A result of the contrived examples? If you wanted to, how would you go about ensuring that the values of your tools would be used? Would that be something you would specify in a prompt message or tool description? |
Beta Was this translation helpful? Give feedback.
-
It seems that the current answer is wrong: AIMessage(content='36 * 12 = 432\n\n11 + 49 = 60\n\nThe answer is: 432 and 60', additional_kwargs={}, response_metadata={'token_usage': {'completion_tokens': 26, 'prompt_tokens': 1175, 'total_tokens': 1201, 'completion_time': 0.021666667, 'prompt_time': 0.174865897, 'queue_time': 0.19576452900000002, 'total_time': 0.196532564}, 'model_name': 'llama3-8b-8192', 'system_fingerprint': 'fp_6a6771ae9c', 'finish_reason': 'stop', 'logprobs': None}, id='run-4a84ee76-0f64-4fb2-915f-6f59113ab17a-0', usage_metadata={'input_tokens': 1175, 'output_tokens': 26, 'total_tokens': 1201}) |
Beta Was this translation helpful? Give feedback.
-
I wanted to test if this would work with compound operations system_message = SystemMessage("You are a helpful assistant who helps with any question asked of you.")
human_message = HumanMessage("Multiply 5.2 by 63, then add 23 to the result.?")
messages = [system_message, human_message] and I got the following which is wrong Tool called
Processing tool: multiply,
{'name': 'multiply',
'args': {'a': 5.2, 'b': 63}, 'id': '66396fc8-7408-4283-8b1b-e7d265020cf1',
'type': 'tool_call'}
Processing tool: addition,
{'name': 'addition',
'args': {'a': 321.6, 'b': 23}, 'id': '2860be65-8304-44d2-aaba-78292396ebf3',
'type': 'tool_call'}
final_output content: 327.6 + 23 = 344.6 (The multiplication of 5.2 and 63 results in 327.6, then adding 23 to the result gives us 344.6.) Correct Answer = |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
docs/how_to/tool_results_pass_to_model/
This guide assumes familiarity with the following concepts:
https://python.langchain.com/docs/how_to/tool_results_pass_to_model/
Beta Was this translation helpful? Give feedback.
All reactions