Files
nisse/scripts/probe_context.py
T
dongarandClaude Opus 5.5 b934c46714
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 56s
Enforce the tool-call contract, asking servers only where it works
The executor ended a milestone on any reply without a tool call, and
nothing held a model to the offered tools. Measured on the 4070:
tool_choice "required" is enforced by vLLM (local-fast) and Anthropic,
but qwen3-14b (local-coder) under it cannot stop and writes until the
output ceiling, a known model bug. So enforcement is asked for per
model, and the loop holds the contract itself everywhere.

- The catalog reads supports_tool_choice from LiteLLM's model_info;
  BudgetedClient sends tool_choice only to models declared true, as
  "required" on the normalized route and {"type": "any"} on the
  Anthropic passthrough, and only when tools are offered
- The executor gains an explicit finish tool, the only way to end a
  milestone. Finishing with nothing changed is refused once; a prose
  reply gets one nudge, then escalates; a call to a tool not offered
  counts toward failure_limit, like a failed command; calls after
  finish are recorded as not run
- Clients record the model that actually answered. ModelFacts.answered
  recognises a proxy fallback, which once credited Claude's answers to
  a local model that could not call tools at all
- The context probe reports a fallback instead of trusting it; rerun,
  both local models now refuse over-long prompts, as they should
- The capability matrix checks every answer came from the model asked,
  that models call only offered tools, and that a declared
  supports_tool_choice is true
- Spec A15 and the tuning guide say how enforcement is requested,
  declared and backed up

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 22:54:49 +00:00

76 lines
2.4 KiB
Python

"""Check a model's declared context window against what its server does.
uv run python scripts/probe_context.py ALIAS [--config PATH]
ALIAS is a LiteLLM model alias. The LiteLLM URL and token come from the agent
config (NISSE_CONFIG, ./nisse-dev.yaml, or --config), with its secrets from
the environment or .env. See docs/Tuning-Guide.md, "Declaring a local model's
limits", and nisse_dev/probe.py for what the verdicts mean.
"""
import argparse
import os
import sys
from pathlib import Path
import httpx
from nisse_dev.catalog import ModelCatalog
from nisse_dev.config import AgentConfig, ConfigError
from nisse_dev.envfile import load_env_file
from nisse_dev.probe import probe
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
parser.add_argument("alias", help="LiteLLM model alias to probe")
parser.add_argument("--config", help="agent config file to take LiteLLM from")
parser.add_argument(
"--max-probe-tokens",
type=int,
default=64_000,
help="refuse to send a prompt larger than this (default: %(default)s)",
)
args = parser.parse_args()
load_env_file(Path(os.environ.get("NISSE_ENV", ".env")).expanduser())
try:
config = (
AgentConfig.from_file(Path(args.config))
if args.config
else AgentConfig.load()
)
except ConfigError as exc:
print(exc, file=sys.stderr)
return 2
catalog = ModelCatalog.discover(config.llm_base_url, config.llm_token)
facts = catalog.facts(args.alias)
declared = facts.max_input_tokens
if declared is None:
print(
f"LiteLLM declares no max_input_tokens for {args.alias}; set one first",
file=sys.stderr,
)
return 1
if declared * 1.5 > args.max_probe_tokens:
print(
f"{args.alias} declares {declared} tokens; probing would send about "
f"{int(declared * 1.5)}. Raise --max-probe-tokens to allow it.",
file=sys.stderr,
)
return 1
with httpx.Client(
base_url=config.llm_base_url.rstrip("/"),
headers={"Authorization": f"Bearer {config.llm_token}"},
timeout=600,
) as http:
result = probe(http, args.alias, declared, facts.backing)
print(f"{args.alias}: {result.message}")
return 0 if result.verdict in ("matches", "refuses", "declared_conservative") else 1
if __name__ == "__main__":
raise SystemExit(main())