fix(chat): forward extra_headers to all LLM calls in agentic pipeline#436
Merged
Conversation
The chat capability silently dropped `extra_headers` from the active
LLM profile because three downstream call sites in `AgenticChatPipeline`
did not forward them:
- `_build_openai_client()` constructed `AsyncOpenAI` /
`AsyncAzureOpenAI` without `default_headers`, so custom headers
required by some gateways (e.g. a `User-Agent` override to bypass
WAF allowlists that block `OpenAI/Python <ver>`) were lost on the
native-tool-calling path.
- `_stream_messages` and `_run_react_fallback` invoked `llm_stream()`
with `model`, `api_key`, `base_url`, `binding` but no
`extra_headers`. The factory's `_resolve_call_config` treats this
set of caller-provided fields as an explicit override and rebuilds
`LLMConfig` with empty `extra_headers`, bypassing the catalog value
loaded by `get_llm_config()`.
Pulls `extra_headers` from `llm_config` once in `__init__` and
forwards it from all three call sites.
Reproduce: configure an OpenAI-compatible gateway whose WAF rejects
the default `OpenAI/Python <ver>` User-Agent; set
`extra_headers: { "User-Agent": "Mozilla/5.0 ..." }` on the active
LLM profile in `model_catalog.json`. Before this change, chat returns
HTTP 403 "Your request was blocked." After, the override reaches the
gateway and chat succeeds.
Collaborator
|
Thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The chat capability silently dropped
extra_headersfrom the active LLM profile, because three downstream call sites inAgenticChatPipelinedid not forward them:_build_openai_client()constructedAsyncOpenAI/AsyncAzureOpenAIwithoutdefault_headers, so custom headers required by some gateways (e.g. aUser-Agentoverride to bypass WAF allowlists that blockOpenAI/Python <ver>) were lost on the native-tool-calling path._stream_messagesand_run_react_fallbackinvokedllm_stream()withmodel,api_key,base_url,bindingbut noextra_headers. The factory's_resolve_call_configtreats this set of caller-provided fields as an explicit override and rebuildsLLMConfigwith emptyextra_headers, bypassing the catalog value already loaded byget_llm_config().The fix pulls
extra_headersfromllm_configonce in__init__and forwards it from all three call sites.Reproduce
OpenAI/Python <ver>User-Agent (e.g. some commercial proxies front-running OpenAI).model_catalog.json, set:Before this PR — chat fails with:
After this PR — the override reaches the gateway and chat succeeds.
I verified the SDK behaviour with an isolated probe against the same gateway:
AsyncOpenAI(api_key, base_url)(no override)Your request was blocked.AsyncOpenAI(api_key, base_url, default_headers={'User-Agent': 'Mozilla/5.0 ...'})Test plan
extra_headersis empty dict, falls through asNone).Notes / not in this PR
While debugging I noticed two adjacent issues that I did not include here, to keep the diff minimal and reviewable:
factory._resolve_call_configcould fall back to the resolver-loadedextra_headerswhen the caller suppliesmodel + api_key + base_url + bindingwithoutextra_headers. Today this path silently substitutes{}, which is what made the chat-side bug fatal. Fixing it would prevent any future agent that forgets to forwardextra_headersfrom regressing the same way. Happy to send as a follow-up if reviewers prefer.statusis left atrunning. The next time the user opens that session,UnifiedChatContextreadsstatus === "running"→isStreaming = true→ the send button stays permanently disabled.New chatworks around it but the state never recovers. This deserves its own PR with proper error-path coverage.