From ba8406367ce3f6975663384b792c9559cdc5cff2 Mon Sep 17 00:00:00 2001 From: Berack96 Date: Fri, 31 Oct 2025 15:31:07 +0100 Subject: [PATCH 1/3] fix query check infinite loop --- src/app/agents/prompts/query_check.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/agents/prompts/query_check.md b/src/app/agents/prompts/query_check.md index 83d6293..e3ba493 100644 --- a/src/app/agents/prompts/query_check.md +++ b/src/app/agents/prompts/query_check.md @@ -13,3 +13,5 @@ - IS_CRYPTO: (empty) - NOT_CRYPTO: "I can only analyze cryptocurrency topics." - AMBIGUOUS: "Which cryptocurrency? (e.g., Bitcoin, Ethereum)" + +STOP instantly WHEN YOU CLASSIFY the query. DO NOT ANSWER the query. -- 2.49.1 From 2d1837ca4a76afd7d02224d92b3967bb53f31bb2 Mon Sep 17 00:00:00 2001 From: Berack96 Date: Fri, 31 Oct 2025 15:35:25 +0100 Subject: [PATCH 2/3] fix team leader fabricated sources --- src/app/agents/prompts/team_leader.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/agents/prompts/team_leader.md b/src/app/agents/prompts/team_leader.md index 84d2f68..649fb96 100644 --- a/src/app/agents/prompts/team_leader.md +++ b/src/app/agents/prompts/team_leader.md @@ -79,4 +79,6 @@ Timestamp: {{CURRENT_DATE}} - Never modify MarketAgent prices - Include all timestamps/sources - Retry failed tasks (max 3) -- Only report agent data \ No newline at end of file +- Only report agent data +- DO NOT fabricate or add info +- DO NOT add sources if none provided -- 2.49.1 From cf41c800bbed80d7e19edb7c41f87cc371799aef Mon Sep 17 00:00:00 2001 From: Berack96 Date: Fri, 31 Oct 2025 16:15:00 +0100 Subject: [PATCH 3/3] added pipeline sanitization --- src/app/agents/pipeline.py | 25 +++++++++++++++++---- src/app/agents/prompts/query_check.md | 5 ++++- src/app/agents/prompts/report_generation.md | 2 +- src/app/agents/prompts/team_market.md | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/app/agents/pipeline.py b/src/app/agents/pipeline.py index d69d7f1..6acaa58 100644 --- a/src/app/agents/pipeline.py +++ b/src/app/agents/pipeline.py @@ -107,7 +107,12 @@ class Pipeline: def condition_query_ok(step_input: StepInput) -> StepOutput: val = step_input.previous_step_content stop = (not val.is_crypto) if isinstance(val, QueryOutputs) else True - return StepOutput(stop=stop) + return StepOutput(stop=stop, content=step_input.input) + + def sanitization_output(step_input: StepInput) -> StepOutput: + val = step_input.previous_step_content + content = f"Query: {step_input.input}\n\nRetrieved data: {self.remove_think(str(val))}" + return StepOutput(content=content) query_check = Step(name=PipelineEvent.QUERY_CHECK, agent=query_check) info_recovery = Step(name=PipelineEvent.INFO_RECOVERY, team=team) @@ -118,6 +123,7 @@ class Pipeline: query_check, condition_query_ok, info_recovery, + sanitization_output, report_generation ]) @@ -150,11 +156,22 @@ class Pipeline: # Restituisce la risposta finale if content and isinstance(content, str): - think_str = "" - think = content.rfind(think_str) - yield content[(think + len(think_str)):] if think != -1 else content + yield cls.remove_think(content) elif content and isinstance(content, QueryOutputs): yield content.response else: logging.error(f"No output from workflow: {content}") yield "Nessun output dal workflow, qualcosa รจ andato storto." + + @classmethod + def remove_think(cls, text: str) -> str: + """ + Rimuove la sezione di pensiero dal testo. + Args: + text: Il testo da pulire. + Returns: + Il testo senza la sezione di pensiero. + """ + think_str = "" + think = text.rfind(think_str) + return text[(think + len(think_str)):] if think != -1 else text diff --git a/src/app/agents/prompts/query_check.md b/src/app/agents/prompts/query_check.md index e3ba493..9896ec8 100644 --- a/src/app/agents/prompts/query_check.md +++ b/src/app/agents/prompts/query_check.md @@ -14,4 +14,7 @@ - NOT_CRYPTO: "I can only analyze cryptocurrency topics." - AMBIGUOUS: "Which cryptocurrency? (e.g., Bitcoin, Ethereum)" -STOP instantly WHEN YOU CLASSIFY the query. DO NOT ANSWER the query. +**RULES:** +- DO NOT ANSWER the query. +- DO NOT PROVIDE ADDITIONAL INFORMATION. +- STOP instantly WHEN YOU CLASSIFY the query. diff --git a/src/app/agents/prompts/report_generation.md b/src/app/agents/prompts/report_generation.md index 1f12b6d..b1e233b 100644 --- a/src/app/agents/prompts/report_generation.md +++ b/src/app/agents/prompts/report_generation.md @@ -8,7 +8,7 @@ - NEVER use placeholders ("N/A", "Data not available") - OMIT section instead - NO example/placeholder data -**INPUT:** Structured report from Team Leader with optional sections: +**INPUT:** You will get the original user query and a structured report with optional sections: - Overall Summary - Market & Price Data (opt) - News & Market Sentiment (opt) diff --git a/src/app/agents/prompts/team_market.md b/src/app/agents/prompts/team_market.md index d3777f4..2bbebb5 100644 --- a/src/app/agents/prompts/team_market.md +++ b/src/app/agents/prompts/team_market.md @@ -19,7 +19,7 @@ Historical: `{Asset, Period: {Start, End}, Data Points, Price Range: {Low, High} **MANDATORY RULES:** 1. **Include timestamps** for every price data point 2. **Never fabricate** prices or dates - only report tool outputs -3. **Always specify the data source** (which API provided the data) +3. **Specify the data source** if provided, else state "source unavailable" 4. **Report data completeness**: If user asks for 30 days but got 7, state this explicitly 5. **Current date context**: Remind that data is as of {{CURRENT_DATE}} 6. **Token Optimization**: Be extremely concise to save tokens. Provide all necessary data using as few words as possible. Exceed 100 words ONLY if absolutely necessary to include all required data points. -- 2.49.1