Agent Foundry
All Problems

#21. Parallel Tool Execution

MediumTool CallingOrchestration

The Problem

Your weather assistant agent can fetch weather for any city using the get_weather tool. When a user asks for weather in three cities, the agent calls the tool sequentially — one city at a time — resulting in 3× the latency. Each lookup takes about 1 second, so three sequential calls take ~3 seconds. Your job is to make the agent execute all three weather lookups in parallel so the total time drops to roughly 1 second.

Examples

Example 1

User input: What's the weather in New York, London, and Tokyo?

Current (bad) output: The agent calls get_weather("New York"), waits for the result, then calls get_weather("London"), waits again, then get_weather("Tokyo"). Total time: ~3 seconds.

Expected (good) output: The agent issues all three get_weather calls simultaneously. All results arrive in ~1 second. The agent presents: New York: 72°F Sunny, London: 58°F Cloudy, Tokyo: 68°F Partly Cloudy.

Example 2

User input: Compare the weather in Paris, Berlin, and Madrid

Current (bad) output: Three sequential calls with cumulative latency. The user waits noticeably longer than necessary.

Expected (good) output: All three lookups happen in parallel. The agent responds quickly with a comparative summary.

Your Task

  • Modify the agent or orchestration to execute multiple get_weather calls in parallel.
  • Ensure the total wall-clock time is roughly the time of a single lookup, not the sum of all lookups.
  • The agent must still collect and present all results together in a coherent response.
  • Do not change the tool's internal implementation.

Evaluation

Submissions are checked for the following:

  • Weather lookups run in parallel: All three city lookups execute concurrently rather than sequentially.
  • Total time is roughly one lookup: The wall-clock time is approximately 1 second, not 3.
  • All city results are returned: The agent presents weather data for all requested cities in a single response.

Constraints

  • All three city weather lookups must execute in parallel, not sequentially
  • The total execution time must be roughly that of one lookup, not three
  • The agent must collect and present all results together
  • No changes to the weather tool's internal logic
Starter Code
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
from langgraph.prebuilt import create_react_agent
import time

llm = ChatOpenAI(model="gpt-4o-mini")

@tool
def get_weather(city: str) -> str:
    """Get current weather for a city."""
    time.sleep(1)  # Simulates API latency
    weather_data = {
        "new york": "72°F, Sunny",
        "london": "58°F, Cloudy",
        "tokyo": "68°F, Partly Cloudy",
    }
    return weather_data.get(city.lower(), f"Weather data not available for {city}")

# BUG: The agent calls get_weather sequentially for each city
# TODO: Build a LangGraph workflow that fans out weather lookups in parallel
agent = create_react_agent(llm, [get_weather])

start = time.time()
result = agent.invoke({"messages": [("human", "What's the weather in New York, London, and Tokyo?")]})
print(f"Time: {time.time() - start:.1f}s")
print(result["messages"][-1].content)
Open in Google Colab
Evaluation Criteria0/3