fix(agent): refresh goal continuation context
This commit is contained in:
1 parent
3ce0cd972e
commit
27d869d3cc
4 files changed
+95
-12
No files matched your search
+14
-2
@@ -54,6 +54,8 @@ from nanobot.utils.runtime import (
|
||||
repeated_workspace_violation_error,
|
||||
)
|
||||
|
||||
GoalContinueMessage = str | Callable[[], str | None]
|
||||
|
||||
_DEFAULT_ERROR_MESSAGE = "Sorry, I encountered an error calling the AI model."
|
||||
_ARREARAGE_ERROR_MESSAGE = (
|
||||
"The AI provider rejected the request because the API key is out of quota or the "
|
||||
@@ -109,7 +111,7 @@ class AgentRunSpec:
|
||||
injection_callback: Any | None = None
|
||||
llm_timeout_s: float | None = None
|
||||
goal_active_predicate: Callable[[], bool] | None = None
|
||||
goal_continue_message: str | None = None
|
||||
goal_continue_message: GoalContinueMessage | None = None
|
||||
finalize_on_max_iterations: bool = True
|
||||
|
||||
|
||||
@@ -198,7 +200,7 @@ class AgentRunner:
|
||||
if not injections and allow_goal_continue and assistant_message is not None:
|
||||
predicate = spec.goal_active_predicate
|
||||
if predicate is not None and predicate():
|
||||
injections = [build_goal_continue_message(spec.goal_continue_message)]
|
||||
injections = [self._build_goal_continue_message(spec)]
|
||||
if not injections:
|
||||
return False, injection_cycles
|
||||
if real_injection:
|
||||
@@ -227,6 +229,16 @@ class AgentRunner:
|
||||
logger.info("Injected sustained-goal continuation {}", phase)
|
||||
return True, injection_cycles
|
||||
|
||||
def _build_goal_continue_message(self, spec: AgentRunSpec) -> dict[str, str]:
|
||||
custom = spec.goal_continue_message
|
||||
if callable(custom):
|
||||
try:
|
||||
custom = custom()
|
||||
except Exception:
|
||||
logger.exception("goal_continue_message callback failed")
|
||||
custom = None
|
||||
return build_goal_continue_message(custom)
|
||||
|
||||
async def _drain_injections(self, spec: AgentRunSpec) -> list[dict[str, Any]]:
|
||||
"""Drain pending user messages via the injection callback.
|
||||
|
||||
|
||||
Reference in new issue
Block a user