sure
import os
from pathlib import Path
from deepagents import create_deep_agent
from deepagents.backends import FilesystemBackend
# 1. Definisci dove si trovano i tuoi file reali
# Usa un Path risolto per evitare problemi con i percorsi relativi
REAL_DATA_PATH = Path("./0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU").resolve()
# Assicurati che la cartella esista (o creala per il test)
if not REAL_DATA_PATH.exists():
REAL_DATA_PATH.mkdir(parents=True, exist_ok=True)
print(f"Creata cartella: {REAL_DATA_PATH}")
else:
print(f"Cartella dati: {REAL_DATA_PATH}")
instructions = """
You are an Expert SAP Migration Validator.
Your goal is to verify that generated SAP HANA SQL Script is functionally equivalent to the original ABAP routine, strictly preserving business logic and data integrity.
### CRITICAL EXECUTION RULES:
1. **FIRST, ANALYZE & PLAN**:
* Read the ABAP code, SQL code, and Metadata.
* Map the ABAP logic flow (Loop -> Collect -> Lookup -> Update) to the SQL structure (CTEs -> Joins -> Projections).
* **CREATE A DETAILED VALIDATION PLAN** listing specific checks (e.g., "Check Substring Offsets", "Verify Conditional Updates").
* Use `write_todos` to document this plan immediately.
2. **EXECUTE VERIFICATION STEPS**:
* Execute each step of your plan.
* **SAVE** intermediate findings to a file (e.g., `validation_notes.txt`).
* **UPDATE** `write_todos` after each step.
3. **DOMAIN-SPECIFIC VALIDATION LOGIC (MUST FOLLOW)**:
* **Offsets**: Verify ABAP (0-based) vs SQL (1-based) substring conversion.
* **Conditional Updates (The "SY-SUBRC" Trap)**:
* ABAP `IF SY-SUBRC = 0` means updates happen *only* if a lookup match exists.
* **FLAG AS ERROR** if SQL uses `COALESCE(lookup_col, source_col)` for these fields. This is incorrect because it updates even if the lookup failed but the source was null.
* **REQUIRE**: `CASE WHEN lookup.Key IS NOT NULL THEN lookup_col ELSE source_col END`.
* **Filtering vs. Skipping**:
* ABAP `CHECK` or `CONTINUE` inside a loop usually means "Skip Update", NOT "Delete Record".
* **FLAG AS ERROR** if SQL uses a `WHERE` clause that drops records that should only be skipped.
* **Missing Fields**: Ensure all fields updated in ABAP are present in the SQL projection.
4. **FINAL DELIVERABLE**:
* Create a `VALIDATION_REPORT.md` containing:
* **Status**: PASS / FAIL.
* **Discrepancies**: List of specific logic mismatches.
* **Corrected SQL**: A complete SQL File with corrections named TARGET_SQL.sql
* Provide a clear summary of results in your final response.
###DO NOT FORGET:
YOU HAVE TO COMPLETE THE PLAN WHATEVER IT TAKES.
Don't just compare text. THINK about the runtime behavior of the code.
"""
# 2. Configura l'agente
deep_agent = create_deep_agent(
model=llm_gpt_4_1, # Assumo tu abbia già inizializzato il modello
system_prompt=instructions, # Le istruzioni che ti ho dato prima
# tools=tools, # Se hai tool specifici
#subagents=subagents, # Se hai subagents
backend=FilesystemBackend(
root_dir=REAL_DATA_PATH, # Lavoriamo sulla cartella reale
virtual_mode=True # Espone percorsi virtuali POSIX (richiesto da deepagents)
)
)
print("FilesystemBackend inizializzato in modalità virtuale (usa percorsi tipo /abap/file.abap)")
user_request = """
considering
ABAP Routine: 'end_routine.abap'
SQL Script: '0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU.sql'
Metadata: 'step_end_metadata.json'
Please execute the validation plan as per your system_prompt.
### ATTENTION POINT ###
you have to complete the plan whatever it takes.
"""
this is my output after the invoke (i got a print function, i think it’s not necessary to paste it, but you tell me
TOOL: write_todos
Action: Updating todo list
TOOL: ls
PLAN UPDATE: 0/9 completed
1. Read and analyze the ABAP routine (‘end_routine.abap’), SQL
2. Map ABAP logic flow (loops, collects, lookups, updates) to S
3. Create a detailed validation checklist including: substring
4. Check substring offset handling: verify all ABAP substring o
5. Check conditional update logic: ensure SY-SUBRC logic is pre
6. Check filtering vs skipping: ensure ABAP CHECK/CONTINUE is n
7. Check for missing fields: ensure all fields updated in ABAP
8. Document all findings and discrepancies in ‘validation_notes
9. Prepare final ‘VALIDATION_REPORT.md’ with status, discrepanc
Todo list updated
Tool Result: [’/\abap/', ‘/\metadata/’, ‘/\optimizer/’, ‘/\sql/’]…
TOOL: ls
TOOL: ls
TOOL: ls
Tool Result: [‘/\abap\end_routine.abap’]…
Tool Result: [‘/\sql\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU.sql’, ‘/\sql\debug/’]…
Tool Result: [‘/\metadata\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_outfields.json’, ‘/\metadata\end/’, ‘/\metadata\fields/’]…
TOOL: ls
TOOL: ls
TOOL: ls
Tool Result: [‘/\abap\end_routine.abap’]…
Tool Result: [‘/\sql\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU.sql’, ‘/\sql\debug/’]…
Tool Result: [‘/\metadata\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_outfields.json’, ‘/\metadata\end/’, ‘/\metadata\fields/’]…
TOOL: read_file
File: ?
TOOL: read_file
File: ?
TOOL: ls
TOOL: ls
Tool Result: [‘/\metadata\fields\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_fields_metadata.json’]…
Tool Result: 1 /** generated at 21-11-2025 - 00.22.34 **/
…
Tool Result: 1 METHOD GLOBAL_END.
…
…
Tool Result: [‘/\metadata\end\step_end_metadata.json’, ‘/\metadata\end\step_end_metadata_alignment.json’, ‘/\metadata\end\step_end_metadata_vars.json’, ‘/\metadata\end\step_end_step1_abap_structure.json’, ‘/\metadata\end\step_end_step2_sql_logic.json’]…
TOOL: read_file
File: ?
TOOL: read_file
File: ?
TOOL: ls
TOOL: ls
Tool Result: [‘/\metadata\fields\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_fields_metadata.json’]…
Tool Result: 1 /** generated at 21-11-2025 - 00.22.34 **/
2
…
Tool Result: 1 METHOD GLOBAL_END.
…
…
Tool Result: [‘/\metadata\end\step_end_metadata.json’, ‘/\metadata\end\step_end_metadata_alignment.json’, ‘/\metadata\end\step_end_metadata_vars.json’, ‘/\metadata\end\step_end_step1_abap_structure.json’, ‘/\metadata\end\step_end_step2_sql_logic.json’]…
TOOL: read_file
File: ?
TOOL: read_file
File: ?
Tool Result: 201 s.“ZSUBSTAT”,
202 s.“ZE_STAT”,
…
Tool Result: 1 {
2 “ZFC_DS08”: {
…
TOOL: read_file
File: ?
TOOL: read_file
File: ?
Tool Result: 201 s.“ZSUBSTAT”,
202 s.“ZE_STAT”,
203 s.“ZFC_STEP”,
204 s.“ZFC_STRAT”,
…
TOOL: write_todos
Action: Updating todo list
PLAN UPDATE: 1/9 completed
1. Read and analyze the ABAP routine (‘end_routine.abap’), SQL
2. Map ABAP logic flow (loops, collects, lookups, updates) to S
3. Create a detailed validation checklist including: substring
4. Check substring offset handling: verify all ABAP substring o
5. Check conditional update logic: ensure SY-SUBRC logic is pre
6. Check filtering vs skipping: ensure ABAP CHECK/CONTINUE is n
7. Check for missing fields: ensure all fields updated in ABAP
8. Document all findings and discrepancies in 'validation_notes
9. Prepare final ‘VALIDATION_REPORT.md’ with status, discrepanc
Todo list updated
TOOL: write_todos
Action: Updating todo list
PLAN UPDATE: 1/9 completed
1. Read and analyze the ABAP routine (‘end_routine.abap’), SQL
2. Map ABAP logic flow (loops, collects, lookups, updates) to S
3. Create a detailed validation checklist including: substring
4. Check substring offset handling: verify all ABAP substring o
5. Check conditional update logic: ensure SY-SUBRC logic is pre
6. Check filtering vs skipping: ensure ABAP CHECK/CONTINUE is n
7. Check for missing fields: ensure all fields updated in ABAP
8. Document all findings and discrepancies in 'validation_notes
9. Prepare final ‘VALIDATION_REPORT.md’ with status, discrepanc
Todo list updated
here my deep agent stop…