fix(multi-agent): do not allow to call ourselves
Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
@@ -219,7 +219,7 @@ func (a *Agent) handlePlanning(ctx context.Context, job *types.Job, chosenAction
|
|||||||
)
|
)
|
||||||
|
|
||||||
subTaskAction := a.availableActions().Find(subtask.Action)
|
subTaskAction := a.availableActions().Find(subtask.Action)
|
||||||
subTaskReasoning := fmt.Sprintf("%s, overall goal is: %s", subtask.Reasoning, planResult.Goal)
|
subTaskReasoning := fmt.Sprintf("%s Overall goal is: %s", subtask.Reasoning, planResult.Goal)
|
||||||
|
|
||||||
params, err := a.generateParameters(ctx, pickTemplate, subTaskAction, conv, subTaskReasoning)
|
params, err := a.generateParameters(ctx, pickTemplate, subTaskAction, conv, subTaskReasoning)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ func Actions(a *state.AgentConfig) func(ctx context.Context, pool *state.AgentPo
|
|||||||
return func(ctx context.Context, pool *state.AgentPool) []types.Action {
|
return func(ctx context.Context, pool *state.AgentPool) []types.Action {
|
||||||
allActions := []types.Action{}
|
allActions := []types.Action{}
|
||||||
|
|
||||||
|
agentName := a.Name
|
||||||
|
|
||||||
for _, a := range a.Actions {
|
for _, a := range a.Actions {
|
||||||
var config map[string]string
|
var config map[string]string
|
||||||
if err := json.Unmarshal([]byte(a.Config), &config); err != nil {
|
if err := json.Unmarshal([]byte(a.Config), &config); err != nil {
|
||||||
@@ -72,7 +74,7 @@ func Actions(a *state.AgentConfig) func(ctx context.Context, pool *state.AgentPo
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
a, err := Action(a.Name, config, pool)
|
a, err := Action(a.Name, agentName, config, pool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,7 @@ func Actions(a *state.AgentConfig) func(ctx context.Context, pool *state.AgentPo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Action(name string, config map[string]string, pool *state.AgentPool) (types.Action, error) {
|
func Action(name, agentName string, config map[string]string, pool *state.AgentPool) (types.Action, error) {
|
||||||
var a types.Action
|
var a types.Action
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -125,7 +127,7 @@ func Action(name string, config map[string]string, pool *state.AgentPool) (types
|
|||||||
case ActionCounter:
|
case ActionCounter:
|
||||||
a = actions.NewCounter(config)
|
a = actions.NewCounter(config)
|
||||||
case ActionCallAgents:
|
case ActionCallAgents:
|
||||||
a = actions.NewCallAgent(config, pool.InternalAPI())
|
a = actions.NewCallAgent(config, agentName, pool.InternalAPI())
|
||||||
case ActionShellcommand:
|
case ActionShellcommand:
|
||||||
a = actions.NewShell(config)
|
a = actions.NewShell(config)
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -10,14 +10,16 @@ import (
|
|||||||
"github.com/sashabaranov/go-openai/jsonschema"
|
"github.com/sashabaranov/go-openai/jsonschema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCallAgent(config map[string]string, pool *state.AgentPoolInternalAPI) *CallAgentAction {
|
func NewCallAgent(config map[string]string, agentName string, pool *state.AgentPoolInternalAPI) *CallAgentAction {
|
||||||
return &CallAgentAction{
|
return &CallAgentAction{
|
||||||
pool: pool,
|
pool: pool,
|
||||||
|
myName: agentName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallAgentAction struct {
|
type CallAgentAction struct {
|
||||||
pool *state.AgentPoolInternalAPI
|
pool *state.AgentPoolInternalAPI
|
||||||
|
myName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *CallAgentAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
func (a *CallAgentAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {
|
||||||
@@ -57,9 +59,17 @@ func (a *CallAgentAction) Run(ctx context.Context, params types.ActionParams) (t
|
|||||||
func (a *CallAgentAction) Definition() types.ActionDefinition {
|
func (a *CallAgentAction) Definition() types.ActionDefinition {
|
||||||
allAgents := a.pool.AllAgents()
|
allAgents := a.pool.AllAgents()
|
||||||
|
|
||||||
|
agents := []string{}
|
||||||
|
|
||||||
|
for _, ag := range allAgents {
|
||||||
|
if ag != a.myName {
|
||||||
|
agents = append(agents, ag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
description := "Use this tool to call another agent. Available agents and their roles are:"
|
description := "Use this tool to call another agent. Available agents and their roles are:"
|
||||||
|
|
||||||
for _, agent := range allAgents {
|
for _, agent := range agents {
|
||||||
agentConfig := a.pool.GetConfig(agent)
|
agentConfig := a.pool.GetConfig(agent)
|
||||||
if agentConfig == nil {
|
if agentConfig == nil {
|
||||||
continue
|
continue
|
||||||
@@ -74,7 +84,7 @@ func (a *CallAgentAction) Definition() types.ActionDefinition {
|
|||||||
"agent_name": {
|
"agent_name": {
|
||||||
Type: jsonschema.String,
|
Type: jsonschema.String,
|
||||||
Description: "The name of the agent to call.",
|
Description: "The name of the agent to call.",
|
||||||
Enum: allAgents,
|
Enum: agents,
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
Type: jsonschema.String,
|
Type: jsonschema.String,
|
||||||
|
|||||||
Reference in New Issue
Block a user