Enable reasoning separately
This commit is contained in:
@@ -52,6 +52,7 @@ func (a Actions) Find(name string) Action {
|
||||
type decisionResult struct {
|
||||
actionParams action.ActionParams
|
||||
message string
|
||||
actioName string
|
||||
}
|
||||
|
||||
// decision forces the agent to take one of the available actions
|
||||
@@ -85,7 +86,7 @@ func (a *Agent) decision(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &decisionResult{actionParams: params}, nil
|
||||
return &decisionResult{actionParams: params, actioName: msg.ToolCalls[0].Function.Name}, nil
|
||||
}
|
||||
|
||||
type Messages []openai.ChatCompletionMessage
|
||||
@@ -130,11 +131,16 @@ func (a *Agent) generateParameters(ctx context.Context, pickTemplate string, act
|
||||
}, conversation...)
|
||||
}
|
||||
|
||||
return a.decision(ctx,
|
||||
append(conversation, openai.ChatCompletionMessage{
|
||||
cc := conversation
|
||||
if a.options.forceReasoning {
|
||||
cc = append(conversation, openai.ChatCompletionMessage{
|
||||
Role: "system",
|
||||
Content: fmt.Sprintf("The agent decided to use the tool %s with the following reasoning: %s", act.Definition().Name, reasoning),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
return a.decision(ctx,
|
||||
cc,
|
||||
a.systemInternalActions().ToTools(),
|
||||
openai.ToolChoice{
|
||||
Type: openai.ToolTypeFunction,
|
||||
@@ -187,6 +193,24 @@ func (a *Agent) prepareHUD() PromptHUD {
|
||||
func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.ChatCompletionMessage) (Action, string, error) {
|
||||
c := messages
|
||||
|
||||
if !a.options.forceReasoning {
|
||||
// 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,
|
||||
messages,
|
||||
a.systemInternalActions().ToTools(),
|
||||
nil)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
// Find the action
|
||||
chosenAction := a.systemInternalActions().Find(thought.actioName)
|
||||
if chosenAction == nil {
|
||||
return nil, "", fmt.Errorf("no action found for intent:" + thought.actioName)
|
||||
}
|
||||
return chosenAction, thought.message, nil
|
||||
}
|
||||
|
||||
var promptHUD *PromptHUD
|
||||
if a.options.enableHUD {
|
||||
h := a.prepareHUD()
|
||||
@@ -241,7 +265,7 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
|
||||
params, err := a.decision(ctx,
|
||||
append(c, openai.ChatCompletionMessage{
|
||||
Role: "system",
|
||||
Content: "The assistant thought: " + reason,
|
||||
Content: "Given the assistant thought, pick the relevant action: " + reason,
|
||||
}),
|
||||
Actions{intentionsTools}.ToTools(),
|
||||
intentionsTools.Definition().Name)
|
||||
|
||||
@@ -23,6 +23,7 @@ type options struct {
|
||||
|
||||
canStopItself bool
|
||||
initiateConversations bool
|
||||
forceReasoning bool
|
||||
characterfile string
|
||||
statefile string
|
||||
context context.Context
|
||||
@@ -78,6 +79,11 @@ var EnableHUD = func(o *options) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var EnableForceReasoning = func(o *options) error {
|
||||
o.forceReasoning = true
|
||||
return nil
|
||||
}
|
||||
|
||||
var EnableKnowledgeBase = func(o *options) error {
|
||||
o.enableKB = true
|
||||
o.kbResults = 5
|
||||
|
||||
@@ -84,12 +84,12 @@ const reSelfEvalTemplate = pickSelfTemplate + `
|
||||
We already have called other tools. Evaluate the current situation and decide if we need to execute other tools.`
|
||||
|
||||
const pickActionTemplate = hudTemplate + `
|
||||
You can take any of the following tools:
|
||||
When deciding what to do, consider that you can take any of the following tools:
|
||||
|
||||
{{range .Actions -}}
|
||||
- {{.Name}}: {{.Description }}
|
||||
{{ end }}
|
||||
To answer back to the user, use the "reply" tool.
|
||||
To answer back to the user, use the "reply" or the "answer" tool.
|
||||
Given the text below, decide which action to take and explain the detailed reasoning behind it. For answering without picking a choice, reply with 'none'.
|
||||
|
||||
{{if .Reasoning}}Reasoning: {{.Reasoning}}{{end}}
|
||||
|
||||
Reference in New Issue
Block a user