0
0
Agentic AIml~10 mins

Retry and fallback logic in Agentic AI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to retry a function call once if it fails.

Agentic AI
try:
    result = perform_task()
except Exception:
    result = [1]()
Drag options to blanks, or click blank then click option'
Aretry_task
Bperform_task
Cfallback_task
Dhandle_error
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a fallback function instead of retrying the main task.
Not retrying the function at all.
2fill in blank
medium

Complete the code to fallback to an alternative function if the main task fails.

Agentic AI
try:
    result = main_task()
except Exception:
    result = [1]()
Drag options to blanks, or click blank then click option'
Aalternative_task
Bmain_task
Cretry_task
Dlog_error
Attempts:
3 left
💡 Hint
Common Mistakes
Retrying the main task instead of falling back.
Logging error instead of handling fallback.
3fill in blank
hard

Fix the error in the retry loop to stop after 3 attempts.

Agentic AI
attempts = 0
while attempts < 3:
    try:
        result = task()
        break
    except Exception:
        attempts [1] 1
Drag options to blanks, or click blank then click option'
A+=
B-=
C*=
D/=
Attempts:
3 left
💡 Hint
Common Mistakes
Decreasing the attempts counter causing infinite loop.
Using multiplication or division operators incorrectly.
4fill in blank
hard

Fill both blanks to implement retry with fallback after 3 failed attempts.

Agentic AI
attempts = 0
while attempts < 3:
    try:
        result = [1]()
        break
    except Exception:
        attempts [2] 1
else:
    result = fallback()
Drag options to blanks, or click blank then click option'
Amain_task
Balternative_task
C+=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using fallback function inside the retry loop.
Decreasing attempts counter causing infinite retries.
5fill in blank
hard

Fill all three blanks to log errors, retry twice, then fallback.

Agentic AI
import logging
attempts = 0
while attempts < [1]:
    try:
        result = [2]()
        break
    except Exception as e:
        logging.error(str(e))
        attempts [3] 1
else:
    result = fallback()
Drag options to blanks, or click blank then click option'
A1
B2
C+=
Dmain_task
Attempts:
3 left
💡 Hint
Common Mistakes
Setting retry count to 1 causing only one attempt.
Not logging errors properly.
Using wrong operator to update attempts.