Fix the API grounding check for agent code
Your task
An agent writing code against a third-party SDK keeps calling methods that do not exist. Each "fix" invents another plausible name. Instead of a third prompt, you check its calls against the SDK's real method list, taken from the type definitions.
An assistant wrote ground_calls_against_api(api_methods, called_methods). It is in the editor. It has a bug. Find it and fix it.
Input and output:
api_methods: the real methods of the SDK client.called_methods: the methods the agent's code calls, in call order.- Return one
call=methodorcall=missingstring per call that is not grounded, in first call order.
Rules the tests check:
- Trim whitespace from both ends of every name. Ignore names that are then empty. Handle each called name once, at its first call.
- A call is grounded only when it equals a real method exactly, case included. Report nothing for it.
- The shape of a name is the name with every
_and-removed and the letters A to Z turned into lowercase. Nothing else changes. - A call that is not grounded but has the same shape as a real method, like
sendMessageforsend_message, is reported ascall=method. If several real methods have that shape, use the smallest name, compared as plain strings. - Any other call is reported as
call=missing.
Examples
ground_calls_against_api(api_methods: list[str], called_methods: list[str]) -> list[str]Example 1
Input
ground_calls_against_api(["send_message", "list_channels", "close"], ["sendMessage", "close", "fetchHistory"])Output
["sendMessage=send_message", "fetchHistory=missing"]Example 2
Input
ground_calls_against_api(["connect", "disconnect"], ["connect", "disconnect"])Output
[]Example 3
Input
ground_calls_against_api([], ["anything"])Output
["anything=missing"]