Strip bot user from messages received
This commit is contained in:
@@ -115,13 +115,7 @@ func (m Messages) Exist(content string) bool {
|
|||||||
|
|
||||||
func (a *Agent) generateParameters(ctx context.Context, pickTemplate string, act Action, c []openai.ChatCompletionMessage, reasoning string) (*decisionResult, error) {
|
func (a *Agent) generateParameters(ctx context.Context, pickTemplate string, act Action, c []openai.ChatCompletionMessage, reasoning string) (*decisionResult, error) {
|
||||||
|
|
||||||
var promptHUD *PromptHUD
|
stateHUD, err := renderTemplate(pickTemplate, a.prepareHUD(), a.systemInternalActions(), reasoning)
|
||||||
if a.options.enableHUD {
|
|
||||||
h := a.prepareHUD()
|
|
||||||
promptHUD = &h
|
|
||||||
}
|
|
||||||
|
|
||||||
stateHUD, err := renderTemplate(pickTemplate, promptHUD, a.systemInternalActions(), reasoning)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -189,8 +183,12 @@ func (a *Agent) systemInternalActions() Actions {
|
|||||||
return defaultActions
|
return defaultActions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) prepareHUD() PromptHUD {
|
func (a *Agent) prepareHUD() (promptHUD *PromptHUD) {
|
||||||
return PromptHUD{
|
if !a.options.enableHUD {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &PromptHUD{
|
||||||
Character: a.Character,
|
Character: a.Character,
|
||||||
CurrentState: *a.currentState,
|
CurrentState: *a.currentState,
|
||||||
PermanentGoal: a.options.permanentGoal,
|
PermanentGoal: a.options.permanentGoal,
|
||||||
@@ -219,7 +217,7 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
|
|||||||
// Find the action
|
// Find the action
|
||||||
chosenAction := a.systemInternalActions().Find(thought.actioName)
|
chosenAction := a.systemInternalActions().Find(thought.actioName)
|
||||||
if chosenAction == nil || thought.actioName == "" {
|
if chosenAction == nil || thought.actioName == "" {
|
||||||
xlog.Debug(fmt.Sprintf("no answer"))
|
xlog.Debug("no answer")
|
||||||
|
|
||||||
// LLM replied with an answer?
|
// LLM replied with an answer?
|
||||||
//fmt.Errorf("no action found for intent:" + thought.actioName)
|
//fmt.Errorf("no action found for intent:" + thought.actioName)
|
||||||
@@ -229,13 +227,7 @@ func (a *Agent) pickAction(ctx context.Context, templ string, messages []openai.
|
|||||||
return chosenAction, thought.actionParams, thought.message, nil
|
return chosenAction, thought.actionParams, thought.message, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var promptHUD *PromptHUD
|
prompt, err := renderTemplate(templ, a.prepareHUD(), a.systemInternalActions(), "")
|
||||||
if a.options.enableHUD {
|
|
||||||
h := a.prepareHUD()
|
|
||||||
promptHUD = &h
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt, err := renderTemplate(templ, promptHUD, a.systemInternalActions(), "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, "", err
|
return nil, nil, "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,6 +222,7 @@ func (a *Agent) Pause() {
|
|||||||
a.Lock()
|
a.Lock()
|
||||||
defer a.Unlock()
|
defer a.Unlock()
|
||||||
a.pause = true
|
a.pause = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) Resume() {
|
func (a *Agent) Resume() {
|
||||||
@@ -609,15 +610,9 @@ func (a *Agent) consumeJob(job *Job, role string) {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// If we have a hud, display it
|
// If we have a hud, display it when answering normally
|
||||||
if a.options.enableHUD {
|
if a.options.enableHUD {
|
||||||
var promptHUD *PromptHUD
|
prompt, err := renderTemplate(hudTemplate, a.prepareHUD(), a.systemInternalActions(), reasoning)
|
||||||
if a.options.enableHUD {
|
|
||||||
h := a.prepareHUD()
|
|
||||||
promptHUD = &h
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt, err := renderTemplate(hudTemplate, promptHUD, a.systemInternalActions(), reasoning)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
job.Result.Finish(fmt.Errorf("error renderTemplate: %w", err))
|
job.Result.Finish(fmt.Errorf("error renderTemplate: %w", err))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ func (t *Slack) AgentReasoningCallback() func(state agent.ActionCurrentState) bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanUpUsernameFromMessage(message string, b *slack.AuthTestResponse) string {
|
||||||
|
return strings.ReplaceAll(message, "<@"+b.BotID+">", "")
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Slack) Start(a *agent.Agent) {
|
func (t *Slack) Start(a *agent.Agent) {
|
||||||
api := slack.New(
|
api := slack.New(
|
||||||
t.botToken,
|
t.botToken,
|
||||||
@@ -71,13 +75,11 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
case socketmode.EventTypeEventsAPI:
|
case socketmode.EventTypeEventsAPI:
|
||||||
eventsAPIEvent, ok := evt.Data.(slackevents.EventsAPIEvent)
|
eventsAPIEvent, ok := evt.Data.(slackevents.EventsAPIEvent)
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Printf("Ignored %+v\n", evt)
|
xlog.Debug(fmt.Sprintf("Ignored %+v\n", evt))
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Event received: %+v\n", eventsAPIEvent)
|
|
||||||
|
|
||||||
client.Ack(*evt.Request)
|
client.Ack(*evt.Request)
|
||||||
|
|
||||||
switch eventsAPIEvent.Type {
|
switch eventsAPIEvent.Type {
|
||||||
@@ -104,6 +106,7 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message := ev.Text
|
message := ev.Text
|
||||||
|
message = cleanUpUsernameFromMessage(message, b)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
ts := ev.ThreadTimeStamp
|
ts := ev.ThreadTimeStamp
|
||||||
@@ -117,7 +120,7 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
slack.MsgOptionPostMessageParameters(slack.PostMessageParameters{LinkNames: 1}),
|
slack.MsgOptionPostMessageParameters(slack.PostMessageParameters{LinkNames: 1}),
|
||||||
slack.MsgOptionTS(ts))
|
slack.MsgOptionTS(ts))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error posting message: %v", err)
|
xlog.Error(fmt.Sprintf("Error posting message: %v", err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
case *slackevents.AppMentionEvent:
|
case *slackevents.AppMentionEvent:
|
||||||
@@ -129,7 +132,7 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
message := ev.Text
|
message := ev.Text
|
||||||
|
|
||||||
// strip our id from the message
|
// strip our id from the message
|
||||||
message = strings.ReplaceAll(message, "<@"+b.UserID+"> ", "")
|
message = cleanUpUsernameFromMessage(message, b)
|
||||||
xlog.Info("Message", message)
|
xlog.Info("Message", message)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -144,9 +147,8 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
Timestamp: ts,
|
Timestamp: ts,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error fetching thread messages: %v", err)
|
xlog.Error(fmt.Sprintf("Error fetching thread messages: %v", err))
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Found messages", len(messages))
|
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
role := "assistant"
|
role := "assistant"
|
||||||
if msg.User != b.UserID {
|
if msg.User != b.UserID {
|
||||||
@@ -155,7 +157,7 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
threadMessages = append(threadMessages,
|
threadMessages = append(threadMessages,
|
||||||
openai.ChatCompletionMessage{
|
openai.ChatCompletionMessage{
|
||||||
Role: role,
|
Role: role,
|
||||||
Content: msg.Text,
|
Content: cleanUpUsernameFromMessage(msg.Text, b),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -164,12 +166,10 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
} else {
|
} else {
|
||||||
threadMessages = append(threadMessages, openai.ChatCompletionMessage{
|
threadMessages = append(threadMessages, openai.ChatCompletionMessage{
|
||||||
Role: "user",
|
Role: "user",
|
||||||
Content: message,
|
Content: cleanUpUsernameFromMessage(message, b),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("THREADS", threadMessages)
|
|
||||||
|
|
||||||
res := a.Ask(
|
res := a.Ask(
|
||||||
// agent.WithText(message),
|
// agent.WithText(message),
|
||||||
agent.WithConversationHistory(threadMessages),
|
agent.WithConversationHistory(threadMessages),
|
||||||
@@ -187,17 +187,17 @@ func (t *Slack) Start(a *agent.Agent) {
|
|||||||
slack.MsgOptionTS(ev.TimeStamp))
|
slack.MsgOptionTS(ev.TimeStamp))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error posting message: %v", err)
|
xlog.Error(fmt.Sprintf("Error posting message: %v", err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
case *slackevents.MemberJoinedChannelEvent:
|
case *slackevents.MemberJoinedChannelEvent:
|
||||||
fmt.Printf("user %q joined to channel %q", ev.User, ev.Channel)
|
xlog.Error(fmt.Sprintf("user %q joined to channel %q", ev.User, ev.Channel))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
client.Debugf("unsupported Events API event received")
|
client.Debugf("unsupported Events API event received")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "Unexpected event type received: %s\n", evt.Type)
|
xlog.Error(fmt.Sprintf("Unexpected event type received: %s", evt.Type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user