Skip to content

fix(delegate): sync self.base_url with client_kwargs after credential resolution - #6933

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/delegation-base-url-overwrite
Closed

fix(delegate): sync self.base_url with client_kwargs after credential resolution#6933
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/delegation-base-url-overwrite

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

Summary

Fixes #6825

When delegation.base_url routes subagents to a different endpoint, the correct URL is passed through _resolve_delegation_credentials() and _build_child_agent() into AIAgent.__init__(), but self.base_url can fall out of sync with client_kwargs["base_url"] — the value the OpenAI client actually uses.

This causes billing_base_url in session records to show the parent's endpoint while actual API calls go to the correct delegation target.

Root cause

At run_agent.py:852, self.api_key is synced from client_kwargs after credential resolution, but self.base_url (set earlier at line 584) is never updated to match. When the else branch at line 797 resolves credentials via resolve_provider_client(), the resolved base_url goes into client_kwargs but self.base_url stays stale.

Fix

One-line addition after line 852 — self.base_url = client_kwargs.get("base_url", self.base_url) — mirrors the existing self.api_key sync pattern. This also ensures the _primary_runtime snapshot (line 1241) captures the correct base_url for fallback recovery.

Test plan

  • Existing delegation test suite passes (104 tests in test_delegate.py, test_delegate_toolset_scope.py, test_agent_loop.py)
  • Verify with local dual-endpoint setup: parent on :8001, delegation target on :8000 — child session billing_base_url should show :8000

Platform

Tested on macOS (Darwin 24.6.0), Python 3.14.2

… resolution

When delegation.base_url routes subagents to a different endpoint, the
correct URL was passed through _resolve_delegation_credentials() and
_build_child_agent() into AIAgent.__init__(), but self.base_url could
fall out of sync with client_kwargs["base_url"] — the value the OpenAI
client actually uses.

This caused billing_base_url in session records to show the parent's
endpoint while actual API calls went to the correct delegation target.

Keep self.base_url in sync with client_kwargs after the credential
resolution block, matching the existing pattern for self.api_key.

Fixes NousResearch#6825
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7360. Cherry-picked with authorship preserved. Textbook one-liner — thanks!

@teknium1 teknium1 closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: delegation.base_url correctly resolved but overwritten before first API call

2 participants