Skip to content

Commit 01cd929

Browse files
halfaipgclaude
andcommitted
fix: give glue models awareness of agent conversation history
- Pass recent agent context (last 3 exchanges) to ChatReply - Skip LLM classification when there's active history — follow-ups after a build go straight to agent - Only greetings/thanks route to chat when conversation is active Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e4116c7 commit 01cd929

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

chat.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,28 @@ func newChatModel(cfg *Config) chatModel {
124124
}
125125
}
126126

127+
// recentContext extracts the last few user/assistant exchanges from the agent
128+
// history so that glue models (classify, chat) know what was said.
129+
func (m *chatModel) recentContext() []ChatMessage {
130+
if m.agent == nil {
131+
return nil
132+
}
133+
// Pull user + assistant messages from agent history (skip system, tool)
134+
var msgs []ChatMessage
135+
for _, msg := range m.agent.history {
136+
if msg.Role == "user" || msg.Role == "assistant" {
137+
if msg.Content != nil && *msg.Content != "" {
138+
msgs = append(msgs, ChatMessage{Role: msg.Role, Content: msg.Content})
139+
}
140+
}
141+
}
142+
// Keep last 6 messages max (3 exchanges) to stay cheap
143+
if len(msgs) > 6 {
144+
msgs = msgs[len(msgs)-6:]
145+
}
146+
return msgs
147+
}
148+
127149
func (m chatModel) Init() tea.Cmd {
128150
return tea.Batch(
129151
textinput.Blink,
@@ -204,6 +226,7 @@ func (m chatModel) Update(msg tea.Msg) (chatModel, tea.Cmd) {
204226

205227
// Route through glue intent classification
206228
hasHistory := m.agent != nil
229+
ctx := m.recentContext()
207230
intent := m.glue.ClassifyIntent(prompt, hasHistory)
208231

209232
switch intent {
@@ -214,7 +237,7 @@ func (m chatModel) Update(msg tea.Msg) (chatModel, tea.Cmd) {
214237
})
215238
glue := m.glue
216239
cmds = append(cmds, func() tea.Msg {
217-
reply := glue.ChatReply(prompt, nil)
240+
reply := glue.ChatReply(prompt, ctx)
218241
return glueResultMsg{kind: "chat", text: reply}
219242
})
220243

glue.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ When in doubt, pick "agent". Respond with ONLY one word: agent, plan, chat, or c
8080

8181
// ClassifyIntent determines what kind of response a user message needs.
8282
func (g *GlueClient) ClassifyIntent(userMsg string, hasHistory bool) Intent {
83+
// If there's an active conversation, follow-ups almost always go to agent.
84+
// Only classify from scratch on the first message or after a greeting.
85+
if hasHistory {
86+
// Quick check: is this clearly just "thanks" / "hi" / "ok"?
87+
lower := strings.ToLower(strings.TrimSpace(userMsg))
88+
greetings := []string{"hi", "hey", "hello", "thanks", "thank you", "ok", "cool", "nice", "bye"}
89+
for _, g := range greetings {
90+
if lower == g {
91+
return IntentChat
92+
}
93+
}
94+
return IntentAgent
95+
}
96+
8397
messages := []ChatMessage{
8498
{Role: "system", Content: strPtr(classifyPrompt)},
8599
{Role: "user", Content: strPtr(userMsg)},
@@ -91,17 +105,12 @@ func (g *GlueClient) ClassifyIntent(userMsg string, hasHistory bool) Intent {
91105
}
92106

93107
result = strings.TrimSpace(strings.ToLower(result))
94-
// Extract just the keyword — check plan before agent since "agent" is a substring match risk
95108
for _, intent := range []Intent{IntentPlan, IntentChat, IntentClarify, IntentAgent} {
96109
if strings.Contains(result, string(intent)) {
97-
// If they have conversation history, "clarify" becomes less useful
98-
if intent == IntentClarify && hasHistory {
99-
return IntentAgent
100-
}
101110
return intent
102111
}
103112
}
104-
return IntentAgent // default: let the agent handle it
113+
return IntentAgent
105114
}
106115

107116
// ──────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)