Bird
0
0

What will be printed when the following async agent code is executed?

medium📝 Predict Output Q4 of 15
Agentic AI - Production Agent Architecture
What will be printed when the following async agent code is executed?
import asyncio

async def agent():
    await asyncio.sleep(0.1)
    return 'finished'

result = asyncio.run(agent())
print(result)
ANone
B<coroutine object agent at some memory address>
C'finished'
DAn error is raised
Step-by-Step Solution
Solution:
  1. Step 1: Run async function with asyncio.run()

    This runs the event loop and waits for the coroutine to complete.
  2. Step 2: Await inside agent()

    The agent awaits asyncio.sleep(0.1), simulating async work.
  3. Step 3: Return value

    After awaiting, 'finished' is returned and assigned to result.
  4. Final Answer:

    'finished' -> Option C
  5. Quick Check:

    asyncio.run executes coroutine fully [OK]
Quick Trick: asyncio.run returns coroutine result, not coroutine object [OK]
Common Mistakes:
  • Expecting print to show coroutine object instead of result
  • Forgetting to use asyncio.run to execute coroutine
  • Assuming print outputs None without awaiting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes