diff --git a/agent/agent.go b/agent/agent.go index 5ee4343..33ff7a4 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -207,6 +207,16 @@ func (a *Agent) consumeJob(job *Job, role string) { }) } + if a.options.systemPrompt != "" { + if !Messages(a.currentConversation).Exist(a.options.systemPrompt) { + a.currentConversation = append([]openai.ChatCompletionMessage{ + { + Role: "system", + Content: a.options.systemPrompt, + }}, a.currentConversation...) + } + } + // RAG if memory { // Walk conversation from bottom to top, and find the first message of the user diff --git a/agent/options.go b/agent/options.go index 82b4ef3..e5f7cfe 100644 --- a/agent/options.go +++ b/agent/options.go @@ -30,6 +30,8 @@ type options struct { kbResults int ragdb RAGDB + systemPrompt string + // callbacks reasoningCallback func(ActionCurrentState) bool resultCallback func(ActionState) @@ -110,6 +112,13 @@ func WithRAGDB(db RAGDB) Option { } } +func WithSystemPrompt(prompt string) Option { + return func(o *options) error { + o.systemPrompt = prompt + return nil + } +} + func WithLLMAPIURL(url string) Option { return func(o *options) error { o.LLMAPI.APIURL = url diff --git a/example/webui/agentpool.go b/example/webui/agentpool.go index b8e6336..c5e12fb 100644 --- a/example/webui/agentpool.go +++ b/example/webui/agentpool.go @@ -39,6 +39,7 @@ type AgentConfig struct { PermanentGoal string `json:"permanent_goal" form:"permanent_goal"` EnableKnowledgeBase bool `json:"enable_kb" form:"enable_kb"` KnowledgeBaseResults int `json:"kb_results" form:"kb_results"` + SystemPrompt string `json:"system_prompt" form:"system_prompt"` } type AgentPool struct { @@ -248,6 +249,7 @@ func (a *AgentPool) startAgentWithConfig(name string, config *AgentConfig) error } return true }), + WithSystemPrompt(config.SystemPrompt), WithAgentResultCallback(func(state ActionState) { fmt.Println("Reasoning", state.Reasoning) diff --git a/example/webui/create.html b/example/webui/create.html index 511725e..29434ce 100644 --- a/example/webui/create.html +++ b/example/webui/create.html @@ -114,6 +114,11 @@ +