Add conversation history for jobs
This commit is contained in:
@@ -167,6 +167,9 @@ func (a *Agent) consumeJob(job *Job, role string) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
a.actionContext = action.NewContext(ctx, cancel)
|
||||
a.selfEvaluationInProgress = selfEvaluation
|
||||
if len(job.conversationHistory) != 0 {
|
||||
a.currentConversation = job.conversationHistory
|
||||
}
|
||||
a.Unlock()
|
||||
|
||||
if selfEvaluation {
|
||||
|
||||
@@ -2,6 +2,8 @@ package agent
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
// Job is a request to the agent to do something
|
||||
@@ -14,6 +16,7 @@ type Job struct {
|
||||
Result *JobResult
|
||||
reasoningCallback func(ActionCurrentState) bool
|
||||
resultCallback func(ActionState)
|
||||
conversationHistory []openai.ChatCompletionMessage
|
||||
}
|
||||
|
||||
// JobResult is the result of a job
|
||||
@@ -28,6 +31,12 @@ type JobResult struct {
|
||||
|
||||
type JobOption func(*Job)
|
||||
|
||||
func WithConversationHistory(history []openai.ChatCompletionMessage) JobOption {
|
||||
return func(j *Job) {
|
||||
j.conversationHistory = history
|
||||
}
|
||||
}
|
||||
|
||||
func WithReasoningCallback(f func(ActionCurrentState) bool) JobOption {
|
||||
return func(r *Job) {
|
||||
r.reasoningCallback = f
|
||||
|
||||
@@ -43,6 +43,17 @@ type AgentPool struct {
|
||||
|
||||
type AgentPoolData map[string]AgentConfig
|
||||
|
||||
func loadPoolFromFile(path string) (*AgentPoolData, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
poolData := &AgentPoolData{}
|
||||
err = json.Unmarshal(data, poolData)
|
||||
return poolData, err
|
||||
}
|
||||
|
||||
func NewAgentPool(model, apiURL, directory string) (*AgentPool, error) {
|
||||
// if file exists, try to load an existing pool.
|
||||
// if file does not exist, create a new pool.
|
||||
@@ -92,10 +103,6 @@ func (a *AgentPool) CreateAgent(name string, agentConfig *AgentConfig) error {
|
||||
return a.startAgentWithConfig(name, agentConfig)
|
||||
}
|
||||
|
||||
func (a *AgentPool) GetManager(name string) Manager {
|
||||
return a.managers[name]
|
||||
}
|
||||
|
||||
func (a *AgentPool) List() []string {
|
||||
var agents []string
|
||||
for agent := range a.pool {
|
||||
@@ -297,13 +304,6 @@ func (a *AgentPool) GetAgent(name string) *Agent {
|
||||
return a.agents[name]
|
||||
}
|
||||
|
||||
func loadPoolFromFile(path string) (*AgentPoolData, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
poolData := &AgentPoolData{}
|
||||
err = json.Unmarshal(data, poolData)
|
||||
return poolData, err
|
||||
func (a *AgentPool) GetManager(name string) Manager {
|
||||
return a.managers[name]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user