Skip to content

feat(slack): append triggering message to thread context body#1230

Open
jkahuja wants to merge 3 commits into
kelos-dev:mainfrom
datagravity-ai:feat/slack-thread-trigger-marker
Open

feat(slack): append triggering message to thread context body#1230
jkahuja wants to merge 3 commits into
kelos-dev:mainfrom
datagravity-ai:feat/slack-thread-trigger-marker

Conversation

@jkahuja
Copy link
Copy Markdown
Contributor

@jkahuja jkahuja commented May 28, 2026

Summary

When a thread reply spawns a task, the agent receives the full thread history in {{.Body}} but has no indicator of which message triggered this specific task. This can cause the agent to act on earlier messages in the thread instead of the triggering one.

This appends a short instruction at the end of the thread context body telling the agent to respond to the last user message:

Slack thread conversation:

User: do the thing

Agent: Working on it

User: here is extra context

---
The last user message in this thread is what triggered this task.
Respond to it specifically. Prior messages and agent responses are context.
  • Single code change in handleMessageEvent — no spawner YAML updates needed
  • All Slack spawners benefit immediately without opt-in
  • Additive change — existing thread format is preserved
  • No text duplication — the triggering message already appears as the last thread entry

Test plan

  • Existing unit tests pass unchanged
  • Deploy and trigger a thread reply — confirm task spec.prompt contains the trailing instruction
  • Verify top-level (non-thread) messages are unaffected

🤖 Generated with Claude Code

@github-actions github-actions Bot added needs-triage needs-kind Indicates an issue or PR lacks a kind/* label needs-priority needs-actor needs-release-note Indicates a PR lacks a release-note block labels May 28, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/slack/handler.go Outdated
When a thread reply spawns a task, the agent receives the full thread
history but has no indicator of which message triggered this specific
task. This can cause the agent to act on earlier messages instead of
the one that spawned it.

Append a short instruction at the end of the thread context body
telling the agent to respond to the last user message. This uses the
highest-attention position (end of prompt) without duplicating text.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@jkahuja jkahuja force-pushed the feat/slack-thread-trigger-marker branch from acc182d to 7b317bb Compare May 28, 2026 19:01
Comment thread internal/slack/handler.go Outdated
"channel", innerEvent.Channel, "threadTS", innerEvent.ThreadTimeStamp)
} else {
msg.Body = body
msg.Body = body + "\n---\nThe last user message in this thread is what triggered this task. Respond to it specifically. Prior messages and agent responses are context.\n"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can add this instruction to the task's prompt.

not sure about adding a specific instruction to msg.Body is right thing to do.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gjkim42 yeah that did read more like a prompt. My thought here is we could update our own slack agent prompts to let it know what the triggering message is, but then everyone using the slack integration would have to do that. I'm trying something different here now -- the last message in the thread is marked as being the "triggering message". The entire slack thread is passed as the body but marking one as "triggering message" would help the agent know which one to pay attention to.

…trigger

Replace the natural-language instruction appended to thread context body
with a [TRIGGERING MESSAGE] prefix on the last message. This keeps prompt
engineering in the spawner's promptTemplate where it belongs, while still
making it unambiguous which message spawned the task.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…full pre-pass

Walk backward from the end to find the last non-empty message instead of
calling formatAttachments() on every message in a forward pre-pass.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-actor needs-kind Indicates an issue or PR lacks a kind/* label needs-priority needs-release-note Indicates a PR lacks a release-note block needs-triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants