[eric] split: move aux LLM helpers out of agent_manager

This commit is contained in:
ciregenz
2026-05-23 03:09:35 -07:00
parent b7ef925b03
commit f26f4985a9
2 changed files with 19 additions and 20 deletions
+1 -20
View File
@@ -49,32 +49,13 @@ from backend.apps.agents.tool_catalog import (
_get_denied_tool_names,
_is_fully_denied,
)
from backend.apps.agents.aux_llm import _safe_resp_text
logger = logging.getLogger(__name__)
os.environ.setdefault("CLAUDE_CODE_STREAM_CLOSE_TIMEOUT", "3600000")
def _safe_resp_text(resp) -> str:
"""Extract text from an Anthropic-shape response, tolerating Gemini/OpenAI
edge cases. Gemini through 9Router occasionally returns `content=[]` (e.g.
safety stop, function-call-only turn) which makes `resp.content[0].text`
raise `'NoneType' object is not subscriptable` and bubbles up as a
fallback-required path. This walks the content list looking for the first
text block and returns "" if none exists, so callers can decide their own
fallback without a raw IndexError.
"""
try:
blocks = getattr(resp, "content", None) or []
for b in blocks:
t = getattr(b, "text", None)
if isinstance(t, str) and t:
return t
return ""
except Exception:
return ""
def _apply_context_window(session, settings=None) -> None:
"""Set session.context_window from the registry for its (provider, model).
+18
View File
@@ -0,0 +1,18 @@
def _safe_resp_text(resp) -> str:
"""Extract text from an Anthropic-shape response, tolerating Gemini/OpenAI
edge cases. Gemini through 9Router occasionally returns `content=[]` (e.g.
safety stop, function-call-only turn) which makes `resp.content[0].text`
raise `'NoneType' object is not subscriptable` and bubbles up as a
fallback-required path. This walks the content list looking for the first
text block and returns "" if none exists, so callers can decide their own
fallback without a raw IndexError.
"""
try:
blocks = getattr(resp, "content", None) or []
for b in blocks:
t = getattr(b, "text", None)
if isinstance(t, str) and t:
return t
return ""
except Exception:
return ""