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) { func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.ChatCompletionMessage, maxRetries int) (types.Action, types.ActionParams, string, error) {
c := messages c := messages
xlog.Debug("picking action", "messages", messages)
if !a.options.forceReasoning { 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 // 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 // and then use the reply to get the action
thought, err := a.decision(ctx, 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 return chosenAction, thought.actionParams, thought.message, nil
} }
xlog.Debug("forcing reasoning")
prompt, err := renderTemplate(templ, a.prepareHUD(), a.availableActions(), "") prompt, err := renderTemplate(templ, a.prepareHUD(), a.availableActions(), "")
if err != nil { if err != nil {
return nil, nil, "", err return nil, nil, "", err
@@ -422,6 +427,8 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
reason = thought.message reason = thought.message
} }
xlog.Debug("thought", "reason", reason)
// From the thought, get the action call // From the thought, get the action call
// Get all the available actions IDs // Get all the available actions IDs
actionsID := []string{} actionsID := []string{}
@@ -430,12 +437,14 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
} }
intentionsTools := action.NewIntention(actionsID...) 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, params, err := a.decision(ctx,
append(c, openai.ChatCompletionMessage{ []openai.ChatCompletionMessage{{
Role: "system", Role: "assistant",
Content: "Given the assistant thought, pick the relevant action: " + reason, Content: reason,
}), },
},
types.Actions{intentionsTools}.ToTools(), types.Actions{intentionsTools}.ToTools(),
intentionsTools.Definition().Name, maxRetries) intentionsTools.Definition().Name, maxRetries)
if err != nil { if err != nil {

View File

@@ -657,11 +657,7 @@ func (a *Agent) consumeJob(job *types.Job, role string) {
conv = a.addFunctionResultToConversation(chosenAction, actionParams, result, conv) conv = a.addFunctionResultToConversation(chosenAction, actionParams, result, conv)
} }
//conv = append(conv, messages...) // given the result, we can now re-evaluate the conversation
//conv = messages
// given the result, we can now ask OpenAI to complete the conversation or
// to continue using another tool given the result
followingAction, followingParams, reasoning, err := a.pickAction(job.GetContext(), reEvaluationTemplate, conv, maxRetries) followingAction, followingParams, reasoning, err := a.pickAction(job.GetContext(), reEvaluationTemplate, conv, maxRetries)
if err != nil { if err != nil {
job.Result.Conversation = conv job.Result.Conversation = conv