Use internal API for services/actions when using the pool
Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
33
core/state/internal.go
Normal file
33
core/state/internal.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -591,6 +591,7 @@ func (a *AgentPool) save() error {
|
|||||||
}
|
}
|
||||||
return os.WriteFile(a.file, data, 0644)
|
return os.WriteFile(a.file, data, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AgentPool) GetAgent(name string) *Agent {
|
func (a *AgentPool) GetAgent(name string) *Agent {
|
||||||
a.Lock()
|
a.Lock()
|
||||||
defer a.Unlock()
|
defer a.Unlock()
|
||||||
|
|||||||
@@ -125,7 +125,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)
|
a = actions.NewCallAgent(config, pool.InternalAPI())
|
||||||
case ActionShellcommand:
|
case ActionShellcommand:
|
||||||
a = actions.NewShell(config)
|
a = actions.NewShell(config)
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import (
|
|||||||
"github.com/sashabaranov/go-openai/jsonschema"
|
"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{
|
return &CallAgentAction{
|
||||||
pool: pool,
|
pool: pool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallAgentAction struct {
|
type CallAgentAction struct {
|
||||||
pool *state.AgentPool
|
pool *state.AgentPoolInternalAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user