Skip to content

fix(captainagent): drop top_p from default LLM config to avoid temperature/top_p conflict#2881

Closed
obchain wants to merge 2 commits into
ag2ai:mainfrom
obchain:fix/issue-2102
Closed

fix(captainagent): drop top_p from default LLM config to avoid temperature/top_p conflict#2881
obchain wants to merge 2 commits into
ag2ai:mainfrom
obchain:fix/issue-2102

Conversation

@obchain
Copy link
Copy Markdown
Contributor

@obchain obchain commented May 18, 2026

Summary

  • CaptainAgent.DEFAULT_NESTED_CONFIG set both temperature and top_p in the built-in default_llm_config. Providers like Anthropic reject requests that set both, which broke out-of-the-box CaptainAgent runs the moment the agent tried to spin up its expert group — even when the user had not configured either parameter.
  • Drop top_p from the default. Users that want it can still set it explicitly via nested_config.
  • Adds a regression test pinning the invariant.

Fixes #2102

Test plan

  • uv run --extra test pytest test/agentchat/contrib/test_captainagent.py::test_default_nested_config_does_not_set_temperature_and_top_p_together — passed

…mperature/top_p conflict

``CaptainAgent.DEFAULT_NESTED_CONFIG`` hard-coded
``default_llm_config = {"temperature": 1, "top_p": 0.95, "max_tokens": 2048}``.

Many providers (notably Anthropic) reject requests that set both
``temperature`` and ``top_p`` simultaneously, which surfaced as

    ValidationError: temperature and top_p cannot be set at the same time

on the very first invocation, even when the user had not configured either
parameter on their own ``llm_config``. The defaults made the demo
unusable on those providers.

OpenAI guidance is to set only one of the two sampling parameters; keep
``temperature`` (it is the more widely supported default) and drop
``top_p`` from the built-in config. Users that want ``top_p`` can still
opt in by overriding ``default_llm_config`` in their ``nested_config``.

Adds a regression test that pins this invariant on
``DEFAULT_NESTED_CONFIG``.

Fixes ag2ai#2102
@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 49 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marklysze
Copy link
Copy Markdown
Collaborator

Thanks @obchain for digging into this and putting together a well-tested change.

Things have shifted since #2102 was originally filed: the error in that issue (temperature and top_p cannot be set at the same time) was raised by validators on ApplicationConfig, and those were removed back in #2054 ("fix: remove temperature & top_p restriction"). On current main that error no longer occurs — and we also confirmed against the live Anthropic API that requests setting both temperature and top_p are accepted rather than rejected — so the underlying problem from #2102 is already resolved upstream and there's no longer a bug for this change to fix.

So, we won't merge this specific fix, but thanks again for taking the time to work on it.

@marklysze marklysze closed this May 27, 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.

In the CaptainAgent demo, temperature and top_p are set simultaneously. Yet I didn’t specify these two parameters in my LLM configuration at all.

2 participants