Skip to content

Commit a217d27

Browse files
committed
help fix semantic prompt - clean up foundry agents
1 parent c017c30 commit a217d27

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

src/backend/sql_agents/semantic_verifier/prompt.txt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@
77
- Do not hallucinate or assume any functionality that is not explicitly mentioned in the queries.
88
- Avoid using any first person language in any of the output.
99
- You are allowed to make common sense assumptions about the data and return types.
10-
- Your final answer should be a JSON with the following fields: 'analysis', 'judgement', 'differences'.
11-
- If the scripts are not semantically equivalent, judgement would be 'Semantically Not Equivalent' and list the differences in the 'differences' field.
10+
- If the scripts are not semantically equivalent, judgement would be 'Semantically Not Equivalent' and the differences would be listed in the 'differences' field.
1211
- If the scripts are semantically equivalent, judgement would be 'Semantically Equivalent' and the differences filed would be an empty list.
1312

14-
# Output structure description
15-
Your final answer should **strictly** adhere to the following JSON structure:
13+
# Output
14+
Return a JSON object with keys ‘analysis’, ‘judgement’, ‘differences’, and ‘summary’ containing the results of your analysis.
15+
Do not include any metadata, schema descriptions, or commentary—only output the JSON result.
16+
Your final output should be a JSON object like:
1617
{
17-
"analysis": "Here, you should provide a brief analysis of the source and target queries and the differences you found.",
18-
"judgement": "Semantically Equivalent/Semantically Not Equivalent",
19-
"differences": [
20-
"Description of the difference 1",
21-
"Description of the difference 2",
22-
<...>
23-
]
24-
"summary": "A one sentence description about your activities."
18+
"analysis": "Brief analysis of the queries.",
19+
"judgement": "Semantically Equivalent or Semantically Not Equivalent",
20+
"differences": ["Difference 1", "Difference 2"],
21+
"summary": "One sentence summary of your analysis."
2522
}
2623

2724
Source Query:

src/backend/sql_agents_start.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@
8585
class SqlAgents:
8686
"""Class to setup the SQL agents for migration."""
8787

88-
agent_fixer = None
89-
agent_migrator = None
90-
agent_picker = None
91-
agent_syntax_checker = None
88+
agent_fixer: AzureAIAgent = None
89+
agent_migrator: AzureAIAgent = None
90+
agent_picker: AzureAIAgent = None
91+
agent_syntax_checker: AzureAIAgent = None
9292
selection_function = None
9393
termination_function = None
94+
agent_config: AgentBaseConfig = None
9495

9596
def __init__(self):
9697
pass
@@ -101,6 +102,7 @@ async def create(cls, config: AgentBaseConfig):
101102
Required as init cannot be async"""
102103
self = cls() # Create an instance
103104
try:
105+
self.agent_config = config
104106
self.agent_fixer = await setup_fixer_agent(config)
105107
self.agent_migrator = await setup_migrator_agent(config)
106108
self.agent_picker = await setup_picker_agent(config)
@@ -132,19 +134,25 @@ def agents(self):
132134
self.agent_fixer,
133135
]
134136

137+
async def delete_agents(self):
138+
"""cleans up the agents"""
139+
try:
140+
for agent in self.agents:
141+
await self.agent_config.ai_project_client.agents.delete_agent(agent.id)
142+
except Exception as exc:
143+
logger.error("Error deleting agents: %s", exc)
144+
135145

136146
async def convert(
137147
source_script,
138148
file: FileRecord,
139149
batch_service: BatchService,
150+
sql_agents: SqlAgents,
140151
agent_config: AgentBaseConfig,
141152
) -> str:
142153
"""setup agents, selection and termination."""
143154
logger.info("Migrating query: %s\n", source_script)
144155

145-
# setup the agents
146-
sql_agents = await SqlAgents.create(agent_config)
147-
148156
history_reducer = ChatHistoryTruncationReducer(
149157
target_count=2
150158
) # keep only the last two messages
@@ -428,6 +436,9 @@ async def invoke_semantic_verifier(
428436
async for response in agent_semantic_verifier.invoke(messages=[user_message]):
429437
return response.content
430438

439+
# Clean up the agent
440+
await config.ai_project_client.agents.delete_agent(agent_semantic_verifier.id)
441+
431442
# Handle this as an exception from the Sematic Verifier is a warning
432443
except Exception as exc:
433444
logger.error(
@@ -465,11 +476,14 @@ async def process_batch_async(
465476
AzureAIAgent.create_client(credential=creds) as client,
466477
):
467478

468-
# setup all agent settings per batch
479+
# setup all agent settings and agents per batch
469480
agent_config = AgentBaseConfig(
470481
project_client=client, sql_from=convert_from, sql_to=convert_to
471482
)
472483

484+
# setup the agents
485+
sql_agents = await SqlAgents.create(agent_config)
486+
473487
# Walk through each file name and retrieve it from blob storage
474488
# Send file to the agents for processing
475489
# Send status update to the client of type in progress, completed, or failed
@@ -519,7 +533,11 @@ async def process_batch_async(
519533

520534
# Convert the file
521535
converted_query = await convert(
522-
sql_in_file, file_record, batch_service, agent_config
536+
sql_in_file,
537+
file_record,
538+
batch_service,
539+
sql_agents,
540+
agent_config,
523541
)
524542
if converted_query:
525543
# Add RAI disclaimer to the converted query - split this into a function
@@ -548,6 +566,9 @@ async def process_batch_async(
548566
# insert data base write to file record stating invalid file
549567
await process_error(exc, file_record, batch_service)
550568

569+
# Cleanup the agents
570+
await sql_agents.delete_agents()
571+
551572
try:
552573
await batch_service.batch_files_final_update(batch_id)
553574
except Exception as exc:

0 commit comments

Comments
 (0)