Skip to content
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

[Bug] [C#] Multiple tools calls of the same function in the same run is not handled correctly. #1929

Open
Tracked by #1095
singhk97 opened this issue Aug 13, 2024 · 1 comment
Labels
bug Something isn't working dotnet Change/fix applies to dotnet. If all three, use the 'JS & dotnet & Python' label

Comments

@singhk97
Copy link
Collaborator

singhk97 commented Aug 13, 2024

// Currently `RequiredAction` is only for a function tool call
// TODO: Potential bug if assistant predicts same tool twice.
toolMap[requiredAction.FunctionName] = requiredAction.ToolCallId;
plan.Commands.Add(new PredictedDoCommand
(
requiredAction.FunctionName,
JsonSerializer.Deserialize<Dictionary<string, object?>>(requiredAction.FunctionArguments)
?? new Dictionary<string, object?>()
));
}
state.SubmitToolMap = toolMap;

Problem 1

  • In line 214, toolMap key takes the function name, which means if two separate tool calls invoke the same function, one of them would be overriden.

Solution

  • Set the tool call id (unique) as the key and the function name as the value.

if (_actions.ContainsAction(doCommand.Action))
{
DoCommandActionData<TState> data = new()
{
PredictedDoCommand = doCommand,
Handler = _actions[doCommand.Action].Handler
};
// Call action handler
output = await this._actions[AIConstants.DoCommandActionName]
.Handler
.PerformActionAsync(turnContext, turnState, data, doCommand.Action, cancellationToken);
shouldLoop = output.Length > 0;
if (turnState.Temp != null)
{
turnState.Temp.ActionOutputs[doCommand.Action] = output;
}
}

Problem 2

  • Suppose problem 1 is fixed. In line 283, the ActionOutputs also runs in the same issue where the action output of the first action call is overriden by the second.

Possible Solutions

  • Update the key of ActionOutputs to be unique.
  • Set the value of ActionOutputs to be an array of strings.
@singhk97
Copy link
Collaborator Author

This has been fixed in JS/PY when implementing tools support in the ActionPlanner

@corinagum corinagum added dotnet Change/fix applies to dotnet. If all three, use the 'JS & dotnet & Python' label bug Something isn't working labels Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dotnet Change/fix applies to dotnet. If all three, use the 'JS & dotnet & Python' label
Projects
None yet
Development

No branches or pull requests

2 participants