Skip to content

fix(ai): LLMClient.chat takes temperature, top_p and seed and sends none of them #2559

Closed

Description

@dan-petty

Problem Description

LLMClient.chat and chat_messages (src/devops_cli/ai/client/unified.py) take **kwargs and use none of them. A caller that passes temperature, top_p or seed gets no error, and the request carries the sampling of the client's config instead. The payload builders read self._config.temperature and self._config.top_p (ai/client/openai.py, ai/client/ollama.py), and the cache key reads the same config.

Review group analysis passes temperature, top_p and seed from its SamplingRecord on each call (src/devops_cli/review/analysis.py, _run_model_job), so it believes it sets them. Found while fixing #2447, which makes the record name the analysis task's configured sampling.

Reproduction Steps

  1. Build an LLMClient whose config has temperature: 0.1.
  2. Call client.chat("system", "user", temperature=0.9, seed=7) against a fake model at the HTTP edge.
  3. Read the request body.

Expected vs Actual Behavior

  • Expected: the request carries temperature 0.9 and seed 7, or the call refuses an argument it does not support.
  • Actual: the request carries temperature 0.1 and no seed, and no error is raised.

Environment Diagnostics

origin/main d156ce7 (2026-10-28).

Existing Tool Considered

The OpenAI-compatible API, Ollama and Anthropic take temperature, top_p and seed (Anthropic: no seed) per request. No new tool is needed: either pass them through to the payload and the cache key, or remove **kwargs so that an unknown argument is a TypeError.

Source: #2447

Proposed design

Problem statement

LLMClient.chat and chat_messages accept **kwargs but silently ignore temperature, top_p, and seed. A caller that passes these values, such as the review analysis module, believes it sets per-call sampling, but the request carries the client's config defaults instead. No error is raised, so the wrong sampling is used and the cache key does not reflect the intended values.

Acceptance criteria

Requirement: Per-call sampling in request payload

When a caller passes temperature, top_p, or seed to chat or chat_messages, the HTTP request body SHALL carry those values.

Scenario: Caller passes temperature=0.9 and seed=7

  • WHEN A caller invokes client.chat(system, user, temperature=0.9, seed=7) against a fake model at the HTTP edge
  • THEN The request body contains temperature 0.9 and seed 7

Requirement: Per-call sampling in cache key

The cache key generated for a chat call SHALL include the per-call temperature, top_p, and seed values when they are provided.

Scenario: Two calls differ only in temperature

  • WHEN A caller invokes chat with temperature=0.1 and then with temperature=0.9 for the same system and user text
  • THEN The two calls produce different cache keys

Requirement: Config default fallback

When a caller does not pass a sampling parameter, the request SHALL use the value from the client's config.

Scenario: Caller omits temperature

  • WHEN A caller invokes client.chat(system, user) with config temperature set to 0.1
  • THEN The request body contains temperature 0.1

Requirement: Unknown keyword argument rejected

A call to chat or chat_messages with a keyword argument that is not a recognized parameter SHALL raise TypeError.

Scenario: Caller passes an unrecognized keyword

  • WHEN A caller invokes client.chat(system, user, unknown_param=1)
  • THEN A TypeError is raised

Requirement: Seed omitted for unsupported providers

When the provider does not support seed, the request body SHALL omit the seed field even if the caller passes one.

Scenario: Caller passes seed to a Claude provider

  • WHEN A caller invokes client.chat(system, user, seed=7) with provider set to claude
  • THEN The request body does not contain a seed field

Existing Tool Considered

No new tool or library is needed. The OpenAI-compatible API, Ollama, and Anthropic APIs natively accept temperature, top_p, and seed per request (Anthropic does not accept seed). The fix threads the caller's values through the existing call chain to the HTTP payload and the cache key. The written cost of building this code is the change to two or three files in src/devops_cli/ai/client/ to add explicit parameters and pass them to the payload builders and cache key generation.

Key questions

  • **Should the fix pass per-call values through to the payload, or remove kwargs so unknown arguments raise TypeError?: Pass the values through. The review analysis module already passes temperature, top_p, and seed and expects them to reach the model. The OpenAI, Ollama, and Anthropic APIs all accept per-request sampling. Removing **kwargs would break existing callers that legitimately need per-call sampling. (best practice) [sources: src/devops_cli/review/analysis.py, src/devops_cli/ai/client/unified.py]
    • Chosen: Pass temperature, top_p, seed through to payload and cache key. Callers already pass these values and expect them to work. The provider APIs support per-request sampling. This is the standard pattern for LLM clients.
    • Rejected: Remove **kwargs so unknown arguments raise TypeError. This would break the review analysis module, which legitimately needs per-call sampling. It also removes the ability to set sampling per call, which the provider APIs support.
  • Which parameters does the fix cover?: temperature, top_p, and seed. These are the three parameters that the body names and that the review analysis module passes. Anthropic does not accept seed, so seed is omitted for that provider. [sources: src/devops_cli/review/analysis.py, src/devops_cli/ai/client/unified.py]
  • Which files hold the code that must change?: src/devops_cli/ai/client/unified.py holds chat, chat_messages, _retry_chat_dispatch, and _dispatch_messages. The payload builders in src/devops_cli/ai/client/openai.py and src/devops_cli/ai/client/ollama.py read self._config.temperature and self._config.top_p. The cache key is generated in chat_messages in unified.py. [sources: src/devops_cli/ai/client/unified.py, src/devops_cli/ai/client/openai.py, src/devops_cli/ai/client/ollama.py]
  • How should the per-call value interact with the config value in the payload builder?: The per-call value takes precedence when it is not None. When it is None, the builder falls back to self._config.temperature or self._config.top_p. This preserves the existing behavior for callers that do not pass per-call values. (best practice) [sources: src/devops_cli/ai/client/unified.py]
    • Chosen: Per-call value overrides config when not None. This is the standard override pattern. It preserves existing behavior for callers that do not pass per-call values, and gives callers that do pass them the expected result.
    • Rejected: Per-call value replaces config entirely. This would require callers to pass all sampling parameters or get no sampling at all. It breaks existing callers that rely on config defaults.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Oct 28, 2026
  2. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. Parameters are silently ignored, producing wrong AI output without any error.
    • Priority: P2-Medium. Callers believe they set per-call sampling but get config defaults silently, which corrupts review-analysis results.
    • Value: Medium. Fixes silent parameter drops that mislead callers and produce incorrect model outputs.
    • Effort: Low. Either forward three kwargs to the payload builder and cache key, or remove the **kwargs signature; a small change in two or three files.
    • Related: fix(ai): sampling settings reach the model or are refused, review sessions record them, and the reply cache key includes them #1070, which asks for a different change. Both address sampling parameters not reaching the model, but 1070 covered num_ctx on the gateway and review-session recording, while this candidate is the specific **kwargs drop in LLMClient.chat and chat_messages.
  3. added
    priority/p2-medium
    on Oct 28, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  5. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 0f7bc26 (see proposed design in issue body).

  6. added
    scope/ai
    on Oct 30, 2026
  7. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Staged: branch fix/2559-llmclient-chat-takes-temperature-top-p, draft pull request #2997. The pull request plans the item and closes no issue.

    The task groups, with the tokens of the inputs of each step, for a budget of 40000 tokens:

    1. Add explicit sampling params to chat and chat_messages: 4757 tokens
    2. Use per-call sampling in provider payload builders: 4758 tokens
    3. Cache key includes per-call sampling values: 4678 tokens

    These paths of the plan are no file on the default branch, and no group creates them: tests/ai/client/test_unified_sampling.py, tests/ai/client/test_provider_sampling.py, tests/ai/client/test_cache_key_sampling.py. A person checks that the plan names them right.

  8. added
    owner/service
    status/in-progress
    and removed
    status/ready
    on Nov 1, 2026
  9. 12 remaining items

  10. added
    owner/service
    status/in-progress
    and removed
    status/planned
    on Nov 1, 2026
  11. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Stopped at group 1.

    Reason:

    ModelHTTPError: HTTP 400, model devops-coder, body: XML syntax error on line 35: unexpected EOF
    The provider failed inside the stream. A known cause is that tool call parsing failed: Ollama refuses a tool call of the model when the XML of the call is not whole (ollama/ollama issue 18563).
    

    Last message of the agent: Now let me implement the changes step by step. First, I'll add the CallSampling class to models.py:

    The job discarded this work. Read it before you retry:

    diff --git a/tests/ai/client/test_per_call_sampling.py b/tests/ai/client/test_per_call_sampling.py
    new file mode 100644
    index 00000000..9156cb57
    --- /dev/null
    +++ b/tests/ai/client/test_per_call_sampling.py
    @@ -0,0 +1,60 @@
    +"""Tests for per-call sampling parameters in LLMClient.chat and chat_messages."""
    +
    +import pytest
    +from unittest.mock import patch, MagicMock
    +from devops_cli.ai.client.unified import LLMClient
    +from devops_cli.ai.client.models import CallSampling
    +
    +
    +def test_per_call_sampling_temperature_and_top_p():
    +    """Test that chat sends per-call temperature and top_p values."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_seed():
    +    """Test that chat sends per-call seed value."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_use_model_sampling():
    +    """Test that when use_model_sampling is True, no sampling parameters are sent."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_supports_reasoning():
    +    """Test that when supports_reasoning is True, no sampling parameters are sent."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_unknown_parameter_raises_type_error():
    +    """Test that passing unknown parameter raises TypeError."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_cache_key_with_temperature():
    +    """Test that cache key includes per-call temperature."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_cache_key_with_seed():
    +    """Test that cache key includes per-call seed."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_cache_key_same_temperature():
    +    """Test that same temperature values result in cache hit."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    +
    +
    +def test_per_call_sampling_cache_key_different_temperatures():
    +    """Test that different temperature values result in cache miss."""
    +    # This is a placeholder - actual implementation will come later
    +    pass
    \ No newline at end of file

    The item is Blocked, and the job will not run it. Fix the cause. Then comment implement: retry. The Service also clears the stop one time when a new runner image rolls out.

  12. added
    status/blocked
    and removed
    status/in-progress
    on Nov 1, 2026
  13. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-runner-20261101-171759-d5a6 ended: succeeded.
    Image digest: sha256:04d655904252706a7321aed38fa5cafd293625c5db469f252f57163a7c463f16

    The last lines of its log:

    b'# Implement plan for dan-petty/devops-cli\n\n## To implement\n- #2559 fix(ai): LLMClient.chat takes temperature, top_p and seed and sends none of them: Planned, new branch `fix/2559-llmclient-chat-takes-temperature-top-p` and a new pull request\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: read_file, ok.\nTool call: list_files, ok.\nTool call: write_file, ok.\n\xe2\x9c\x93 Took 0 item(s) to a ready pull request, stopped 1.\nElapsed: 1m 5s\n'
    
  14. added
    status/planned
    and removed
    owner/service
    status/blocked
    on Nov 1, 2026
  15. devops-cli-service commented on Nov 1, 2026

    @devops-cli-service
    Contributor

    Cleared the stop at group 1 by the rule digest: the runner image changed since the stop, from sha256:04d655904252706a7321aed38fa5cafd293625c5db469f252f57163a7c463f16 to sha256:c4ca1742d66bef1bfb15d41d7c54ebf2d0c674a8aaf413f2b28253a0963e4ab0. The item is Planned again, and the Service takes it in the next round. The Service clears a stop one time for each runner image. A new stop on this image waits for a comment implement: retry.

  16. removed
    status/planned
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/aisource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions