Repository: UKGovernmentBEIS/inspect_ai
Issue: `TypeError: AsyncAPIClient.request() got an unexpected keyword argument 'remaining_retries'` with agent bridge
Root cause: External Dependency Breakage

Hi,

When running the attached reproduction, I am receiving a `TypeError: AsyncAPIClient.request() got an unexpected keyword argument 'remaining_retries'`.

What is puzzling to me is that

- The [code](https://github.com/UKGovernmentBEIS/inspect_ai/blame/c76d1af255bafe4fbe77babf9a51c717f1266e57/src/inspect_ai/agent/_bridge/patch.py#L85) in inspect-ai is four months old.
- The [code](https://github.com/openai/openai-python/blame/01a69ab8cbed129e9edb84865893310ab52e59c7/src/openai/_base_client.py#L1441) in openai-python is two years old.

Removing the function parameter and adding a piece before, helps in my case

```python
...

                if re.match(r"^inspect/?", model_name):
                    return await inspect_model_request(model_name, options)

            if remaining_retries:
                options.max_retries = remaining_retries

            # otherwise just delegate
            return await original_request(
                self,
                cast_to,
                options,
                stream=stream,
                stream_cls=stream_cls,
            )
...
```


<details><summary>Traceback</summary>

```console
❯ pixi run inspect eval repro.py
╭─ hello (1 sample): openai/azure/<deployment-name> ──────────────────────────────────────────────────────────────────────────────────────╮
│ ╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/_eval/task/run.py:309 in   │                                                 │
│ │ task_run                                                                                                             │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/_util/_async.py:72 in      │                                                 │
│ │ tg_collect                                                                                                           │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/_util/_async.py:60 in      │                                                 │
│ │ run_task                                                                                                             │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/_eval/task/run.py:884 in   │                                                 │
│ │ task_run_sample                                                                                                      │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/_eval/task/run.py:675 in   │                                                 │
│ │ task_run_sample                                                                                                      │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/solver/_plan.py:106 in     │                                                 │
│ │ __call__                                                                                                             │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/agent/_as_solver.py:66 in  │                                                 │
│ │ solve                                                                                                                │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/agent/_bridge/bridge.py:69 │                                                 │
│ │ in execute                                                                                                           │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/repro.py:24 in run                                                                    │                                                 │
│ │                                                                                                                      │                                                 │
│ │   21 def my_agent():                                                                                                 │                                                 │
│ │   22 │   async def run(sample: dict[str, Any]) -> dict[str, Any]:                                                    │                                                 │
│ │   23 │   │   client = AsyncAzureOpenAI()                                                                             │                                                 │
│ │ ❱ 24 │   │   completion = await client.chat.completions.create(                                                      │                                                 │
│ │   25 │   │   │   model="openai/azure/<deployment-name>",                                  │                                                 │
│ │   26 │   │   │   messages=sample["input"],                                                                           │                                                 │
│ │   27 │   │   )                                                                                                       │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/openai/resources/chat/completions/co… │                                                 │
│ │ in create                                                                                                            │                                                 │
│ │                                                                                                                      │                                                 │
│ │   2025 │   │   timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,                                         │                                                 │
│ │   2026 │   ) -> ChatCompletion | AsyncStream[ChatCompletionChunk]:                                                   │                                                 │
│ │   2027 │   │   validate_response_format(response_format)                                                             │                                                 │
│ │ ❱ 2028 │   │   return await self._post(                                                                              │                                                 │
│ │   2029 │   │   │   "/chat/completions",                                                                              │                                                 │
│ │   2030 │   │   │   body=await async_maybe_transform(                                                                 │                                                 │
│ │   2031 │   │   │   │   {                                                                                             │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/openai/_base_client.py:1742 in post   │                                                 │
│ │                                                                                                                      │                                                 │
│ │   1739 │   │   opts = FinalRequestOptions.construct(                                                                 │                                                 │
│ │   1740 │   │   │   method="post", url=path, json_data=body, files=await async_to_httpx_files(fi                      │                                                 │
│ │   1741 │   │   )                                                                                                     │                                                 │
│ │ ❱ 1742 │   │   return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)                        │                                                 │
│ │   1743 │                                                                                                             │                                                 │
│ │   1744 │   async def patch(                                                                                          │                                                 │
│ │   1745 │   │   self,                                                                                                 │                                                 │
│ │                                                                                                                      │                                                 │
│ │ /Users/repo/.pixi/envs/default/lib/python3.12/site-packages/inspect_ai/agent/_bridge/patch.py:85  │                                                 │
│ │ in patched_request                                                                                                   │                                                 │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                 │
│ TypeError: AsyncAPIClient.request() got an unexpected keyword argument 'remaining_retries'                                                                               │
│                                                                                                                                                                          │
│ Task interrupted (no samples completed before interruption)                                                                                                              │
│                                                                                                                                                                          │
│ Log: logs/2025-05-09T09-28-35+02-00_hello_k4nvD4EXyykusUZnh2XQCY.eval                                                                                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

</details>



<details><summary>Code</summary>

```python
from typing import Any
import dotenv
from openai import AsyncAzureOpenAI
from inspect_ai import Task, task
from inspect_ai.agent import bridge
from inspect_ai.dataset import Sample
from inspect_ai.scorer import includes

dotenv.load_dotenv()


@task
def hello():
    return Task(
        dataset=[Sample(input="Please print the word 'hello'?", target="hello")],
        solver=bridge(my_agent()),
        scorer=includes(),
    )


def my_agent():
    async def run(sample: dict[str, Any]) -> dict[str, Any]:
        client = AsyncAzureOpenAI()
        completion = await client.chat.completions.create(
            model="openai/azure/cognitive_deployment_openAI_gpt4-eu-internal",
            messages=sample["input"],
        )
        return {"output": completion.choices[0].message.content}

    return run
```

</details>

It looks like 1.78.0 changed the signature. Fixed here: https://github.com/UKGovernmentBEIS/inspect_ai/pull/1841

Will likely ship to PyPI later on today.