Compare commits
1 Commits
fix/626-va
...
queue/378-
| Author | SHA1 | Date | |
|---|---|---|---|
| 628487f7bd |
@@ -13,6 +13,7 @@ import concurrent.futures
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -643,7 +644,56 @@ def _build_job_prompt(job: dict) -> str:
|
|||||||
return "\n".join(parts)
|
return "\n".join(parts)
|
||||||
|
|
||||||
|
|
||||||
def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
|
# Regex patterns for local service references that fail on cloud endpoints
|
||||||
|
_CLOUD_INCOMPATIBLE_PATTERNS = [
|
||||||
|
(re.compile(r"\b[Cc]heck\s+(?:that\s+)?[Oo]llama\s+(?:is\s+)?(?:responding|running|up|available)", re.IGNORECASE),
|
||||||
|
"Verify system services are healthy using available tools"),
|
||||||
|
(re.compile(r"\b[Vv]erify\s+(?:that\s+)?[Oo]llama\s+(?:is\s+)?(?:responding|running|up)", re.IGNORECASE),
|
||||||
|
"Verify system services are healthy using available tools"),
|
||||||
|
(re.compile(r"\bcurl\s+localhost:\d+", re.IGNORECASE),
|
||||||
|
"use available tools to check service health"),
|
||||||
|
(re.compile(r"\bcurl\s+127\.0\.0\.1:\d+", re.IGNORECASE),
|
||||||
|
"use available tools to check service health"),
|
||||||
|
(re.compile(r"\bpoll\s+localhost", re.IGNORECASE),
|
||||||
|
"check service health via available tools"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _rewrite_cloud_incompatible_prompt(prompt: str, base_url: str) -> str:
|
||||||
|
"""Rewrite prompt instructions that assume local service access when running on cloud.
|
||||||
|
|
||||||
|
When a cron job runs on a cloud inference endpoint (Nous, OpenRouter, Anthropic),
|
||||||
|
instructions to "Check Ollama" or "curl localhost:11434" are impossible.
|
||||||
|
Instead of just warning, this rewrites the instruction to a cloud-compatible
|
||||||
|
equivalent that the agent can actually execute.
|
||||||
|
|
||||||
|
Returns the (possibly rewritten) prompt.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
from agent.model_metadata import is_local_endpoint
|
||||||
|
except ImportError:
|
||||||
|
return prompt
|
||||||
|
|
||||||
|
if is_local_endpoint(base_url or ""):
|
||||||
|
return prompt # Local — no rewrite needed
|
||||||
|
|
||||||
|
rewritten = prompt
|
||||||
|
for pattern, replacement in _CLOUD_INCOMPATIBLE_PATTERNS:
|
||||||
|
rewritten = pattern.sub(replacement, rewritten)
|
||||||
|
|
||||||
|
if rewritten != prompt:
|
||||||
|
rewritten = (
|
||||||
|
"[NOTE: Some instructions were adjusted for cloud execution. "
|
||||||
|
"Local service checks were rewritten to use available tools.]
|
||||||
|
|
||||||
|
"
|
||||||
|
+ rewritten
|
||||||
|
)
|
||||||
|
|
||||||
|
return rewritten
|
||||||
|
|
||||||
|
|
||||||
|
def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:(job: dict) -> tuple[bool, str, str, Optional[str]]:
|
||||||
"""
|
"""
|
||||||
Execute a single cron job.
|
Execute a single cron job.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user