* 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>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package action
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/sashabaranov/go-openai/jsonschema"
|
|
)
|
|
|
|
// PlanActionName is the name of the plan action
|
|
// used by the LLM to schedule more actions
|
|
const PlanActionName = "plan"
|
|
|
|
func NewPlan(plannableActions []string) *PlanAction {
|
|
return &PlanAction{
|
|
plannables: plannableActions,
|
|
}
|
|
}
|
|
|
|
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) (ActionResult, error) {
|
|
return ActionResult{}, nil
|
|
}
|
|
|
|
func (a *PlanAction) Plannable() bool {
|
|
return false
|
|
}
|
|
|
|
func (a *PlanAction) Definition() ActionDefinition {
|
|
return ActionDefinition{
|
|
Name: PlanActionName,
|
|
Description: "The assistant for solving complex tasks that involves calling more functions in sequence, replies with the action.",
|
|
Properties: map[string]jsonschema.Definition{
|
|
"subtasks": {
|
|
Type: jsonschema.Array,
|
|
Description: "The message to reply with",
|
|
Properties: map[string]jsonschema.Definition{
|
|
"action": {
|
|
Type: jsonschema.String,
|
|
Description: "The action to call",
|
|
Enum: a.plannables,
|
|
},
|
|
"reasoning": {
|
|
Type: jsonschema.String,
|
|
Description: "The reasoning for calling this action",
|
|
},
|
|
},
|
|
},
|
|
"goal": {
|
|
Type: jsonschema.String,
|
|
Description: "The goal of this plan",
|
|
},
|
|
},
|
|
Required: []string{"subtasks", "goal"},
|
|
}
|
|
}
|