fix: stream internal model calls with idle timeouts (#5730)
* fix: stream internal model calls with idle timeouts * fix(providers): reject streams without terminal events
This commit is contained in:
1 parent
aeb7b207d7
commit
73410e0217
60 files changed
+815
-795
No files matched your search
@@ -1,8 +1,8 @@
|
||||
"""Session metadata helpers for explicit sustained goals.
|
||||
|
||||
Tools set ``metadata[GOAL_STATE_KEY]``. Reads accept the legacy session key ``thread_goal``
|
||||
for older sessions. Callers use ``goal_state_runtime_lines``, ``goal_state_ws_blob``, and
|
||||
``runner_wall_llm_timeout_s`` without importing tool implementations.
|
||||
for older sessions. Callers use ``goal_state_runtime_lines`` and ``goal_state_ws_blob`` without
|
||||
importing tool implementations.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -10,8 +10,6 @@ from __future__ import annotations
|
||||
import json
|
||||
from typing import Any, Mapping, MutableMapping, cast
|
||||
|
||||
from nanobot.session.manager import SessionManager
|
||||
|
||||
GOAL_STATE_KEY = "goal_state"
|
||||
GOAL_COMMAND = "/goal"
|
||||
MAX_GOAL_OBJECTIVE_CHARS = 4000
|
||||
@@ -114,23 +112,3 @@ def goal_state_ws_blob(metadata: Mapping[str, Any] | None) -> dict[str, Any]:
|
||||
blob["recap"] = recap
|
||||
return blob
|
||||
return {"active": False}
|
||||
|
||||
|
||||
def runner_wall_llm_timeout_s(
|
||||
sessions: SessionManager,
|
||||
session_key: str | None,
|
||||
*,
|
||||
metadata: Mapping[str, Any] | None = None,
|
||||
message_metadata: Mapping[str, Any] | None = None,
|
||||
) -> float | None:
|
||||
"""Wall-clock cap for :class:`~nanobot.agent.runner.AgentRunner` when streaming an LLM.
|
||||
|
||||
Returns ``0.0`` to disable ``asyncio.wait_for`` around the request when this is a
|
||||
sustained-goal turn; ``None`` means use ``NANOBOT_LLM_TIMEOUT_S``. Pass in-memory
|
||||
``metadata`` when the caller already holds :attr:`~nanobot.session.manager.Session.metadata`
|
||||
for this turn.
|
||||
"""
|
||||
meta: Mapping[str, Any] | None = metadata
|
||||
if meta is None and session_key:
|
||||
meta = sessions.get_or_create(session_key).metadata
|
||||
return 0.0 if sustained_goal_turn(meta, message_metadata=message_metadata) else None
|
||||
@@ -256,7 +256,7 @@ async def maybe_generate_webui_title(
|
||||
|
||||
try:
|
||||
with llm_usage_source("system"):
|
||||
response = await provider.chat_with_retry(
|
||||
response = await provider.chat_stream_with_retry(
|
||||
[
|
||||
{
|
||||
"role": "system",
|
||||
|
||||
Reference in new issue
Block a user