Initiate agents from pool
This commit is contained in:
@@ -39,10 +39,7 @@ type Agent struct {
|
|||||||
func New(opts ...Option) (*Agent, error) {
|
func New(opts ...Option) (*Agent, error) {
|
||||||
options, err := newOptions(opts...)
|
options, err := newOptions(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != nil {
|
return nil, fmt.Errorf("failed to set options: %v", err)
|
||||||
err = fmt.Errorf("failed to set options: %v", err)
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client := llm.NewClient(options.LLMAPI.APIKey, options.LLMAPI.APIURL)
|
client := llm.NewClient(options.LLMAPI.APIKey, options.LLMAPI.APIURL)
|
||||||
@@ -126,6 +123,12 @@ func (a *Agent) CurrentConversation() []openai.ChatCompletionMessage {
|
|||||||
return a.currentConversation
|
return a.currentConversation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Agent) SetConversation(conv []openai.ChatCompletionMessage) {
|
||||||
|
a.Lock()
|
||||||
|
defer a.Unlock()
|
||||||
|
a.currentConversation = conv
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Agent) ResetConversation() {
|
func (a *Agent) ResetConversation() {
|
||||||
a.Lock()
|
a.Lock()
|
||||||
defer a.Unlock()
|
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 {
|
func WithLLMAPIKey(key string) Option {
|
||||||
return func(o *options) error {
|
return func(o *options) error {
|
||||||
o.LLMAPI.APIKey = key
|
o.LLMAPI.APIKey = key
|
||||||
|
|||||||
@@ -16,8 +16,54 @@ type ConnectorConfig struct {
|
|||||||
type ActionsConfig string
|
type ActionsConfig string
|
||||||
|
|
||||||
type AgentConfig struct {
|
type AgentConfig struct {
|
||||||
Connector []ConnectorConfig `json:"connector"`
|
Connector []ConnectorConfig `json:"connector"`
|
||||||
Actions []ActionsConfig `json:"actions"`
|
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 {
|
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 {
|
func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error {
|
||||||
|
opts := []Option{
|
||||||
agent, err := New(
|
WithModel(config.Model),
|
||||||
WithModel("hermes-2-pro-mistral"),
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user