diff --git a/core/agent/actions.go b/core/agent/actions.go index 164a46b..d40704d 100644 --- a/core/agent/actions.go +++ b/core/agent/actions.go @@ -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 { diff --git a/core/agent/agent.go b/core/agent/agent.go index 49f25a8..deaf998 100644 --- a/core/agent/agent.go +++ b/core/agent/agent.go @@ -657,11 +657,7 @@ func (a *Agent) consumeJob(job *types.Job, role string) { conv = a.addFunctionResultToConversation(chosenAction, actionParams, result, conv) } - //conv = append(conv, messages...) - //conv = messages - - // given the result, we can now ask OpenAI to complete the conversation or - // to continue using another tool given the result + // given the result, we can now re-evaluate the conversation followingAction, followingParams, reasoning, err := a.pickAction(job.GetContext(), reEvaluationTemplate, conv, maxRetries) if err != nil { job.Result.Conversation = conv