Agent Foundry
All Problems

#70. Partial Failure Handler

MediumError Recovery

The Problem

Your morning briefing agent calls four tools: weather, news, stock prices, and calendar. If any one of them fails, the entire request crashes — the user gets nothing, even though three out of four tools worked perfectly. There is no isolation between tool calls, so a single failure in the stock service takes down the weather, news, and calendar results too. Your job is to handle partial failures gracefully: return what succeeded and clearly note what failed.

Examples

Example 1

User input: Give me my morning briefing for today

Current (bad) output: ConnectionError: Stock service unavailable — the entire briefing crashes. Weather, news, and calendar results are lost.

Expected (good) output:

Morning Briefing:
- Weather: 72°F, sunny
- News: AI advances continue
- Stocks: ⚠️ Unavailable (stock service is currently down)
- Calendar: Team standup at 9am

Example 2

User input: What's happening today?

Current (bad) output: Unhandled exception — no output at all.

Expected (good) output: The agent returns the 3 successful results and includes a note that the stock data could not be fetched.

Your Task

Add partial failure handling so the agent:

  • Isolates each tool call so one failure doesn't crash the others.
  • Returns results from all tools that succeeded.
  • Clearly notes which tool(s) failed in the final output.
  • Never crashes entirely due to a single tool failure.

Evaluation

Submissions are checked for the following:

  • Successful results are returned: Data from working tools is included in the response.
  • Failed tool is noted: The output states which tool failed and that its data is unavailable.
  • No total crash on partial failure: A single tool failure does not abort the entire request.

Constraints

  • If one tool fails, the agent must still return results from the tools that succeeded
  • The response must clearly note which tool failed and why
  • The agent must not crash or abort entirely due to a single tool failure
  • Failed tools must not be silently ignored — the failure must be reported
Starter Code
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get current weather for a city."""
    return f"Weather in {city}: 72°F, sunny"

@tool
def get_news(topic: str) -> str:
    """Get latest news on a topic."""
    return f"Latest news on {topic}: [headlines]"

@tool
def get_stock_price(ticker: str) -> str:
    """Get current stock price."""
    # BUG: This tool always fails and takes down the entire request
    raise ConnectionError("Stock service unavailable")

@tool
def get_calendar(date: str) -> str:
    """Get calendar events for a date."""
    return f"Events for {date}: Team standup at 9am"

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

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a daily briefing assistant. Gather weather, news, stocks, and calendar info."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

tools = [get_weather, get_news, get_stock_price, get_calendar]
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

# Test: One tool failure crashes the entire briefing
result = executor.invoke({"input": "Give me my morning briefing for today"})
print(result["output"])
Open in Google Colab
Evaluation Criteria0/3