Skip to content

Commit 8e2ecc5

Browse files
authored
Answer on a plain OpenAI key from the Microsoft Agent Framework Bot (#660)
Compose writes OPENAI_BASE_URL empty when the model screen chose a plain OpenAI key, and the OpenAI SDK only defaults an absent URL, so the Bot's client was given "" as its address and every run failed with "Connection error.". It now falls back to https://api.openai.com/v1 for an empty value, as its Anthropic branch already does for ANTHROPIC_BASE_URL.
1 parent b4db0f3 commit 8e2ecc5

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ now read, each on its own labelled line. The URI leads and the name and descript
9090
a long name cannot push the pointer past the result cap; a server's `title` is shown over its `name`
9191
when it gives one. A part that already carried text is unchanged.
9292

93+
### The Microsoft Agent Framework Bot answers on a plain OpenAI key
94+
95+
Picked with an OpenAI key, the Microsoft Agent Framework Bot failed every run with "Connection
96+
error.". Compose writes `OPENAI_BASE_URL` empty when the choice is a plain OpenAI key, and the
97+
OpenAI SDK only defaults an absent URL, so it was given "" as the address. The Bot now falls back to
98+
`https://api.openai.com/v1` for an empty value, as its Anthropic branch already did for
99+
`ANTHROPIC_BASE_URL`. An OpenAI-compatible endpoint is unchanged.
100+
93101
### Skill selection keeps capabilities named across multiple JSON replies
94102

95103
When a model wraps its skill choice in prose or sends a revised JSON object, OpenBot reads each

‎agent-microsoft/src/main.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def _client() -> AnthropicClient | OpenAIChatClient:
2323
# Compose exports missing overrides as ""; the SDK only defaults an absent URL.
2424
base_url = (os.environ.get("ANTHROPIC_BASE_URL") or "").strip() or "https://api.anthropic.com"
2525
return AnthropicClient(model=model, base_url=base_url)
26-
return OpenAIChatClient(model)
26+
# The same "" for OPENAI_BASE_URL, which Compose writes whenever the model screen chose a plain
27+
# OpenAI key. The SDK only defaults an absent URL; given "", every request fails to connect.
28+
base_url = (os.environ.get("OPENAI_BASE_URL") or "").strip() or "https://api.openai.com/v1"
29+
return OpenAIChatClient(model, base_url=base_url)
2730

2831

2932
agent = _client().as_agent(

‎agent-microsoft/tests/test_main.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88

99
import httpx
10+
import httpx2
1011
import pytest
1112
import uvicorn
1213
from fastapi import FastAPI, Request
@@ -217,3 +218,43 @@ async def respond(transport, request):
217218
assert '"RUN_FINISHED"' in response.text
218219
assert '"RUN_ERROR"' not in response.text
219220
assert "hello" in response.text
221+
222+
223+
def test_an_openai_key_uses_the_official_endpoint_when_compose_sets_a_blank_url(monkeypatch):
224+
# The same "" Compose writes for ANTHROPIC_BASE_URL above, on the other provider: the model screen
225+
# sets only the key for a plain OpenAI key, and the SDK treats "" as an address, not as absent.
226+
seen = []
227+
provider_seen = []
228+
provider_app = _provider_app(provider_seen)
229+
230+
async def respond(transport, request):
231+
seen.append(
232+
(request.url.scheme, request.url.host, request.url.path, request.headers.get("authorization"))
233+
)
234+
async with httpx2.ASGITransport(app=provider_app) as local_provider:
235+
return await local_provider.handle_async_request(request)
236+
237+
# Keep the real framework and OpenAI clients; replace only the network transport. The OpenAI SDK
238+
# sends through httpx2, not httpx, so patching httpx's transport here would let the request out.
239+
monkeypatch.setattr(httpx2.AsyncHTTPTransport, "handle_async_request", respond)
240+
monkeypatch.setenv("MANAGED_AGENT_TOKEN", TOKEN)
241+
monkeypatch.setenv("BOT_PROVIDER", "openai")
242+
monkeypatch.setenv("BOT_MODEL", "gpt-5.5")
243+
monkeypatch.setenv("OPENAI_API_KEY", "test-key")
244+
monkeypatch.setenv("OPENAI_BASE_URL", "")
245+
monkeypatch.setenv("ANTHROPIC_API_KEY", "")
246+
monkeypatch.setenv("ANTHROPIC_BASE_URL", "")
247+
248+
from src import main
249+
250+
main = importlib.reload(main)
251+
response = TestClient(main.app).post(
252+
"/", json=RUN, headers={"x-openbot-agent-token": TOKEN}
253+
)
254+
255+
assert seen == [("https", "api.openai.com", "/v1/responses", "Bearer test-key")]
256+
assert provider_seen == [("openai", "gpt-5.5")]
257+
assert response.status_code == 200
258+
assert '"RUN_FINISHED"' in response.text
259+
assert '"RUN_ERROR"' not in response.text
260+
assert "hello" in response.text

0 commit comments

Comments
 (0)