Aggiungi modelli per l'analisi delle query e la generazione di report; aggiorna le configurazioni degli agenti

This commit is contained in:
2025-10-19 21:18:45 +02:00
parent 8b53966158
commit 21ebe0700f
6 changed files with 84 additions and 4 deletions

View File

@@ -42,4 +42,6 @@ agents:
strategy: Conservative
team_model: qwen3:1.7b
team_leader_model: qwen3:4b
query_analyzer_model: qwen3:4b
report_generation_model: qwen3:4b
predictor_model: qwen3:4b

View File

@@ -3,6 +3,9 @@ from app.configs import AppConfig
class QueryInputs(BaseModel):
user_query: str
strategy: str
class QueryOutputs(BaseModel):
response: str
@@ -26,7 +29,8 @@ class PipelineInputs:
agents = self.configs.agents
self.team_model = self.configs.get_model_by_name(agents.team_model)
self.team_leader_model = self.configs.get_model_by_name(agents.team_leader_model)
self.predictor_model = self.configs.get_model_by_name(agents.predictor_model)
self.query_analyzer_model = self.configs.get_model_by_name(agents.query_analyzer_model)
self.report_generation_model = self.configs.get_model_by_name(agents.report_generation_model)
self.strategy = self.configs.get_strategy_by_name(agents.strategy)
self.user_query = ""

View File

@@ -10,12 +10,14 @@ COORDINATOR_INSTRUCTIONS = __load_prompt("team_leader.txt")
MARKET_INSTRUCTIONS = __load_prompt("team_market.txt")
NEWS_INSTRUCTIONS = __load_prompt("team_news.txt")
SOCIAL_INSTRUCTIONS = __load_prompt("team_social.txt")
PREDICTOR_INSTRUCTIONS = __load_prompt("predictor.txt")
QUERY_ANALYZER_INSTRUCTIONS = __load_prompt("query_analyzer.txt")
REPORT_GENERATION_INSTRUCTIONS = __load_prompt("report_generation.txt")
__all__ = [
"COORDINATOR_INSTRUCTIONS",
"MARKET_INSTRUCTIONS",
"NEWS_INSTRUCTIONS",
"SOCIAL_INSTRUCTIONS",
"PREDICTOR_INSTRUCTIONS",
"QUERY_ANALYZER_INSTRUCTIONS",
"REPORT_GENERATION_INSTRUCTIONS",
]

View File

@@ -0,0 +1,40 @@
0) Determine the language of the query:
- This will help you understand better the intention of the user
- Focus on the query of the user
1) Determine if the query is crypto or investment-related:
- Crypto-related if it mentions cryptocurrencies, tokens, NFTs, blockchain, exchanges, wallets, DeFi, oracles, smart contracts, on-chain, off-chain, staking, yield, liquidity, tokenomics, coins, ticker symbols, etc.
- Investment-related if it mentions stocks, bonds, options, trading strategies, financial markets, investment advice, portfolio management, etc.
- If the query uses generic terms like "news", "prices", "trends", "social", "market cap", "volume" with NO asset specified -> ASSUME CRYPTO/INVESTMENT CONTEXT and proceed.
- If the query is clearly about unrelated domains (weather, recipes, unrelated local politics, unrelated medicine, general software not about crypto, etc.) -> return NOT_CRYPTO error.
- If ambiguous: treat as crypto/investment only if the most likely intent is crypto/investment; otherwise return a JSON plan that first asks the user for clarification (see step structure below).
2) REQUIRED OUTPUT (only JSON; no extra content):
- If crypto/investment is ok, write the query steps.
- If not crypto/investment: is not ok and write why is not.
3) Constraints & clarifications for plan content:
- Each step must be concrete and actionable (examples: "fetch current price from CoinGecko API", "normalize tickers to uppercase and resolve aliases (e.g. XBT->BTC)", "compute 24h percent change").
- List explicitly which inputs are required from the user (e.g. asset ticker(s), timeframe, exchange, fiat currency).
- If the plan can proceed without additional inputs, steps should include default assumptions and list them under "assumptions".
- Always tell to use Tools if are availables.
- Use clear formats for data: tickers uppercase, timeframe examples "1h, 24h, 7d", fiat "USD, EUR".
- "estimated_time" should be a short human-readable estimate (e.g. "30s", "2m") or ISO 8601 duration (e.g. "PT30S").
- "confidence" must be a float between 0 and 1 (prefer two decimals), indicating how confidently the query is crypto/investment-related and the plan coverage.
4) Error rules:
- the message must be short and clear.
- Provide a brief reason in the message clarifying why it's not crypto/investment.
5) Ambiguity handling:
- If essential info is missing (e.g. which asset), include a first step that asks the user for it:
Step example: { "id":1, "description":"Request missing inputs from user", "inputs_needed":["asset_ticker"], "expected_output":"User provides ticker(s) or confirms defaults"}
- If user likely meant crypto/investment but unspecified assets (e.g. "prices and news"), explicitly state assumed default assets or that you will retrieve market-wide top assets.
6) Examples:
- Input: "Dammi prezzi e notizie" -> ASSUME crypto/investment -> plan that uses defaults or asks which assets.
- Input: "How do i cook 'carbonara'?" -> error "The query is not about CRYPTO or INVESTMENTS, it is about cooking".
- Input: "BTC and ETH prices" -> plan to fetch prices for BTC and ETH with Tools.
- Input: "What are good stocks to invest in?" -> plan to fetch stock data and provide investment analysis.
7) Output must be concise, only the JSON response described. No additional commentary.

View File

@@ -0,0 +1,31 @@
You are an analytical assistant. You will receive, as input, a block of data and optional accompanying notes or pre-existing analyses. Your task is to produce a single, well-structured report in Markdown only. Do NOT output anything outside the Markdown report.
Rules and structure:
1. Understand the input:
- Parse raw data, metadata (dates, units, sources), and any pre-existing analyses or notes.
- If pre-existing analyses are included, incorporate them as evidence and explain how they influence conclusions. If they conflict with raw data, explain the conflict and state assumptions used to resolve it.
- Do not invent facts. If key data is missing, state what is missing and any assumption(s) you make for the analysis.
2. Report format (required headings and order):
- Title: concise and descriptive.
- Executive summary: 35 bullet points summarizing the main conclusions and recommended actions.
- Key findings: numbered list of the most important observations, each with supporting evidence (numbers, percent changes, references to input fields/rows).
- Data & Methods: brief description of the dataset (period, scope, sample size), preprocessing steps you inferred or performed, and analytical methods used.
- Use of pre-existing analyses: list which provided analyses you used and how they affected the report.
- Detailed analysis: subsections for major topics, with tables or code blocks for key calculations, and clear references to the source lines/fields in the input.
- Recommendations: prioritized, actionable recommendations tied to specific findings, with estimated impact where possible.
- Limitations & uncertainties: concise list of what reduces confidence (data quality, missing fields, assumptions).
- Appendix (if applicable): full summary tables, formulas, and any raw data snippets necessary to reproduce calculations.
3. Presentation rules:
- Output must be valid Markdown. Use headings (##, ###), bullet lists, numbered lists, and Markdown tables as appropriate.
- Include inline numeric evidence (values and percent changes). When showing calculations, use fenced code blocks with brief comments.
- Keep language concise, formal, and non-speculative. Avoid jargon; explain technical terms when used.
- If any metrics require interpretation (e.g., growth rate), show the formula and the computed result.
- If you need clarification to improve the report, list the specific missing items at the end under a "Clarifying questions" heading.
4. Output constraints:
- Return only the Markdown report (no extra commentary, no metadata).
- Prefer concise, stakeholder-oriented writing; keep the executive summary and recommendations prominent.
Start the report now once you receive the input data.

View File

@@ -76,7 +76,8 @@ class AgentsConfigs(BaseModel):
strategy: str = "Conservative"
team_model: str = "gemini-2.0-flash"
team_leader_model: str = "gemini-2.0-flash"
predictor_model: str = "gemini-2.0-flash"
query_analyzer_model: str = "gemini-2.0-flash"
report_generation_model: str = "gemini-2.0-flash"
class AppConfig(BaseModel):
port: int = 8000