Skip to content

Conversation

@angiejones
Copy link
Collaborator

@angiejones angiejones commented Jan 18, 2026

Summary

Problem

When using /prompt in the CLI with multi-message MCP prompts (e.g., User → Assistant → User), only the final user message was being interpreted by the model.

Root Cause

  1. handle_prompt_command correctly added all prompt messages to self.messages (local conversation)
  2. But process_agent_response only sent self.messages.last() to agent.reply()
  3. agent.reply() added that single message to the session, then retrieved the conversation from the session
  4. Result: Earlier messages from the prompt were never added to the session

Fix

Before calling process_agent_response, we now sync all messages except the last one to the session via session_manager.add_message(). The last message is still added by agent.reply() as normal, ensuring the full conversation context is available to the agent.

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

ran test suite. thought about adding a new test but testing handle_prompt_command directly is complex because it requires a full CliSession with Agent. I did temporarily implement it with mocking just to make sure the fix worked, but it added little value as a regression test. open to ideas if anyone thinks we need one

Related Issues

fixes #6506

Fixes #6506

When using /prompt in the CLI with multi-message MCP prompts, only the
final user message was being interpreted by the model. This happened
because:

1. handle_prompt_command added all prompt messages to self.messages (local)
2. process_agent_response only sent self.messages.last() to agent.reply()
3. agent.reply() added that single message to the session, then retrieved
   the conversation from the session - missing all earlier prompt messages

The fix syncs all messages except the last one to the session via
session_manager.add_message() before calling process_agent_response.
The last message is still added by agent.reply() as normal, ensuring
the full conversation context is available to the agent.
Copilot AI review requested due to automatic review settings January 18, 2026 22:13
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 bug where multi-message MCP prompts executed via /prompt were not fully synced to the session before the agent processed them. The root cause was that only the final message was being added to the session by agent.reply(), while earlier messages remained only in the local conversation state.

Changes:

  • Added message synchronization logic to ensure all prompt messages except the last are added to the session before agent processing

@angiejones angiejones merged commit 21d63f4 into main Jan 19, 2026
20 checks passed
@angiejones angiejones deleted the fix/mcp-prompts-cli-multi-message branch January 19, 2026 00:52
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.

MCP Prompts only respect final user message in CLI

3 participants