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
Step 1: Check asyncio.gather usage
asyncio.gather returns a coroutine; it must be awaited to get results.
Step 2: Identify missing await
Code misses await before asyncio.gather, so print shows coroutine object, not results.
Final Answer:
Missing await before asyncio.gather, so results is a coroutine, not actual results. -> Option A
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
Step 1: Identify dependency order
agent3 needs results from agent1 and agent2, so it must run after they finish.
Step 2: Use asyncio.gather for parallelism
Run agent1 and agent2 concurrently with asyncio.gather, await results, then pass to agent3.
Final Answer:
Run agent1 and agent2 concurrently with asyncio.gather, await their results, then run agent3 with those results. -> Option D
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