learning-it by example

#22 AI agents and MCP 6.7 min

OpenAI Agents SDK vs LangGraph vs Plain Python

One tool kept failing. One agent loop stopped at 6 calls, one at 10, and one kept going.

1. What loop do plain Python, the OpenAI Agents SDK and LangGraph all run in the refund agent comparison?
2. In the refund agent comparison, when the order tool failed 60 times in a row, how many model calls did the LangGraph version make before it finished?
3. In the refund agent comparison, which limit stopped each version when the tool stayed down: plain Python, the Agents SDK and LangGraph?
4. Why does the refund agent written with the OpenAI Agents SDK turn tracing off?
5. What does the comparison of the three agent loops not show, since a scripted stand-in plays the model?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Watch the order tool fail

    Copy the code folder first. In a Python prompt in that folder, import tools, call tools.reset(2), then call tools.lookup_order(7) three times, catching the error each time. Predict which calls fail before you run. When we ran it, the first two raised TimeoutError with the message order service timed out and the third returned {'total': 40}.

    A hint

    reset(2) tells the tool to fail the next 2 calls.

  2. Show why a retry needs a guard

    In a Python prompt, call tools.reset(0), then tools.refund(7, 40) twice, and print tools.REFUNDS. Then add a check at the top of refund in tools.py that returns a message and does not append again if a refund for that order id was already made. Run the same two calls again. Without your check we saw [40, 40], and with a working check you should see [40]. When you have seen both outputs, take your check out of tools.py again, or compare.py will show wrong refunds in the next tasks.

    A hint

    Keep a second list or dictionary of order ids that have been refunded.

  3. Predict the calls when the tool fails 3 times

    In compare.py the second attempt uses 60 failures. Predict, before you change anything, how many model calls each version makes if the tool fails 3 times then recovers, and whether plain Python still finishes inside its limit of 6. Then change 60 to 3 and run python compare.py with the packages from the video installed. Compare with your prediction. The printed label still says tool down 60 calls, but the tool now fails 3 times.

    A hint

    Count each failed lookup, then the good lookup, the refund and the final answer. This is a prediction task because we could not run the three frameworks here.

  4. Find the limit that stops plain Python

    In compare.py set the second attempt to 4 failures. Predict whether plain Python with its limit of 6 stops, whether the Agents SDK with its default of 10 stops, and what LangGraph does. Then change max_turns in plain.py from 6 to 8 and predict whether the plain Python result changes. Run python compare.py to check, with the video's packages installed. The printed label still says tool down 60 calls, but the tool now fails 4 times.

    A hint

    With 4 failures the model needs 7 calls in total. This is a prediction task because we could not run the three frameworks here.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

A scripted stand-in plays the model and retries a failed tool every time, so this compares code length and default limits only, not how a real model behaves. One small task with two tools. The limit of six in plain Python is the author's choice; the other two are the defaults of openai-agents 0.24.0 and langgraph 1.2.16, and all three limits can be changed. Lines of code are not features.

Up next in AI agents and MCP

More in AI agents and MCP

All AI agents and MCP videos

Related videos