Bird
0
0

What is wrong with this async agent execution code?

medium📝 Debug Q14 of 15
Agentic AI - Production Agent Architecture
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())
AMissing await before asyncio.gather, so results is a coroutine, not actual results.
Bagent() is not async, so cannot be awaited.
Casyncio.run cannot be used with async functions.
Dprint cannot be used inside async functions.
Step-by-Step Solution
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]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes