Skip to content

Conversation

@gautam-arklex
Copy link
Contributor

@gautam-arklex gautam-arklex commented Nov 18, 2025

Summary

Updating prompt templates to provide system prompt and conversation history separately.

Description

We're switching from providing one prompt that contains the system prompt and conversation history to providing these separately to the GenAI providers

  • System instructions are passed as system_prompt to ModelService.get_response()
  • User prompts contain conversation history and context
  • Removed manual "assistant:" markers; the model API handles role formatting
  • All streaming methods updated to use _format_messages() with system/user prompts

Tests

  • Additional console lines are written to verify if system prompts and conversation history are separated.
  • Make requests to the server bot and check the console in the Chatbot repository.

Reviewers

@arklexai/agent-leads


Note

Modernizes model interactions to use structured chat messages instead of concatenated strings.

  • Adds _format_messages() in ModelService and updates get_response/get_response_with_structured_output to accept system_prompt and conversation_history; streaming paths now pass messages
  • Changes ConvoMessage.history from str to list[dict[str,str]]; updates all workers (MessageWorker, OutputProcessWorker, SearchWorker, MilvusRAGWorker, RagMsgWorker) and RAG retrievers to format history strings as needed (often including current user turn)
  • Splits prompt templates into system-only templates (e.g., *_system) and moves conversation/context into user prompts; introduces get_prompt_templates() helper
  • Updates prompts in utils/prompts.py, removes inline assistant markers, and aligns EN/CN variants
  • Adjusts NLU agent flow, post-process rephrase, retrieval inputs, streaming generation to the new interface; updates integration tests to parse last user message from history and docs to reflect formatting

Written by Cursor Bugbot for commit 4b6d416. This will update automatically on new commits. Configure here.

@gautam-arklex
Copy link
Contributor Author

ToDo: Print lines need to be removed after testing before merging to main.

# Format messages with system prompt if provided
messages = []
# Print statement to show what's being sent to get_response
print("\n" + "="*80)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's us logging instead of printing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This temporary. Will remove it after testing is done: unless you recommend keeping it. I can convert it as a logger in that case

pyproject.toml Outdated
"fastapi-cli>=0.0.5,<1.0.0",
"greenlet>=3.1.1,<4.0.0",
"httptools>=0.6.4,<1.0.0",
"httpx>=0.28.1,<1.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this additional package needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this creeped in from the original PR. I'm investigating this rn


If you provide specific details in the response, it should be based on the conversation history or context below. Do not hallucinate.""",
"context_generator_prompt": """Conversation:
{formatted_chat}
Copy link
Collaborator

@xinyang-articulate xinyang-articulate Nov 19, 2025

Choose a reason for hiding this comment

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

As discussed for the task, we would split the conversation history into format of:
[
{
"role": "system",
"message": "<system_prompt>"
},
{
"role": "assistant",
"message": "Hi, how can I help you?"
},
{
"role": "user",
"message": "I want to ..."
}
]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yepp, I think I'm splitting it into system and conversation right now. I can make that change.

…y to using a dictionary with user/assistant format
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 18

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

system_prompt: str = system_template.invoke(
{"sys_instruct": state.sys_instruct}
).text
log_context.info(f"System prompt: {system_prompt}")
Copy link

Choose a reason for hiding this comment

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

Debug print statements need removal before merge

Multiple log_context.info() statements logging system prompts and user prompts were added for testing purposes. Per the PR discussion, these were explicitly marked "To be removed after testing" but are still present in the code. These include logging in utils.py lines 61, 119, 176, message_worker.py line 84, and output_process_worker.py lines 115-120.

Additional Locations (2)

Fix in Cursor Fix in Web

system_prompt: str = system_template.invoke(
{"sys_instruct": state.sys_instruct}
).text
log_context.info(f"System prompt: {system_prompt}")
Copy link

Choose a reason for hiding this comment

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

Debug logging statements left in code before merge

The author explicitly noted "ToDo: Print lines need to be removed after testing before merging to main" and multiple "To be removed after testing" comments in the PR discussion. There are log_context.info() statements that log system prompts and user prompts across multiple files (utils.py, message_worker.py, output_process_worker.py, rag_message_worker.py). System prompts may contain sensitive instructions and should not be logged in production. These debug statements need to be removed before merging.

Additional Locations (2)

Fix in Cursor Fix in Web

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