Commit ·
856a97c
1
Parent(s): 0bfaafb
agent: surface _llm_extract failure reason in visit tool_response
Browse filesWhen the visit extractor returns None, attach `extractor_error` so the
trace JSON tells us whether the env vars are missing, the OpenAI client
errored, or the model rejected the call. Diagnostic only — strips out
once we are confident the SUMMARY model is wired up.
app.py
CHANGED
|
@@ -1610,11 +1610,24 @@ def _jina_readpage(url: str) -> Optional[str]:
|
|
| 1610 |
return None
|
| 1611 |
|
| 1612 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1613 |
def _llm_extract(webpage_content: str, goal: str) -> Optional[str]:
|
| 1614 |
"""Run the SUMMARY model as the visit extractor. Mirrors
|
| 1615 |
inference/prompt.py:build_visit_extractor_messages + tool_visit's call."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1616 |
client = _get_openai_client(SUMMARY_API_KEY, SUMMARY_API_BASE)
|
| 1617 |
-
if client is None
|
|
|
|
| 1618 |
return None
|
| 1619 |
try:
|
| 1620 |
resp = client.chat.completions.create(
|
|
@@ -1630,7 +1643,8 @@ def _llm_extract(webpage_content: str, goal: str) -> Optional[str]:
|
|
| 1630 |
timeout=120,
|
| 1631 |
)
|
| 1632 |
return (resp.choices[0].message.content or "").strip() or None
|
| 1633 |
-
except Exception:
|
|
|
|
| 1634 |
return None
|
| 1635 |
|
| 1636 |
|
|
@@ -1729,6 +1743,8 @@ def _run_visit_single(url: str, max_chars: int, goal: str = "") -> Dict[str, Any
|
|
| 1729 |
"content": (extract or jina_md)[:max_chars],
|
| 1730 |
"extractor": "llm" if extract else "jina-raw",
|
| 1731 |
}
|
|
|
|
|
|
|
| 1732 |
VISIT_CACHE[cache_key] = result
|
| 1733 |
return result
|
| 1734 |
|
|
|
|
| 1610 |
return None
|
| 1611 |
|
| 1612 |
|
| 1613 |
+
# Last error from the most recent _llm_extract call (for diagnostics in trace).
|
| 1614 |
+
_LAST_EXTRACT_ERR: Optional[str] = None
|
| 1615 |
+
|
| 1616 |
+
|
| 1617 |
def _llm_extract(webpage_content: str, goal: str) -> Optional[str]:
|
| 1618 |
"""Run the SUMMARY model as the visit extractor. Mirrors
|
| 1619 |
inference/prompt.py:build_visit_extractor_messages + tool_visit's call."""
|
| 1620 |
+
global _LAST_EXTRACT_ERR
|
| 1621 |
+
_LAST_EXTRACT_ERR = None
|
| 1622 |
+
if not SUMMARY_MODEL_NAME:
|
| 1623 |
+
_LAST_EXTRACT_ERR = "SUMMARY_MODEL_NAME env var not set"
|
| 1624 |
+
return None
|
| 1625 |
+
if not SUMMARY_API_KEY:
|
| 1626 |
+
_LAST_EXTRACT_ERR = "API_KEY / SUMMARY_OPENAI_API_KEY env var not set"
|
| 1627 |
+
return None
|
| 1628 |
client = _get_openai_client(SUMMARY_API_KEY, SUMMARY_API_BASE)
|
| 1629 |
+
if client is None:
|
| 1630 |
+
_LAST_EXTRACT_ERR = "openai client could not be constructed (package missing?)"
|
| 1631 |
return None
|
| 1632 |
try:
|
| 1633 |
resp = client.chat.completions.create(
|
|
|
|
| 1643 |
timeout=120,
|
| 1644 |
)
|
| 1645 |
return (resp.choices[0].message.content or "").strip() or None
|
| 1646 |
+
except Exception as exc:
|
| 1647 |
+
_LAST_EXTRACT_ERR = f"{type(exc).__name__}: {str(exc)[:300]}"
|
| 1648 |
return None
|
| 1649 |
|
| 1650 |
|
|
|
|
| 1743 |
"content": (extract or jina_md)[:max_chars],
|
| 1744 |
"extractor": "llm" if extract else "jina-raw",
|
| 1745 |
}
|
| 1746 |
+
if not extract and _LAST_EXTRACT_ERR:
|
| 1747 |
+
result["extractor_error"] = _LAST_EXTRACT_ERR
|
| 1748 |
VISIT_CACHE[cache_key] = result
|
| 1749 |
return result
|
| 1750 |
|