Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

The agent was replying to the root post of conversation threads instead of the specific post where it was mentioned, breaking conversation threading.

Changes

  • GrokService.analyzeAndDecide(): Added mentionPostId parameter to accept the ID of the post containing the mention
  • Line 65 in grok.ts: Changed from thread.root_post.id to mentionPostId when calling parseGrokResponse()
  • Simulation mode: Updated to use mentionPostId for both reply and analyze actions
  • Call sites: Updated agent.ts and examples.ts to pass mention.post.id as third argument

Example

// Before - replies went to thread root
const analysis = await this.grokService.analyzeAndDecide(
  mention.post.text,
  thread
);

// After - replies target the specific mention
const analysis = await this.grokService.analyzeAndDecide(
  mention.post.text,
  thread,
  mention.post.id  // ID of post where agent was mentioned
);

The action.target_post_id now correctly references the mention post, ensuring xClient.postReply() creates proper reply chains.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix potential bug in response handling in grok.ts Fix agent replies targeting thread root instead of mention post Jan 28, 2026
Copilot AI requested a review from groupthinking January 28, 2026 17:08
@groupthinking groupthinking marked this pull request as ready for review February 5, 2026 11:56
Copilot AI review requested due to automatic review settings February 5, 2026 11:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug where the agent was replying to the root post of conversation threads instead of the specific post where it was mentioned, breaking proper conversation threading in X/Twitter.

Changes:

  • Added mentionPostId parameter to GrokService.analyzeAndDecide() method to track the specific mention post
  • Updated all call sites to pass mention.post.id as the third argument
  • Modified both simulation and production code paths to use the mention post ID for setting target_post_id

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/services/grok.ts Added mentionPostId parameter to analyzeAndDecide() and simulateAnalysis() methods; updated to pass this ID to parseGrokResponse() and use it in simulation mode for both reply and analyze actions
src/services/agent.ts Updated call to analyzeAndDecide() to pass mention.post.id as the third argument
src/examples.ts Updated both example functions (example1 and example5) to pass mention.post.id as the third argument to analyzeAndDecide()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@groupthinking groupthinking merged commit 88983ff into main Feb 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants