diff --git a/infra/main.bicep b/infra/main.bicep index 2b8858531..ba54fa1e5 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -158,7 +158,8 @@ var functionAppSqlPrompt = '''Generate a valid T-SQL query to find {query} for t ALWAYS select Client Name (Column: Client) in the query. Query filters are IMPORTANT. Add filters like AssetType, AssetDate, etc. if needed. When answering scheduling or time-based meeting questions, always use the StartTime column from ClientMeetings table. Use correct logic to return the most recent past meeting (last/previous) or the nearest future meeting (next/upcoming), and ensure only StartTime column is used for meeting timing comparisons. - For asset values: if question is about total \"asset value\"/\"portfolio value\"/\"AUM\" → return SUM of latest investments; if about \"current asset/investment value\" → return all latest investments without SUM. + For asset values: If the question is about "asset value", "total asset value", "portfolio value", or "AUM" → ALWAYS return the SUM of the latest investments (do not return individual rows). If the question is about "current asset value" or "current investment value" → return all latest investments without SUM. + For trend queries: If the question contains "how did change", "over the last", "trend", or "progression" → return time series data for the requested period with SUM for each time period and show chronological progression. Only return the generated SQL query. Do not return anything else.''' var functionAppCallTranscriptSystemPrompt = '''You are an assistant who supports wealth advisors in preparing for client meetings. diff --git a/src/App/backend/agents/agent_factory.py b/src/App/backend/agents/agent_factory.py index 0e4ac3467..37f67d97a 100644 --- a/src/App/backend/agents/agent_factory.py +++ b/src/App/backend/agents/agent_factory.py @@ -183,7 +183,8 @@ async def get_sql_agent(cls) -> dict: - Do not use client name for filtering - Assets table contains snapshots by date; do not sum values across dates - Use StartTime for time-based filtering (meetings) - - For asset values: if question is about total "asset value"/"portfolio value"/"AUM" → return SUM of latest investments; if about "current asset/investment value" → return all latest investments without SUM. + - For asset values: If the question is about "asset value", "total asset value", "portfolio value", or "AUM" → ALWAYS return the SUM of the latest investments (do not return individual rows). If the question is about "current asset value" or "current investment value" → return all latest investments without SUM. + - For trend queries: If the question contains "how did change", "over the last", "trend", or "progression" → return time series data for the requested period with SUM for each time period and show chronological progression. - Only return the raw T-SQL query. No explanations or comments. """