Initiate agents from pool
This commit is contained in:
@@ -39,10 +39,7 @@ type Agent struct {
|
||||
func New(opts ...Option) (*Agent, error) {
|
||||
options, err := newOptions(opts...)
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to set options: %v", err)
|
||||
}
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed to set options: %v", err)
|
||||
}
|
||||
|
||||
client := llm.NewClient(options.LLMAPI.APIKey, options.LLMAPI.APIURL)
|
||||
@@ -126,6 +123,12 @@ func (a *Agent) CurrentConversation() []openai.ChatCompletionMessage {
|
||||
return a.currentConversation
|
||||
}
|
||||
|
||||
func (a *Agent) SetConversation(conv []openai.ChatCompletionMessage) {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
a.currentConversation = conv
|
||||
}
|
||||
|
||||
func (a *Agent) ResetConversation() {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
@@ -94,6 +94,20 @@ func WithLLMAPIURL(url string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func WithStateFile(path string) Option {
|
||||
return func(o *options) error {
|
||||
o.statefile = path
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithCharacterFile(path string) Option {
|
||||
return func(o *options) error {
|
||||
o.characterfile = path
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithLLMAPIKey(key string) Option {
|
||||
return func(o *options) error {
|
||||
o.LLMAPI.APIKey = key
|
||||
|
||||
@@ -16,8 +16,54 @@ type ConnectorConfig struct {
|
||||
type ActionsConfig string
|
||||
|
||||
type AgentConfig struct {
|
||||
Connector []ConnectorConfig `json:"connector"`
|
||||
Actions []ActionsConfig `json:"actions"`
|
||||
Connector []ConnectorConfig `json:"connector"`
|
||||
Actions []ActionsConfig `json:"actions"`
|
||||
StateFile string `json:"state_file"`
|
||||
CharacterFile string `json:"character_file"`
|
||||
// This is what needs to be part of ActionsConfig
|
||||
|
||||
// WithLLMAPIURL(apiModel),
|
||||
// WithModel(testModel),
|
||||
// EnableHUD,
|
||||
// DebugMode,
|
||||
// EnableStandaloneJob,
|
||||
// WithAgentReasoningCallback(func(state ActionCurrentState) bool {
|
||||
// sseManager.Send(
|
||||
// sse.NewMessage(
|
||||
// fmt.Sprintf(`Thinking: %s`, htmlIfy(state.Reasoning)),
|
||||
// ).WithEvent("status"),
|
||||
// )
|
||||
// return true
|
||||
// }),
|
||||
// WithActions(external.NewSearch(3)),
|
||||
// WithAgentResultCallback(func(state ActionState) {
|
||||
// text := fmt.Sprintf(`Reasoning: %s
|
||||
// Action taken: %+v
|
||||
// Parameters: %+v
|
||||
// Result: %s`,
|
||||
// state.Reasoning,
|
||||
// state.ActionCurrentState.Action.Definition().Name,
|
||||
// state.ActionCurrentState.Params,
|
||||
// state.Result)
|
||||
// sseManager.Send(
|
||||
// sse.NewMessage(
|
||||
// htmlIfy(
|
||||
// text,
|
||||
// ),
|
||||
// ).WithEvent("status"),
|
||||
// )
|
||||
// }),
|
||||
// WithRandomIdentity(),
|
||||
// WithPeriodicRuns("10m"),
|
||||
|
||||
APIURL string `json:"api_url"`
|
||||
Model string `json:"model"`
|
||||
HUD bool `json:"hud"`
|
||||
Debug bool `json:"debug"`
|
||||
StandaloneJob bool `json:"standalone_job"`
|
||||
RandomIdentity bool `json:"random_identity"`
|
||||
IdentityGuidance string `json:"identity_guidance"`
|
||||
PeriodicRuns string `json:"periodic_runs"`
|
||||
}
|
||||
|
||||
type AgentPool struct {
|
||||
@@ -68,10 +114,30 @@ func (a *AgentPool) CreateAgent(name string, agentConfig *AgentConfig) error {
|
||||
}
|
||||
|
||||
func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error {
|
||||
|
||||
agent, err := New(
|
||||
WithModel("hermes-2-pro-mistral"),
|
||||
)
|
||||
opts := []Option{
|
||||
WithModel(config.Model),
|
||||
WithLLMAPIURL(config.APIURL),
|
||||
WithPeriodicRuns(config.PeriodicRuns),
|
||||
WithStateFile(config.StateFile),
|
||||
WithCharacterFile(config.StateFile),
|
||||
}
|
||||
if config.HUD {
|
||||
opts = append(opts, EnableHUD)
|
||||
}
|
||||
if config.Debug {
|
||||
opts = append(opts, DebugMode)
|
||||
}
|
||||
if config.StandaloneJob {
|
||||
opts = append(opts, EnableStandaloneJob)
|
||||
}
|
||||
if config.RandomIdentity {
|
||||
if config.IdentityGuidance != "" {
|
||||
opts = append(opts, WithRandomIdentity(config.IdentityGuidance))
|
||||
} else {
|
||||
opts = append(opts, WithRandomIdentity())
|
||||
}
|
||||
}
|
||||
agent, err := New(opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user