fix(pick_action): improve action pickup by using only the assistant thought process

Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
mudler
2025-04-10 20:07:34 +02:00
parent 0fda6e38db
commit 8e18df468b
2 changed files with 15 additions and 10 deletions

View File

@@ -358,7 +358,10 @@ func (a *Agent) prepareHUD() (promptHUD *PromptHUD) {
func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.ChatCompletionMessage, maxRetries int) (types.Action, types.ActionParams, string, error) {
c := messages
xlog.Debug("picking action", "messages", messages)
if !a.options.forceReasoning {
xlog.Debug("not forcing reasoning")
// We also could avoid to use functions here and get just a reply from the LLM
// and then use the reply to get the action
thought, err := a.decision(ctx,
@@ -386,6 +389,8 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
return chosenAction, thought.actionParams, thought.message, nil
}
xlog.Debug("forcing reasoning")
prompt, err := renderTemplate(templ, a.prepareHUD(), a.availableActions(), "")
if err != nil {
return nil, nil, "", err
@@ -422,6 +427,8 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
reason = thought.message
}
xlog.Debug("thought", "reason", reason)
// From the thought, get the action call
// Get all the available actions IDs
actionsID := []string{}
@@ -430,12 +437,14 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
}
intentionsTools := action.NewIntention(actionsID...)
//XXX: Why we add the reason here?
// NOTE: we do not give the full conversation here to pick the action
// to avoid hallucinations
params, err := a.decision(ctx,
append(c, openai.ChatCompletionMessage{
Role: "system",
Content: "Given the assistant thought, pick the relevant action: " + reason,
}),
[]openai.ChatCompletionMessage{{
Role: "assistant",
Content: reason,
},
},
types.Actions{intentionsTools}.ToTools(),
intentionsTools.Definition().Name, maxRetries)
if err != nil {