Deepagent does not complete all to dos

Hi experts,

I created a deep agent and in certain use case it works, But in the majority seems it stop to complete all to dos it write itself!

Possible? Any experience or suggestions??

basically I create and deep agent to judge a conversion from a language (abap) to sql performed by an old sample but working chain.

So the deep agent needs to read a lot of file (rules, starting code and output sql) and verify correctness, create a report and possible create a correct version of the sql if needed.

It stuck after reading the files

I also try with a Lange recursion limit, but I see no error;

HELP!!! :blush:

hi @riccardofresi

could you share your implementation code?

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

:hammer_and_wrench: TOOL: write_todos
Action: Updating todo list

:hammer_and_wrench: TOOL: ls

:clipboard: PLAN UPDATE: 0/9 completed
:hourglass_not_done: 1. Read and analyze the ABAP routine (‘end_routine.abap’), SQL
:hourglass_not_done: 2. Map ABAP logic flow (loops, collects, lookups, updates) to S
:hourglass_not_done: 3. Create a detailed validation checklist including: substring
:hourglass_not_done: 4. Check substring offset handling: verify all ABAP substring o
:hourglass_not_done: 5. Check conditional update logic: ensure SY-SUBRC logic is pre
:hourglass_not_done: 6. Check filtering vs skipping: ensure ABAP CHECK/CONTINUE is n
:hourglass_not_done: 7. Check for missing fields: ensure all fields updated in ABAP
:hourglass_not_done: 8. Document all findings and discrepancies in ‘validation_notes
:hourglass_not_done: 9. Prepare final ‘VALIDATION_REPORT.md’ with status, discrepanc
:white_check_mark: Todo list updated
:white_check_mark: Tool Result: [’/\abap/', ‘/\metadata/’, ‘/\optimizer/’, ‘/\sql/’]…

:hammer_and_wrench: TOOL: ls

:hammer_and_wrench: TOOL: ls

:hammer_and_wrench: TOOL: ls
:white_check_mark: Tool Result: [‘/\abap\end_routine.abap’]…
:white_check_mark: Tool Result: [‘/\sql\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU.sql’, ‘/\sql\debug/’]…
:white_check_mark: Tool Result: [‘/\metadata\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_outfields.json’, ‘/\metadata\end/’, ‘/\metadata\fields/’]…

:hammer_and_wrench: TOOL: ls

:hammer_and_wrench: TOOL: ls

:hammer_and_wrench: TOOL: ls
:white_check_mark: Tool Result: [‘/\abap\end_routine.abap’]…
:white_check_mark: Tool Result: [‘/\sql\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU.sql’, ‘/\sql\debug/’]…
:white_check_mark: Tool Result: [‘/\metadata\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_outfields.json’, ‘/\metadata\end/’, ‘/\metadata\fields/’]…

:hammer_and_wrench: TOOL: read_file
File: ?

:hammer_and_wrench: TOOL: read_file
File: ?

:hammer_and_wrench: TOOL: ls

:hammer_and_wrench: TOOL: ls
:white_check_mark: Tool Result: [‘/\metadata\fields\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_fields_metadata.json’]…
:white_check_mark: Tool Result: 1 /** generated at 21-11-2025 - 00.22.34 **/

:white_check_mark: Tool Result: 1 METHOD GLOBAL_END.


:white_check_mark: 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’]…

:hammer_and_wrench: TOOL: read_file
File: ?

:hammer_and_wrench: TOOL: read_file
File: ?

:hammer_and_wrench: TOOL: ls

:hammer_and_wrench: TOOL: ls
:white_check_mark: Tool Result: [‘/\metadata\fields\0A0R7LSOUDD45IRFIEQDXQOFB7X1YNJU_fields_metadata.json’]…
:white_check_mark: Tool Result: 1 /** generated at 21-11-2025 - 00.22.34 **/
2

:white_check_mark: Tool Result: 1 METHOD GLOBAL_END.


:white_check_mark: 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’]…

:hammer_and_wrench: TOOL: read_file
File: ?

:hammer_and_wrench: TOOL: read_file
File: ?
:white_check_mark: Tool Result: 201 s.“ZSUBSTAT”,
202 s.“ZE_STAT”,

:white_check_mark: Tool Result: 1 {
2 “ZFC_DS08”: {

:hammer_and_wrench: TOOL: read_file
File: ?

:hammer_and_wrench: TOOL: read_file
File: ?
:white_check_mark: Tool Result: 201 s.“ZSUBSTAT”,
202 s.“ZE_STAT”,
203 s.“ZFC_STEP”,
204 s.“ZFC_STRAT”,

:hammer_and_wrench: TOOL: write_todos
Action: Updating todo list

:clipboard: PLAN UPDATE: 1/9 completed
:white_check_mark: 1. Read and analyze the ABAP routine (‘end_routine.abap’), SQL
:hourglass_not_done: 2. Map ABAP logic flow (loops, collects, lookups, updates) to S
:hourglass_not_done: 3. Create a detailed validation checklist including: substring
:hourglass_not_done: 4. Check substring offset handling: verify all ABAP substring o
:hourglass_not_done: 5. Check conditional update logic: ensure SY-SUBRC logic is pre
:hourglass_not_done: 6. Check filtering vs skipping: ensure ABAP CHECK/CONTINUE is n
:hourglass_not_done: 7. Check for missing fields: ensure all fields updated in ABAP
:hourglass_not_done: 8. Document all findings and discrepancies in 'validation_notes
:hourglass_not_done: 9. Prepare final ‘VALIDATION_REPORT.md’ with status, discrepanc
:white_check_mark: Todo list updated

:hammer_and_wrench: TOOL: write_todos
Action: Updating todo list

:clipboard: PLAN UPDATE: 1/9 completed
:white_check_mark: 1. Read and analyze the ABAP routine (‘end_routine.abap’), SQL
:hourglass_not_done: 2. Map ABAP logic flow (loops, collects, lookups, updates) to S
:hourglass_not_done: 3. Create a detailed validation checklist including: substring
:hourglass_not_done: 4. Check substring offset handling: verify all ABAP substring o
:hourglass_not_done: 5. Check conditional update logic: ensure SY-SUBRC logic is pre
:hourglass_not_done: 6. Check filtering vs skipping: ensure ABAP CHECK/CONTINUE is n
:hourglass_not_done: 7. Check for missing fields: ensure all fields updated in ABAP
:hourglass_not_done: 8. Document all findings and discrepancies in 'validation_notes
:hourglass_not_done: 9. Prepare final ‘VALIDATION_REPORT.md’ with status, discrepanc
:white_check_mark: Todo list updated

here my deep agent stop…