Skip to content

Commit c36f747

Browse files
committed
Resolved conflicts in ChatMessage
2 parents 36f71de + 132b093 commit c36f747

File tree

7 files changed

+515
-42
lines changed

7 files changed

+515
-42
lines changed

api/agents/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from .relevancy_agent import RelevancyAgent
55
from .follow_up_agent import FollowUpAgent
66
from .response_formatter_agent import ResponseFormatterAgent
7+
from .healer_agent import HealerAgent
78
from .utils import parse_response
89

910
__all__ = [
1011
"AnalysisAgent",
1112
"RelevancyAgent",
1213
"FollowUpAgent",
1314
"ResponseFormatterAgent",
15+
"HealerAgent",
1416
"parse_response"
1517
]

api/agents/analysis_agent.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,29 @@ def get_analysis( # pylint: disable=too-many-arguments, too-many-positional-arg
1818
db_description: str,
1919
instructions: str | None = None,
2020
memory_context: str | None = None,
21+
database_type: str | None = None,
2122
) -> dict:
2223
"""Get analysis of user query against database schema."""
2324
formatted_schema = self._format_schema(combined_tables)
25+
# Add system message with database type if not already present
26+
if not self.messages or self.messages[0].get("role") != "system":
27+
self.messages.insert(0, {
28+
"role": "system",
29+
"content": (
30+
f"You are a SQL expert. TARGET DATABASE: "
31+
f"{database_type.upper() if database_type else 'UNKNOWN'}"
32+
)
33+
})
34+
2435
prompt = self._build_prompt(
25-
user_query, formatted_schema, db_description, instructions, memory_context
36+
user_query, formatted_schema, db_description,
37+
instructions, memory_context, database_type
2638
)
2739
self.messages.append({"role": "user", "content": prompt})
2840
completion_result = completion(
2941
model=Config.COMPLETION_MODEL,
3042
messages=self.messages,
3143
temperature=0,
32-
top_p=1,
3344
)
3445

3546
response = completion_result.choices[0].message.content
@@ -158,7 +169,8 @@ def _format_foreign_keys(self, foreign_keys: dict) -> str:
158169

159170
def _build_prompt( # pylint: disable=too-many-arguments, too-many-positional-arguments
160171
self, user_input: str, formatted_schema: str,
161-
db_description: str, instructions, memory_context: str | None = None
172+
db_description: str, instructions, memory_context: str | None = None,
173+
database_type: str | None = None,
162174
) -> str:
163175
"""
164176
Build the prompt for Claude to analyze the query.
@@ -169,6 +181,7 @@ def _build_prompt( # pylint: disable=too-many-arguments, too-many-positional-a
169181
db_description: Description of the database
170182
instructions: Custom instructions for the query
171183
memory_context: User and database memory context from previous interactions
184+
database_type: Target database type (sqlite, postgresql, mysql, etc.)
172185
173186
Returns:
174187
The formatted prompt for Claude
@@ -196,6 +209,8 @@ def _build_prompt( # pylint: disable=too-many-arguments, too-many-positional-a
196209
prompt = f"""
197210
You must strictly follow the instructions below. Deviations will result in a penalty to your confidence score.
198211
212+
TARGET DATABASE: {database_type.upper() if database_type else 'UNKNOWN'}
213+
199214
MANDATORY RULES:
200215
- Always explain if you cannot fully follow the instructions.
201216
- Always reduce the confidence score if instructions cannot be fully applied.

0 commit comments

Comments
 (0)