diff --git a/core/state/internal.go b/core/state/internal.go new file mode 100644 index 0000000..5e297f8 --- /dev/null +++ b/core/state/internal.go @@ -0,0 +1,33 @@ +package state + +import ( + . "github.com/mudler/LocalAgent/core/agent" +) + +type AgentPoolInternalAPI struct { + *AgentPool +} + +func (a *AgentPool) InternalAPI() *AgentPoolInternalAPI { + return &AgentPoolInternalAPI{a} +} + +func (a *AgentPoolInternalAPI) GetAgent(name string) *Agent { + return a.agents[name] +} + +func (a *AgentPoolInternalAPI) AllAgents() []string { + var agents []string + for agent := range a.agents { + agents = append(agents, agent) + } + return agents +} + +func (a *AgentPoolInternalAPI) GetConfig(name string) *AgentConfig { + agent, exists := a.pool[name] + if !exists { + return nil + } + return &agent +} diff --git a/core/state/pool.go b/core/state/pool.go index 8fc54e0..c13fbc9 100644 --- a/core/state/pool.go +++ b/core/state/pool.go @@ -591,6 +591,7 @@ func (a *AgentPool) save() error { } return os.WriteFile(a.file, data, 0644) } + func (a *AgentPool) GetAgent(name string) *Agent { a.Lock() defer a.Unlock() diff --git a/services/actions.go b/services/actions.go index 29a9690..9d9bfac 100644 --- a/services/actions.go +++ b/services/actions.go @@ -125,7 +125,7 @@ func Action(name string, config map[string]string, pool *state.AgentPool) (types case ActionCounter: a = actions.NewCounter(config) case ActionCallAgents: - a = actions.NewCallAgent(config, pool) + a = actions.NewCallAgent(config, pool.InternalAPI()) case ActionShellcommand: a = actions.NewShell(config) default: diff --git a/services/actions/callagents.go b/services/actions/callagents.go index 71fcc04..f14c008 100644 --- a/services/actions/callagents.go +++ b/services/actions/callagents.go @@ -10,14 +10,14 @@ import ( "github.com/sashabaranov/go-openai/jsonschema" ) -func NewCallAgent(config map[string]string, pool *state.AgentPool) *CallAgentAction { +func NewCallAgent(config map[string]string, pool *state.AgentPoolInternalAPI) *CallAgentAction { return &CallAgentAction{ pool: pool, } } type CallAgentAction struct { - pool *state.AgentPool + pool *state.AgentPoolInternalAPI } func (a *CallAgentAction) Run(ctx context.Context, params types.ActionParams) (types.ActionResult, error) {