-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Support repeated tool calls in a loop within AssistantAgent
#6268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The idea sounds good to me 👍 For my use-case it would be nice to have a way to enforce a text response after a certain amount of loops. In my case the model is gathering information from a vectorDB. The agent sometimes decides to query multiple times, if it does not get the right information. But I cannot do too many loops since the cost and time gets too high. So this would force the model to formulate the best answer it can with the info it got after a few tries. |
I want try to implement this! As @philippHorn mentioned, this feature would be very useful when we want to query a database. However, I see that Running an Agent in a Loop already provides a way to do this. I don't have a deep understanding of the system yet, but assuming there is a tool used to interact with the database, and for some reason (the desired data doesn't exist when we query), would the difference be that: Running an Agent in a Loop would be considered multiple independent Agent runs or interactions, with each run potentially involving one or a limited number of tool calls. Whereas the tool_call_loop feature we hope to implement would be considered a single complete interaction or operation flow, where the Agent internally and autonomously repeats tool calls until specific termination conditions are met. |
@zhengkezhou1 if you are new to the code base, I think you can get started by sketching out your design in this issue so we can get you to the right direction. The goal for this feature is to make it much easier to use a single agent without thinking about team at all. The tool call loop provides a quick way to do the same thing as a round robin with a single agent and termination condition however, the implementation can be much more specific to |
@ekzhu you mentioned that Claude models have been trained to perform exactly this. Do you have any relevant links? I couldn't find this type of information in the documentation. Also, I did a small test with Gemini. My initial idea is as follows: Instead of manual checking, we will add the result obtained from the tool call to the If the response from the model indicates that the result is not what we expect, we will loop the tool call until we get the desired result, while also ensuring that if we continuously fail for a certain period, we will stop calling and return directly." Explanation based on OpenAI API:
|
Sorry. I made this up. However their documentation indicates this is the recommended way. See Sequential Tools in the documentation. |
Can we instead have the model decide directly whether to continue with another tool call, using only the tool call response? This is recommended by the Anthropic doc. The OpenAI Assistant API also uses similar pattern, see Run Lifecycle. |
Confirmation
Issue body
Many models have been trained to call tools repeatedly until a reflection on the results. For example, Claude models have been trained to perform exactly this.
Idea:
We can support this in
AssistantAgent
by introducing an optionaltool_call_loop
parameter to the constructor. By default,tool_call_loop=False
which indicates the tool calls won't get into a loop -- a single tool call at most.User can set
tool_call_loop=True
which indicates the tool call will run in a loop until the model:This is a start. As the next step, introduce a
ToolCallConfig
class which controls how a tool call loop should behave, with parameters for setting maximum number of iterations, preset response text, etc. -- we can consider mergingreflect_on_tool_call
into it as well.Please discuss and suggest ideas.
Related:
#6261
#5621
The text was updated successfully, but these errors were encountered: