mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
feat: enhance report generation with length constraints and user-friendly language guidelines
This commit is contained in:
parent
e059ee4193
commit
e568ded743
2 changed files with 24 additions and 4 deletions
|
|
@ -23,6 +23,8 @@ Today's date (UTC): {resolved_today}
|
|||
|
||||
When writing mathematical formulas or equations, ALWAYS use LaTeX notation. NEVER use backtick code spans or Unicode symbols for math.
|
||||
|
||||
NEVER expose internal tool parameter names, backend IDs, or implementation details to the user. Always use natural, user-friendly language instead.
|
||||
|
||||
</system_instruction>
|
||||
"""
|
||||
|
||||
|
|
@ -37,6 +39,8 @@ Today's date (UTC): {resolved_today}
|
|||
|
||||
When writing mathematical formulas or equations, ALWAYS use LaTeX notation. NEVER use backtick code spans or Unicode symbols for math.
|
||||
|
||||
NEVER expose internal tool parameter names, backend IDs, or implementation details to the user. Always use natural, user-friendly language instead.
|
||||
|
||||
</system_instruction>
|
||||
"""
|
||||
|
||||
|
|
@ -120,8 +124,9 @@ You have access to the following tools:
|
|||
* "auto" — Use source_content if sufficient, otherwise fall back to internal KB search using search_queries.
|
||||
* "provided" — Use only what is in source_content (default, backward-compatible).
|
||||
- search_queries: When source_strategy is "kb_search" or "auto", provide 1-5 specific search queries for the knowledge base. These should be precise, not just the topic name repeated.
|
||||
- report_style: Optional style. Options: "detailed" (default), "executive_summary", "deep_research", "brief"
|
||||
- user_instructions: Optional specific instructions (e.g., "focus on financial impacts", "include recommendations"). When revising (parent_report_id set), describe WHAT TO CHANGE.
|
||||
- report_style: Controls report depth. Options: "detailed" (DEFAULT), "deep_research", "brief".
|
||||
Use "brief" ONLY when the user explicitly asks for a short/concise/one-page report (e.g., "one page", "keep it short", "brief report", "500 words"). Default to "detailed" for all other requests.
|
||||
- user_instructions: Optional specific instructions (e.g., "focus on financial impacts", "include recommendations"). When revising (parent_report_id set), describe WHAT TO CHANGE. If the user mentions a length preference (e.g., "one page", "500 words", "2 pages"), include that VERBATIM here AND set report_style="brief".
|
||||
- parent_report_id: Set this to the report_id from a previous generate_report result when the user wants to MODIFY an existing report. Do NOT set it for new reports or questions about reports.
|
||||
- Returns: A dictionary with status "ready" or "failed", report_id, title, and word_count.
|
||||
- The report is generated immediately in Markdown and displayed inline in the chat.
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ _REPORT_PROMPT = """You are an expert report writer. Generate a comprehensive Ma
|
|||
|
||||
---
|
||||
|
||||
{length_instruction}
|
||||
|
||||
Write a well-structured Markdown report with a # title, executive summary, organized sections, and conclusion. Cite facts from the source content. Be thorough and professional.
|
||||
|
||||
{formatting_rules}
|
||||
|
|
@ -102,6 +104,8 @@ _REVISION_PROMPT = """You are an expert report editor. Apply ONLY the requested
|
|||
|
||||
---
|
||||
|
||||
{length_instruction}
|
||||
|
||||
Preserve all structure and content not affected by the modification.
|
||||
|
||||
{formatting_rules}
|
||||
|
|
@ -696,8 +700,7 @@ def create_generate_report_tool(
|
|||
search_queries: When source_strategy is "kb_search" or "auto",
|
||||
provide 1-5 targeted search queries for the knowledge base.
|
||||
These should be specific, not just the topic repeated.
|
||||
report_style: "detailed", "executive_summary", "deep_research",
|
||||
or "brief".
|
||||
report_style: "detailed", "deep_research", or "brief".
|
||||
user_instructions: Optional focus or modification instructions.
|
||||
When revising (parent_report_id set), describe WHAT TO CHANGE.
|
||||
parent_report_id: ID of a previous report to revise (creates new
|
||||
|
|
@ -897,6 +900,16 @@ def create_generate_report_tool(
|
|||
|
||||
capped_source = effective_source[:100000] # Cap source content
|
||||
|
||||
# Length constraint — only when user explicitly asks for brevity
|
||||
length_instruction = ""
|
||||
if report_style == "brief":
|
||||
length_instruction = (
|
||||
"**LENGTH CONSTRAINT (MANDATORY):** The user wants a SHORT report. "
|
||||
"Keep it concise — aim for ~500 words (~1 page) unless a different "
|
||||
"length is specified in the Additional Instructions above. "
|
||||
"Prioritize brevity over thoroughness. Do NOT write a long report."
|
||||
)
|
||||
|
||||
# ── Phase 2: LLM GENERATION (no DB connection held) ──────────
|
||||
|
||||
report_content: str | None = None
|
||||
|
|
@ -944,6 +957,7 @@ def create_generate_report_tool(
|
|||
or "Improve and refine the report.",
|
||||
source_content=capped_source,
|
||||
previous_report_content=parent_report_content,
|
||||
length_instruction=length_instruction,
|
||||
formatting_rules=_FORMATTING_RULES,
|
||||
)
|
||||
response = await llm.ainvoke([HumanMessage(content=prompt)])
|
||||
|
|
@ -966,6 +980,7 @@ def create_generate_report_tool(
|
|||
user_instructions_section=user_instructions_section,
|
||||
previous_version_section="",
|
||||
source_content=capped_source,
|
||||
length_instruction=length_instruction,
|
||||
formatting_rules=_FORMATTING_RULES,
|
||||
)
|
||||
response = await llm.ainvoke([HumanMessage(content=prompt)])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue