Bird
Raised Fist0
Agentic AIml~20 mins

Async agent execution in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Async Agent Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Async Agent Execution Basics

Which statement best describes the main advantage of using asynchronous execution in AI agents?

AIt allows the agent to perform multiple tasks at the same time without waiting for each to finish.
BIt guarantees that tasks are executed in a strict order, one after another.
CIt reduces the agent's memory usage by storing fewer task details.
DIt makes the agent run slower but more accurately.
Attempts:
2 left
💡 Hint

Think about how multitasking works in everyday life, like cooking while listening to music.

Predict Output
intermediate
2:00remaining
Output of Async Agent Task Scheduling

What will be the output of the following async agent code snippet?

Agentic AI
import asyncio

async def task(name, delay):
    await asyncio.sleep(delay)
    return f'Task {name} done'

async def main():
    results = await asyncio.gather(
        task('A', 1),
        task('B', 0.5),
        task('C', 0.2)
    )
    print(results)

asyncio.run(main())
A['Task A done', 'Task C done', 'Task B done']
B['Task C done', 'Task B done', 'Task A done']
C['Task A done', 'Task B done', 'Task C done']
D['Task B done', 'Task A done', 'Task C done']
Attempts:
2 left
💡 Hint

Consider how asyncio.gather returns results in the order of the tasks passed, not completion order.

Model Choice
advanced
2:00remaining
Choosing the Best Model for Async Agent Execution

Which model architecture is best suited for an AI agent that requires efficient asynchronous task handling and context switching?

ARecurrent Neural Network (RNN) with sequential processing
BTransformer model with self-attention mechanisms
CFeedforward Neural Network with fixed input size
DConvolutional Neural Network (CNN) for image tasks
Attempts:
2 left
💡 Hint

Think about models that handle sequences flexibly and can focus on different parts of input simultaneously.

Hyperparameter
advanced
2:00remaining
Hyperparameter Impact on Async Agent Performance

Which hyperparameter adjustment is most likely to improve an async agent's responsiveness when handling many simultaneous tasks?

AIncreasing the number of parallel worker threads
BReducing the learning rate drastically
CDecreasing the number of training epochs
DIncreasing batch size during training
Attempts:
2 left
💡 Hint

Consider what helps an agent handle more tasks at the same time without delay.

🔧 Debug
expert
3:00remaining
Debugging Async Agent Deadlock

Given this async agent code, what is the cause of the deadlock preventing task completion?

Agentic AI
import asyncio

async def task1():
    await task2()
    return 'Task1 done'

async def task2():
    await task1()
    return 'Task2 done'

async def main():
    result = await asyncio.gather(task1(), task2())
    print(result)

asyncio.run(main())
AThe tasks return strings instead of coroutine objects.
BThe tasks are missing await keywords causing syntax errors.
CThe asyncio.gather call is missing a timeout parameter.
DThe tasks call each other recursively causing infinite waiting.
Attempts:
2 left
💡 Hint

Look for circular calls between async functions.

Practice

(1/5)
1. What is the main benefit of using async agent execution in AI systems?
easy
A. It makes the agents run slower but more accurately.
B. It allows multiple agents to run at the same time, speeding up processing.
C. It forces agents to run one after another in a fixed order.
D. It disables agents from communicating with each other.

Solution

  1. Step 1: Understand async execution

    Async execution means running tasks without waiting for each to finish before starting the next.
  2. Step 2: Apply to AI agents

    Running multiple AI agents at the same time speeds up overall processing by avoiding delays.
  3. Final Answer:

    It allows multiple agents to run at the same time, speeding up processing. -> Option B
  4. Quick Check:

    Async = concurrent execution = speed up [OK]
Hint: Async means agents run together, not one by one [OK]
Common Mistakes:
  • Thinking async slows down agents
  • Believing async forces sequential runs
  • Confusing async with disabling communication
2. Which of the following is the correct syntax to run multiple async agents together in Python?
easy
A. await agent1() and agent2()
B. asyncio.run(agent1(), agent2())
C. await asyncio.gather(agent1(), agent2())
D. async gather(agent1, agent2)

Solution

  1. Step 1: Recall asyncio syntax

    To run multiple async functions concurrently, use await asyncio.gather(...).
  2. Step 2: Check options

    await asyncio.gather(agent1(), agent2()) uses correct syntax with await asyncio.gather(agent1(), agent2()). Others are invalid or incorrect.
  3. Final Answer:

    await asyncio.gather(agent1(), agent2()) -> Option C
  4. Quick Check:

    asyncio.gather + await = correct syntax [OK]
Hint: Use await with asyncio.gather to run agents together [OK]
Common Mistakes:
  • Using asyncio.run with multiple args
  • Missing await before asyncio.gather
  • Wrong function call syntax without parentheses
3. Given the code below, what will be the output?
import asyncio

async def agent1():
    await asyncio.sleep(1)
    return 'Agent1 done'

async def agent2():
    await asyncio.sleep(2)
    return 'Agent2 done'

async def main():
    results = await asyncio.gather(agent1(), agent2())
    print(results)

asyncio.run(main())
medium
A. ['Agent1 done', 'Agent2 done'] after about 2 seconds
B. ['Agent2 done', 'Agent1 done'] after about 2 seconds
C. ['Agent1 done', 'Agent2 done'] after about 3 seconds
D. Error because agent2 takes longer

Solution

  1. Step 1: Understand asyncio.gather timing

    asyncio.gather runs tasks concurrently, so total time is max of individual times.
  2. Step 2: Analyze sleep durations

    agent1 sleeps 1s, agent2 sleeps 2s, so total time ~2 seconds, results in order of calls.
  3. Final Answer:

    ['Agent1 done', 'Agent2 done'] after about 2 seconds -> Option A
  4. Quick Check:

    Concurrent run time = max sleep = 2s [OK]
Hint: Total time = longest agent sleep with asyncio.gather [OK]
Common Mistakes:
  • Adding sleep times instead of taking max
  • Assuming output order changes by sleep time
  • Expecting error due to different sleep durations
4. What is wrong with this async agent execution code?
import asyncio

async def agent():
    return 'done'

async def main():
    results = asyncio.gather(agent(), agent())
    print(results)

asyncio.run(main())
medium
A. Missing await before asyncio.gather, so results is a coroutine, not actual results.
B. agent() is not async, so cannot be awaited.
C. asyncio.run cannot be used with async functions.
D. print cannot be used inside async functions.

Solution

  1. Step 1: Check asyncio.gather usage

    asyncio.gather returns a coroutine; it must be awaited to get results.
  2. Step 2: Identify missing await

    Code misses await before asyncio.gather, so print shows coroutine object, not results.
  3. Final Answer:

    Missing await before asyncio.gather, so results is a coroutine, not actual results. -> Option A
  4. Quick Check:

    Always await asyncio.gather to get results [OK]
Hint: Always put await before asyncio.gather to get results [OK]
Common Mistakes:
  • Forgetting await before asyncio.gather
  • Thinking print can't be used in async
  • Misunderstanding asyncio.run usage
5. You want to run three async agents where agent3 depends on the results of agent1 and agent2. Which approach correctly handles this dependency using async agent execution?
hard
A. Run all three agents sequentially without async to ensure order.
B. Run agent3 concurrently with agent1 and agent2 using asyncio.gather without waiting.
C. Run agent3 first, then run agent1 and agent2 concurrently after.
D. Run agent1 and agent2 concurrently with asyncio.gather, await their results, then run agent3 with those results.

Solution

  1. Step 1: Identify dependency order

    agent3 needs results from agent1 and agent2, so it must run after they finish.
  2. Step 2: Use asyncio.gather for parallelism

    Run agent1 and agent2 concurrently with asyncio.gather, await results, then pass to agent3.
  3. Final Answer:

    Run agent1 and agent2 concurrently with asyncio.gather, await their results, then run agent3 with those results. -> Option D
  4. Quick Check:

    Run dependencies first, then dependent agent [OK]
Hint: Await dependencies before running dependent agent [OK]
Common Mistakes:
  • Running dependent agent before dependencies finish
  • Running all agents concurrently ignoring dependencies
  • Running sequentially losing async speed benefits