feat(planning): enable agent planning (#68)
* feat(planning): Allow the agent to plan subtasks Signed-off-by: mudler <mudler@localai.io> * feat(planning): enable planning toggle in the webui Signed-off-by: mudler <mudler@localai.io> * feat(planning): take in consideration the overall goal Signed-off-by: mudler <mudler@localai.io> * Update core/action/plan.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: mudler <mudler@localai.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
638eedc2a0
commit
33483ab4b9
@@ -75,6 +75,10 @@ func (a *CustomAction) initializeInterpreter() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *CustomAction) Plannable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *CustomAction) Run(ctx context.Context, params ActionParams) (ActionResult, error) {
|
||||
v, err := a.i.Eval(fmt.Sprintf("%s.Run", a.config["name"]))
|
||||
if err != nil {
|
||||
|
||||
@@ -25,6 +25,10 @@ func (a *IntentAction) Run(context.Context, ActionParams) (ActionResult, error)
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *IntentAction) Plannable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *IntentAction) Definition() ActionDefinition {
|
||||
return ActionDefinition{
|
||||
Name: "pick_tool",
|
||||
|
||||
@@ -22,6 +22,10 @@ func (a *ConversationAction) Run(context.Context, ActionParams) (ActionResult, e
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *ConversationAction) Plannable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *ConversationAction) Definition() ActionDefinition {
|
||||
return ActionDefinition{
|
||||
Name: ConversationActionName,
|
||||
|
||||
@@ -16,6 +16,10 @@ func (a *StopAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *StopAction) Plannable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *StopAction) Definition() ActionDefinition {
|
||||
return ActionDefinition{
|
||||
Name: StopActionName,
|
||||
|
||||
@@ -10,22 +10,31 @@ import (
|
||||
// used by the LLM to schedule more actions
|
||||
const PlanActionName = "plan"
|
||||
|
||||
func NewPlan() *PlanAction {
|
||||
return &PlanAction{}
|
||||
func NewPlan(plannableActions []string) *PlanAction {
|
||||
return &PlanAction{
|
||||
plannables: plannableActions,
|
||||
}
|
||||
}
|
||||
|
||||
type PlanAction struct{}
|
||||
type PlanAction struct {
|
||||
plannables []string
|
||||
}
|
||||
|
||||
type PlanResult struct {
|
||||
Subtasks []PlanSubtask `json:"subtasks"`
|
||||
Goal string `json:"goal"`
|
||||
}
|
||||
type PlanSubtask struct {
|
||||
Action string `json:"action"`
|
||||
Reasoning string `json:"reasoning"`
|
||||
}
|
||||
|
||||
func (a *PlanAction) Run(context.Context, ActionParams) (string, error) {
|
||||
return "no-op", nil
|
||||
func (a *PlanAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *PlanAction) Plannable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *PlanAction) Definition() ActionDefinition {
|
||||
@@ -40,6 +49,7 @@ func (a *PlanAction) Definition() ActionDefinition {
|
||||
"action": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The action to call",
|
||||
Enum: a.plannables,
|
||||
},
|
||||
"reasoning": {
|
||||
Type: jsonschema.String,
|
||||
@@ -47,7 +57,11 @@ func (a *PlanAction) Definition() ActionDefinition {
|
||||
},
|
||||
},
|
||||
},
|
||||
"goal": {
|
||||
Type: jsonschema.String,
|
||||
Description: "The goal of this plan",
|
||||
},
|
||||
},
|
||||
Required: []string{"subtasks"},
|
||||
Required: []string{"subtasks", "goal"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ func (a *ReasoningAction) Run(context.Context, ActionParams) (ActionResult, erro
|
||||
return ActionResult{}, nil
|
||||
}
|
||||
|
||||
func (a *ReasoningAction) Plannable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *ReasoningAction) Definition() ActionDefinition {
|
||||
return ActionDefinition{
|
||||
Name: "pick_action",
|
||||
|
||||
@@ -25,6 +25,10 @@ func (a *ReplyAction) Run(context.Context, ActionParams) (string, error) {
|
||||
return "no-op", nil
|
||||
}
|
||||
|
||||
func (a *ReplyAction) Plannable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *ReplyAction) Definition() ActionDefinition {
|
||||
return ActionDefinition{
|
||||
Name: ReplyActionName,
|
||||
|
||||
@@ -37,6 +37,10 @@ func (a *StateAction) Run(context.Context, ActionParams) (ActionResult, error) {
|
||||
return ActionResult{Result: "internal state has been updated"}, nil
|
||||
}
|
||||
|
||||
func (a *StateAction) Plannable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *StateAction) Definition() ActionDefinition {
|
||||
return ActionDefinition{
|
||||
Name: StateActionName,
|
||||
|
||||
Reference in New Issue
Block a user