Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/advanced/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Configure Strix using environment variables or a config file.
Request timeout in seconds for LLM calls.
</ParamField>

<ParamField path="STRIX_LLM_MAX_TOKENS" type="integer">
Optional maximum output tokens for each agent LLM request. Leave unset to use
the provider/model default.
</ParamField>

<ParamField path="STRIX_LLM_MAX_RETRIES" default="5" type="integer">
Maximum number of retries for LLM API calls on transient failures.
</ParamField>
Expand Down
1 change: 1 addition & 0 deletions strix/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class LlmSettings(BaseSettings):
default=False,
alias="LLM_DISABLE_STREAMING",
)
max_tokens: int | None = Field(default=None, gt=0, alias="STRIX_LLM_MAX_TOKENS")
timeout: int = Field(default=300, alias="LLM_TIMEOUT")


Expand Down
2 changes: 2 additions & 0 deletions strix/core/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ def make_model_settings(
request_timeout: float | None = None,
prompt_cache: bool = True,
extra_headers: dict[str, str] | None = None,
max_tokens: int | None = None,
) -> ModelSettings:
model_settings = ModelSettings(
parallel_tool_calls=False,
retry=DEFAULT_MODEL_RETRY,
include_usage=True,
max_tokens=max_tokens,
extra_args=request_timeout_extra_args(request_timeout),
extra_headers=dict(extra_headers) if extra_headers else None,
)
Expand Down
1 change: 1 addition & 0 deletions strix/core/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ async def _spill_to_workspace(output_id: str, text: str) -> str | None:
request_timeout=settings.llm.timeout,
prompt_cache=settings.llm.prompt_cache,
extra_headers=settings.llm.extra_headers,
max_tokens=settings.llm.max_tokens,
)
run_config = RunConfig(
model=resolved_model,
Expand Down
7 changes: 6 additions & 1 deletion tests/test_config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic.fields import FieldInfo

from strix.config import loader
from strix.config.settings import ContextSettings
from strix.config.settings import ContextSettings, LlmSettings


if TYPE_CHECKING:
Expand All @@ -28,6 +28,7 @@
"OLLAMA_API_BASE",
"STRIX_REASONING_EFFORT",
"STRIX_FORCE_REQUIRED_TOOL_CHOICE",
"STRIX_LLM_MAX_TOKENS",
"LLM_TIMEOUT",
"PERPLEXITY_API_KEY",
# RuntimeSettings
Expand Down Expand Up @@ -130,6 +131,10 @@ def test_tool_output_max_bytes_accepts_floor() -> None:
assert ContextSettings(STRIX_TOOL_OUTPUT_MAX_BYTES=1024).tool_output_max_bytes == 1024


def test_llm_max_tokens_env_alias() -> None:
assert LlmSettings(STRIX_LLM_MAX_TOKENS=12_000).max_tokens == 12_000


# --------------------------------------------------------------------------- #
# _aliases_for
# --------------------------------------------------------------------------- #
Expand Down
10 changes: 10 additions & 0 deletions tests/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,16 @@ def test_make_model_settings_sets_request_timeout() -> None:
assert settings.extra_args["timeout"] == 300.0


def test_make_model_settings_sets_configured_token_budget() -> None:
settings = make_model_settings(
"none",
model_name="gpt-4o",
max_tokens=12_000,
)

assert settings.max_tokens == 12_000


def test_make_model_settings_omits_timeout_when_unset() -> None:
settings = make_model_settings("none", model_name="gpt-4o")

Expand Down
1 change: 1 addition & 0 deletions tests/test_runner_rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async def test_persistent_rate_limit_stops_gracefully(
timeout=300,
prompt_cache=True,
extra_headers=None,
max_tokens=None,
),
runtime=types.SimpleNamespace(max_context_images=3),
)
Expand Down
25 changes: 24 additions & 1 deletion tests/test_runner_root_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _patch_engine_scaffold(
timeout=300,
prompt_cache=True,
extra_headers=None,
max_tokens=12_000,
),
runtime=types.SimpleNamespace(max_context_images=3),
)
Expand All @@ -74,10 +75,15 @@ async def _cleanup(*_args: Any, **_kwargs: Any) -> None:

monkeypatch.setattr(runner, "build_root_task", lambda _scan_config: "task")
monkeypatch.setattr(runner, "build_scope_context", lambda _scan_config: scope_context)
monkeypatch.setattr(runner, "make_model_settings", lambda *_args, **_kwargs: object())

captured: dict[str, Any] = {}

def _make_model_settings(*_args: Any, **kwargs: Any) -> object:
captured["model_settings_kwargs"] = kwargs
return object()

monkeypatch.setattr(runner, "make_model_settings", _make_model_settings)

def _build_strix_agent(**kwargs: Any) -> object:
if kwargs.get("is_root") and "kwargs" not in captured:
captured["kwargs"] = kwargs
Expand Down Expand Up @@ -176,3 +182,20 @@ async def test_root_prompt_options_default_to_none(
kwargs = captured["kwargs"]
assert kwargs["instructions_override"] is None
assert kwargs["system_prompt_context"] == {"scope": "built-in"}


@pytest.mark.asyncio
async def test_llm_max_tokens_flows_into_model_settings(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Any,
) -> None:
captured = _patch_engine_scaffold(monkeypatch, tmp_path, {"scope": "built-in"})

await runner.run_strix_scan(
scan_config={"targets": [], "scan_mode": "deep"},
scan_id="scan-token-budget",
image="img",
coordinator=AgentCoordinator(),
)

assert captured["model_settings_kwargs"]["max_tokens"] == 12_000