Forward provider output caps in bg-review + cron agents; chunk OpenViking batch sync

- agent/background_review.py, cron/scheduler.py: forward custom_providers
  max_output_tokens so qwen-family models don't fall back to the 65,536
  family cap and 400 on long prompts against a 131k local vLLM.
- plugins/memory/openviking: chunk /messages/batch posts at 100 items so
  long sessions keep structured sync instead of the 4k text fallback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Chris Korhonen 2026-07-05 18:30:04 -04:00
parent cba9975aba
commit 1a567f7067
3 changed files with 23 additions and 1 deletions

View file

@ -87,12 +87,18 @@ def _resolve_review_runtime(agent: Any) -> Dict[str, Any]:
explicit_api_key=task_api_key,
explicit_base_url=task_base_url,
)
# Forward the per-provider output cap (custom_providers
# max_output_tokens) so the routed fork doesn't fall back to the
# model-family output limit (e.g. qwen3 -> 65,536), which can exceed
# the local server's real context budget. Mirrors gateway/run.py.
_rt_max_tokens = rp.get("max_output_tokens")
return {
"provider": rp.get("provider") or task_provider,
"model": task_model,
"api_key": rp.get("api_key"),
"base_url": rp.get("base_url"),
"api_mode": rp.get("api_mode"),
"max_tokens": _rt_max_tokens if isinstance(_rt_max_tokens, int) and _rt_max_tokens > 0 else None,
"routed": True,
}
except Exception as e:
@ -647,6 +653,7 @@ def _run_review_in_thread(
# (The runtime whitelist below still restricts dispatch.)
review_agent = AIAgent(
model=_rt.get("model") or agent.model,
max_tokens=_rt.get("max_tokens"),
max_iterations=16,
quiet_mode=True,
platform=agent.platform,

View file

@ -2751,6 +2751,7 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
# example DeepSeek) for cron jobs that do not pin provider/model.
runtime_kwargs = {
"requested": job.get("provider"),
"target_model": model or None,
}
if job.get("base_url"):
runtime_kwargs["explicit_base_url"] = job.get("base_url")
@ -2871,8 +2872,15 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
job_id, _mcp_exc,
)
# Forward the per-provider output cap (custom_providers
# max_output_tokens) so cron agents don't fall back to the
# model-family output limit (e.g. qwen3 -> 65,536), which can
# exceed the local server's real context budget. Mirrors
# agent/background_review.py.
_rt_max_tokens = runtime.get("max_output_tokens")
agent = AIAgent(
model=model,
max_tokens=_rt_max_tokens if isinstance(_rt_max_tokens, int) and _rt_max_tokens > 0 else None,
api_key=runtime.get("api_key"),
base_url=runtime.get("base_url"),
provider=runtime.get("provider"),

View file

@ -3116,7 +3116,14 @@ class OpenVikingMemoryProvider(MemoryProvider):
json.dumps(payload, ensure_ascii=False),
)
try:
client.post(f"/api/v1/sessions/{sid}/messages/batch", payload)
# The OpenViking server caps batches at 100 messages;
# chunk so long sessions keep structured sync instead
# of degrading to the 4k-char text fallback.
for _start in range(0, len(batch_messages), 100):
client.post(
f"/api/v1/sessions/{sid}/messages/batch",
{"messages": batch_messages[_start:_start + 100]},
)
return
except Exception as batch_error:
logger.warning(