⚗️(summarization) add system prompt to handle tool

With these modifications, we expect the LLM to not sumarize the
summarization tool result.
This commit is contained in:
Quentin BEY
2025-10-21 22:12:50 +02:00
parent ab45eea736
commit 151914f55c
5 changed files with 76 additions and 2 deletions
+1
View File
@@ -20,6 +20,7 @@ and this project adheres to
- 💬(wording) error page wording #102
- ⚡️(web-search) allow to override returned chunks #107
- 🐛(activation-codes) create contact in brevo before add to list #108
- ⚗️(summarization) add system prompt to handle tool #112
## [0.0.1] - 2025-10-19
+6 -2
View File
@@ -37,8 +37,12 @@ def read_document_content(doc):
async def hand_off_to_summarization_agent(ctx: RunContext) -> ToolReturn:
"""
Summarize the documents for the user, only when asked for,
the documents are in my context.
Generate a complete, ready-to-use summary of the documents in context
(do not request the documents to the user).
Return this summary directly to the user WITHOUT any modification,
or additional summarization.
The summary is already optimized and MUST be presented as-is in the final response
or translated preserving the information.
"""
summarization_agent = SummarizationAgent()
+13
View File
@@ -480,6 +480,19 @@ class AIAgentService: # pylint: disable=too-many-instance-attributes
elif has_not_pdf_docs:
add_document_rag_search_tool(self.conversation_agent)
@self.conversation_agent.system_prompt
def summarization_system_prompt() -> str:
return (
"When you receive a result from the summarization tool, you MUST return it "
"directly to the user without any modification, paraphrasing, or additional "
"summarization."
"The tool already produces optimized summaries that should be presented "
"verbatim."
"You may translate the summary if required, but you MUST preserve all the "
"information from the original summary."
"You may add a follow-up question after the summary if needed."
)
@self.conversation_agent.tool
async def summarize(ctx) -> ToolReturn:
"""
@@ -375,6 +375,20 @@ def test_post_conversation_with_document_upload( # noqa: PLR0913 # pylint: disa
"part_kind": "system-prompt",
"timestamp": timezone_now,
},
{
"content": "When you receive a result from the summarization tool, "
"you MUST return it directly to the user without any "
"modification, paraphrasing, or additional "
"summarization.The tool already produces optimized "
"summaries that should be presented verbatim.You may "
"translate the summary if required, but you MUST "
"preserve all the information from the original "
"summary.You may add a follow-up question after the "
"summary if needed.",
"dynamic_ref": None,
"part_kind": "system-prompt",
"timestamp": timezone_now,
},
{
"content": ["What does the document say?"],
"part_kind": "user-prompt",
@@ -688,6 +702,20 @@ def test_post_conversation_with_document_upload_summarize( # pylint: disable=to
"part_kind": "system-prompt",
"timestamp": timezone_now,
},
{
"content": "When you receive a result from the summarization tool, "
"you MUST return it directly to the user without any "
"modification, paraphrasing, or additional "
"summarization.The tool already produces optimized "
"summaries that should be presented verbatim.You may "
"translate the summary if required, but you MUST "
"preserve all the information from the original "
"summary.You may add a follow-up question after the "
"summary if needed.",
"dynamic_ref": None,
"part_kind": "system-prompt",
"timestamp": timezone_now,
},
{
"content": ["Make a summary of this document."],
"part_kind": "user-prompt",
@@ -1,4 +1,5 @@
"""Unit tests for chat conversation actions with document URL."""
# pylint: disable=too-many-lines
from io import BytesIO
@@ -860,6 +861,19 @@ def test_post_conversation_with_local_not_pdf_document_url( # noqa: PLR0913 # p
),
timestamp=timezone.now(),
),
SystemPromptPart(
content=(
"When you receive a result from the summarization tool, you MUST "
"return it directly to the user without any modification, "
"paraphrasing, or additional summarization."
"The tool already produces optimized summaries that should "
"be presented verbatim."
"You may translate the summary if required, but you MUST preserve "
"all the information from the original summary."
"You may add a follow-up question after the summary if needed."
),
timestamp=timezone.now(),
),
UserPromptPart(
content=[
"What is in this document?",
@@ -962,6 +976,20 @@ def test_post_conversation_with_local_not_pdf_document_url( # noqa: PLR0913 # p
"part_kind": "system-prompt",
"timestamp": timestamp,
},
{
"content": "When you receive a result from the summarization "
"tool, you MUST return it directly to the user without "
"any modification, paraphrasing, or additional "
"summarization.The tool already produces optimized "
"summaries that should be presented verbatim.You may "
"translate the summary if required, but you MUST "
"preserve all the information from the original "
"summary.You may add a follow-up question after the "
"summary if needed.",
"dynamic_ref": None,
"part_kind": "system-prompt",
"timestamp": timestamp,
},
{
"content": [
"What is in this document?",