learning-it by example

#240 Enterprise architecture and AI agents 5.8 min

Wrap Legacy APIs for AI Agents: OpenAPI to Checked Tools

Seven operations in the old API, four tools for the agent, and only two of six test calls got through.

1. Why can the OpenAPI description of an existing API be used to generate tools for an AI agent?
2. In the legacy shop example, how many operations did the API have, how many tools did the agent get, and how many of the 6 test calls reached the legacy API?
3. Why was the deleteCustomer call in the legacy API example answered with no such tool?
4. What does the converter check about a tool call before any request is made to the legacy API?
5. Why must the old system still enforce its own rules even after the wrapper checks the arguments?

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

  1. Count the operations and tools

    Copy the code folder first. Run python compare.py and read the first line. Then open spec.py and list the seven operation ids. Write down which three operations are not on the SAFE list in compare.py and why an agent should not have them.

    A hint

    The three that are left out are in the description as delete, export and health.

  2. Change the maximum

    In spec.py, change "maximum": 100 to "maximum": 1000 in the refund operation. Predict what happens to the refund of 500, then run python compare.py. When I ran it the refund of 500 was sent and the last line said 3 of 6 calls reached the legacy API. Then change 1000 back to 100 before the next task.

    A hint

    The amount is checked against the maximum in the schema.

  3. Add one more allowed operation

    In compare.py, add "deleteCustomer" to the SAFE set. Predict the first line and the last line of the output, then run python compare.py. The legacy API here is only a function that records the request, so nothing real is deleted. When I ran it the agent was given 5 tools and 3 of 6 calls reached the legacy API. Then remove deleteCustomer from the SAFE set again before the next task.

    A hint

    Adding one name to the allow list is all it takes to make a tool, which is why the list needs care.

  4. Try a negative refund

    In compare.py, add a seventh call to the CALLS list: ("refundOrder", {"id": 7, "amount": -5}). Predict whether it is stopped, then run python compare.py. When I ran it the call was sent and the last line said 3 of 7 calls reached the legacy API. Write one sentence on which check you would add.

    A hint

    The schema only has a maximum, so a negative number passes.

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

What this does not show

A made-up API with seven operations and six hand-written calls; no model or agent runs. The checks cover missing, unknown, wrong type and one maximum, so a negative refund still passes. No nested bodies, headers, authentication, user identity or approval step.

Up next in Enterprise architecture and AI agents

More in Enterprise architecture and AI agents

All Enterprise architecture and AI agents videos

Related videos