wip: noaction for deciding to stop
This commit is contained in:
@@ -136,18 +136,33 @@ func (a *Agent) generateParameters(ctx context.Context, pickTemplate string, act
|
||||
}
|
||||
|
||||
func (a *Agent) systemInternalActions() Actions {
|
||||
if a.options.enableHUD {
|
||||
return append(a.options.userActions,
|
||||
action.NewState(), action.NewReply())
|
||||
}
|
||||
defaultActions := append(a.options.userActions, action.NewReply())
|
||||
|
||||
if a.options.initiateConversations && a.selfEvaluationInProgress { // && self-evaluation..
|
||||
return append(a.options.userActions,
|
||||
action.NewState(), action.NewReply(), action.NewConversation())
|
||||
acts := append(defaultActions, action.NewConversation())
|
||||
if a.options.enableHUD {
|
||||
acts = append(acts, action.NewState())
|
||||
}
|
||||
if a.options.canStopItself {
|
||||
acts = append(acts, action.NewStop())
|
||||
}
|
||||
|
||||
return acts
|
||||
}
|
||||
|
||||
return append(a.options.userActions,
|
||||
action.NewReply())
|
||||
if a.options.canStopItself {
|
||||
acts := append(defaultActions, action.NewStop())
|
||||
if a.options.enableHUD {
|
||||
acts = append(acts, action.NewState())
|
||||
}
|
||||
return acts
|
||||
}
|
||||
|
||||
if a.options.enableHUD {
|
||||
return append(defaultActions, action.NewState())
|
||||
}
|
||||
|
||||
return defaultActions
|
||||
}
|
||||
|
||||
func (a *Agent) prepareHUD() PromptHUD {
|
||||
|
||||
@@ -340,6 +340,14 @@ func (a *Agent) consumeJob(job *Job, role string) {
|
||||
}
|
||||
}
|
||||
|
||||
if chosenAction.Definition().Name.Is(action.StopActionName) {
|
||||
if a.options.debugMode {
|
||||
fmt.Println("LLM decided to stop")
|
||||
}
|
||||
job.Result.Finish(nil)
|
||||
return
|
||||
}
|
||||
|
||||
if chosenAction == nil {
|
||||
// If no action was picked up, the reasoning is the message returned by the assistant
|
||||
// so we can consume it as if it was a reply.
|
||||
@@ -410,8 +418,10 @@ func (a *Agent) consumeJob(job *Job, role string) {
|
||||
if !chosenAction.Definition().Name.Is(action.ReplyActionName) {
|
||||
result, err := a.runAction(chosenAction, params)
|
||||
if err != nil {
|
||||
job.Result.Finish(fmt.Errorf("error running action: %w", err))
|
||||
return
|
||||
//job.Result.Finish(fmt.Errorf("error running action: %w", err))
|
||||
//return
|
||||
// make the LLM aware of the error of running the action instead of stopping the job here
|
||||
result = fmt.Sprintf("Error running tool: %v", err)
|
||||
}
|
||||
|
||||
stateResult := ActionState{ActionCurrentState{chosenAction, params.actionParams, reasoning}, result}
|
||||
@@ -585,7 +595,7 @@ func (a *Agent) periodicallyRun() {
|
||||
|
||||
// whatNext := NewJob(WithText("Decide what to do based on the state"))
|
||||
whatNext := NewJob(
|
||||
WithText("Decide what to based on the goal and the persistent goal."),
|
||||
WithText(innerMonologueTemplate),
|
||||
WithReasoningCallback(a.options.reasoningCallback),
|
||||
WithResultCallback(a.options.resultCallback),
|
||||
)
|
||||
|
||||
@@ -21,6 +21,7 @@ type options struct {
|
||||
userActions Actions
|
||||
enableHUD, standaloneJob, showCharacter, enableKB bool
|
||||
debugMode bool
|
||||
canStopItself bool
|
||||
initiateConversations bool
|
||||
characterfile string
|
||||
statefile string
|
||||
@@ -53,7 +54,7 @@ func defaultOptions() *options {
|
||||
},
|
||||
character: Character{
|
||||
Name: "John Doe",
|
||||
Age: 0,
|
||||
Age: "",
|
||||
Occupation: "Unemployed",
|
||||
Hobbies: []string{},
|
||||
MusicTaste: []string{},
|
||||
@@ -82,6 +83,11 @@ var EnableKnowledgeBase = func(o *options) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var CanStopItself = func(o *options) error {
|
||||
o.canStopItself = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func EnableKnowledgeBaseWithResults(results int) Option {
|
||||
return func(o *options) error {
|
||||
o.enableKB = true
|
||||
|
||||
@@ -22,7 +22,7 @@ type PromptHUD struct {
|
||||
|
||||
type Character struct {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Age string `json:"age"`
|
||||
Occupation string `json:"job_occupation"`
|
||||
Hobbies []string `json:"hobbies"`
|
||||
MusicTaste []string `json:"music_taste"`
|
||||
@@ -99,7 +99,7 @@ func (a *Agent) generateIdentity(guidance string) error {
|
||||
|
||||
func (a *Agent) validCharacter() bool {
|
||||
return a.Character.Name != "" &&
|
||||
a.Character.Age != 0 &&
|
||||
a.Character.Age != "" &&
|
||||
a.Character.Occupation != "" &&
|
||||
len(a.Character.Hobbies) != 0 &&
|
||||
len(a.Character.MusicTaste) != 0
|
||||
@@ -107,7 +107,7 @@ func (a *Agent) validCharacter() bool {
|
||||
|
||||
const fmtT = `=====================
|
||||
Name: %s
|
||||
Age: %d
|
||||
Age: %s
|
||||
Occupation: %s
|
||||
Hobbies: %v
|
||||
Music taste: %v
|
||||
|
||||
@@ -40,6 +40,10 @@ func renderTemplate(templ string, hud *PromptHUD, actions Actions, reasoning str
|
||||
return prompt.String(), nil
|
||||
}
|
||||
|
||||
const innerMonologueTemplate = `"This is not a typical conversation between an assistant and an user.
|
||||
You are thinking out loud by yourself now, and you are evaluating the current situation.
|
||||
Considering the goal and the persistent goal, if you have one, and do something, or decide to plan something for later on. If you have the action available, you might also decide to engage a conversation with the user by notifying him."`
|
||||
|
||||
const hudTemplate = `{{with .HUD }}{{if .ShowCharacter}}The assistant acts like an human, has a character and the replies and actions might be influenced by it.
|
||||
{{if .Character.Name}}This is the assistant name: {{.Character.Name}}
|
||||
{{end}}{{if .Character.Age}}This is the assistant age: {{.Character.Age}}
|
||||
|
||||
Reference in New Issue
Block a user