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())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
a.actionContext = action.NewContext(ctx, cancel)
|
a.actionContext = action.NewContext(ctx, cancel)
|
||||||
a.selfEvaluationInProgress = selfEvaluation
|
a.selfEvaluationInProgress = selfEvaluation
|
||||||
|
if len(job.conversationHistory) != 0 {
|
||||||
|
a.currentConversation = job.conversationHistory
|
||||||
|
}
|
||||||
a.Unlock()
|
a.Unlock()
|
||||||
|
|
||||||
if selfEvaluation {
|
if selfEvaluation {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/sashabaranov/go-openai"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Job is a request to the agent to do something
|
// Job is a request to the agent to do something
|
||||||
@@ -9,11 +11,12 @@ type Job struct {
|
|||||||
// The job is a request to the agent to do something
|
// The job is a request to the agent to do something
|
||||||
// It can be a question, a command, or a request to do something
|
// It can be a question, a command, or a request to do something
|
||||||
// The agent will try to do it, and return a response
|
// The agent will try to do it, and return a response
|
||||||
Text string
|
Text string
|
||||||
Image string // base64 encoded image
|
Image string // base64 encoded image
|
||||||
Result *JobResult
|
Result *JobResult
|
||||||
reasoningCallback func(ActionCurrentState) bool
|
reasoningCallback func(ActionCurrentState) bool
|
||||||
resultCallback func(ActionState)
|
resultCallback func(ActionState)
|
||||||
|
conversationHistory []openai.ChatCompletionMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// JobResult is the result of a job
|
// JobResult is the result of a job
|
||||||
@@ -28,6 +31,12 @@ type JobResult struct {
|
|||||||
|
|
||||||
type JobOption func(*Job)
|
type JobOption func(*Job)
|
||||||
|
|
||||||
|
func WithConversationHistory(history []openai.ChatCompletionMessage) JobOption {
|
||||||
|
return func(j *Job) {
|
||||||
|
j.conversationHistory = history
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithReasoningCallback(f func(ActionCurrentState) bool) JobOption {
|
func WithReasoningCallback(f func(ActionCurrentState) bool) JobOption {
|
||||||
return func(r *Job) {
|
return func(r *Job) {
|
||||||
r.reasoningCallback = f
|
r.reasoningCallback = f
|
||||||
|
|||||||
@@ -43,6 +43,17 @@ type AgentPool struct {
|
|||||||
|
|
||||||
type AgentPoolData map[string]AgentConfig
|
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) {
|
func NewAgentPool(model, apiURL, directory string) (*AgentPool, error) {
|
||||||
// if file exists, try to load an existing pool.
|
// if file exists, try to load an existing pool.
|
||||||
// if file does not exist, create a new 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)
|
return a.startAgentWithConfig(name, agentConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AgentPool) GetManager(name string) Manager {
|
|
||||||
return a.managers[name]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AgentPool) List() []string {
|
func (a *AgentPool) List() []string {
|
||||||
var agents []string
|
var agents []string
|
||||||
for agent := range a.pool {
|
for agent := range a.pool {
|
||||||
@@ -297,13 +304,6 @@ func (a *AgentPool) GetAgent(name string) *Agent {
|
|||||||
return a.agents[name]
|
return a.agents[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadPoolFromFile(path string) (*AgentPoolData, error) {
|
func (a *AgentPool) GetManager(name string) Manager {
|
||||||
data, err := os.ReadFile(path)
|
return a.managers[name]
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
poolData := &AgentPoolData{}
|
|
||||||
err = json.Unmarshal(data, poolData)
|
|
||||||
return poolData, err
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user