How to enforce either a text response or tool_use, but not both at the same time? #382
-
Hey folks 👋 TL;DR: Since RubyLLM automatically handles tool invocations, does it make sense for the LLM to ever return a response where Context: Model: Example query: RubyLLM.ask "What do you see on the image?", with: "url-to-image" Sometimes the response is just text: "content": [
{
"type": "text",
"text": "I see product X. Do you want a recommendation for a similar product?"
}
] Other times, it’s both text and "content": [
{
"type": "text",
"text": "I see product X. Do you want a recommendation for a similar product?"
},
{
"type": "tool_use",
"id": "toolu_01WuLdB6aVijh3R78jai7eR9",
"name": "ruby_llm_tools--product_recommender",
"input": {
"query": "Product X similar product"
}
}
] Because RubyLLM handles tools automatically, the sequence looks like this under the hood:
From the user’s perspective, it looks like:
Ideally, what I’d like instead is one of two scenarios: Scenario I: Explicit confirmation before tool use
Scenario II: Seamless tool use incorporated into the answer
So the question is: Is it possible to configure the model so it always follows one of these two patterns, instead of mixing |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
|
Beta Was this translation helpful? Give feedback.
-
You might try telling the LLM which pattern you'd like it to follow in your system prompt. |
Beta Was this translation helpful? Give feedback.
-
Hey @crmne and @tpaulshippy, thank you for your quick answers. They make sense, however, I'm not sure what's the right way to implement them.
Here what I don't get is this - look at the tool execution flow from the docs, what trips me is this:
I expect the model's response to be something like:
instead, it's:
When you say: I don't have confirmation code, I rely on the user to confirm whether they want to search for a product or not. Basically, the flow I want is either:
get the user's approval (Yes, serach for similar products), respond with tool_use and give final answer or
I understand this might probably be more of a question on how to properly build a prompt, not so much about the RubyLLM capabilities, so if you feel that way, please, disregard this.
The problem with this is - I don't want to always use a given tool, I need to offload the decision to the LLM, so enforcing a tool is not an option for me.
Yes, after looking into Anthropic's API and RubyLLM, I tend to think that this is my only option. |
Beta Was this translation helpful? Give feedback.
-
@crmne @tpaulshippy I finally found a solution!!!
This results in exactly the flow I want - the second call to the LLM contains just the tool_use and the tool_result in the history, but not the intermediate text response of the LLM:
This results in the LLM having a response, which both:
Thank you very much, folks! 🙇 🙏 |
Beta Was this translation helpful? Give feedback.
tool_choice: "required"
.