Pass instruction depth config to llm-connect

This commit is contained in:
2026-05-19 20:55:35 +02:00
parent 1ff8b14d1b
commit 5c4f96e7aa
6 changed files with 208 additions and 16 deletions

View File

@@ -144,15 +144,16 @@ def _execute(
# Step 2 — render prompt (raises UntrustedFieldError on policy violation)
rendered = _render_prompt(instr.prompt, instr.trusted_fields, event, context)
prompt_hash = hashlib.sha256(rendered.encode()).hexdigest()
llm_config = _llm_run_config(instr)
# Step 3 — call LLM
raw_output = llm_client.complete(rendered, model=instr.model)
raw_output = llm_client.complete(rendered, model=instr.model, config=llm_config)
# Step 4 — validate and optionally retry
task_specs, report, error = _validate_output(raw_output, instr)
if error:
retry_prompt = rendered + f"\n\nPrevious output was invalid: {error}\nPlease fix."
raw_output = llm_client.complete(retry_prompt, model=instr.model)
raw_output = llm_client.complete(retry_prompt, model=instr.model, config=llm_config)
task_specs, report, error = _validate_output(raw_output, instr)
if error:
logger.warning(
@@ -172,6 +173,19 @@ def _execute(
)
def _llm_run_config(instr: Any) -> dict[str, Any]:
"""Build the llm-connect RunConfig payload from instruction metadata."""
config: dict[str, Any] = {"model_name": instr.model}
for field in ("temperature", "max_tokens", "max_depth"):
value = getattr(instr, field, None)
if value is not None:
config[field] = value
model_params = getattr(instr, "model_params", None)
if model_params:
config["model_params"] = model_params
return config
def _empty_result(instr: Any, prompt_hash: str | None = None) -> InstructionResult:
return InstructionResult(
tasks=[],