Skip to content

Add extra_headers support - #4

Open
tembo[bot] wants to merge 7 commits into
mainfrom
tembo/feat/extra-headers-update-tests
Open

Add extra_headers support#4
tembo[bot] wants to merge 7 commits into
mainfrom
tembo/feat/extra-headers-update-tests

Conversation

@tembo

@tembo tembo Bot commented Apr 13, 2026

Copy link
Copy Markdown

What does this PR do?

Adds comprehensive support for custom HTTP headers (extra_headers) across the hermes-agent codebase. This enables custom providers to include additional authentication headers or routing information with API requests.

Related Issue

Follows up on PR NousResearch#3526 feedback to merge latest changes and add test coverage.

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)
  • ✅ Tests (adding or improving test coverage)

Changes Made

Core Implementation

  • run_agent.py: Added extra_headers parameter to AIAgent.__init__() with proper documentation. Implemented logic to merge custom headers with existing default_headers for custom providers.
  • cli.py: Added extra_headers attribute to HermesCLI and propagated it through runtime configuration in _resolve_turn_agent_config() and _resolve_agent_config().
  • hermes_cli/runtime_provider.py: Enhanced _get_named_custom_provider() to parse and validate extra_headers from config (dict type only). Updated _resolve_named_custom_runtime() to include extra_headers in resolved runtime.
  • agent/smart_model_routing.py: Added extra_headers propagation in resolve_turn_route() for both primary fallback and routed runtime scenarios.
  • gateway/run.py: Added extra_headers to _resolve_runtime_agent_kwargs() and GatewayRunner runtime configuration.

Test Coverage

  • tests/test_run_agent.py: Added TestExtraHeaders class with 7 comprehensive tests covering:

    • Storage of extra_headers on agent instance
    • Proper application to OpenAI client for custom providers
    • Non-application for non-custom providers
    • Merging with existing default headers
    • Handling of None/empty values
  • tests/agent/test_smart_model_routing.py: Added 3 tests for smart routing:

    • Preservation of extra_headers from primary runtime
    • Exclusion from signature tuple
    • Inclusion from routed runtime
  • tests/test_runtime_provider_resolution.py: Added 8 tests for provider resolution:

    • Named custom provider with valid extra_headers
    • Type validation (dict-only)
    • Empty dict and non-dict handling
    • Gateway integration tests
  • tests/test_cli_provider_resolution.py: Updated existing tests to initialize extra_headers = None.

How to Test

  1. Run all tests: pytest tests/ -q
  2. Verify custom provider with headers: Configure a custom provider in cli-config.yaml with extra_headers dict
  3. Test smart routing: Verify headers are preserved when routing to different models
  4. Test gateway: Verify headers are passed through gateway runtime resolution

Checklist

Code

  • My commit messages follow Conventional Commits
  • I've run pytest tests/ -q and all tests pass
  • I've added comprehensive tests for the changes
  • Changes are focused on extra_headers feature only

Documentation & Housekeeping

  • Updated docstrings in AIAgent.__init__() with extra_headers parameter documentation
  • Changes are backward compatible (extra_headers defaults to None)
  • Cross-platform compatible (no platform-specific code)

Want tembo to make any changes? Add a review or comment with @tembo and i'll get back to work!

View on Tembo View Agent Settings

jneeee and others added 7 commits March 28, 2026 09:57
…rn_agent_config

The TUI side correctly passed extra_headers through the runtime kwargs
to resolve_turn_route, but the Gateway's _resolve_turn_agent_config was
missing it in the primary dict, causing custom provider headers (like
x-host-head) to not be applied for Gateway requests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Test that named custom providers with extra_headers are resolved correctly
- Test that empty extra_headers dict is ignored
- Test that non-dict extra_headers is ignored
- Test that _resolve_named_custom_runtime includes extra_headers
- Test that resolve_turn_route preserves extra_headers from primary runtime
- Test that resolve_turn_route uses routed runtime's extra_headers when routing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The _resolve_named_custom_runtime always includes extra_headers key
in its return dict (with None value when not configured), but the
tests were asserting the key should be absent. Also add missing
extra_headers attribute to CLI test fixtures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tembo tembo Bot added the tembo Pull request created by Tembo label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tembo Pull request created by Tembo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant