fix: preserve exploration tool history and cap context budget
This commit is contained in:
1 parent
ee256ad7ce
commit
621f30e437
17 files changed
+211
-23
No files matched your search
@@ -17,7 +17,7 @@ from collections.abc import Awaitable
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
from langchain_core.messages import SystemMessage, ToolMessage
|
||||
from langchain_core.messages import BaseMessage, SystemMessage, ToolMessage
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
from artemis.agents.validator.tool_declarations import normalize_coordinate_target
|
||||
@@ -146,9 +146,9 @@ class OperatorNode:
|
||||
from artemis.config.agent import MemoryTranscriptConfig
|
||||
|
||||
self._transcript_cfg = MemoryTranscriptConfig()
|
||||
# Index into the rendered message list where this turn's tail begins;
|
||||
# set by the transcript build and consumed after the tool loop.
|
||||
self._transcript_turn_base: int | None = None
|
||||
# Keep the actual observation, not an index: plugin/exploration context
|
||||
# may be prepended after render, shifting every message's position.
|
||||
self._transcript_turn_tail: BaseMessage | None = None
|
||||
self._turn_plan_baseline: str | None = None
|
||||
self._turn_ledger_streak: int = 0
|
||||
# Whether the previous turn's replies carried no visible reasoning text;
|
||||
@@ -225,7 +225,7 @@ class OperatorNode:
|
||||
active_background_tasks: list[dict] = None,
|
||||
newly_finished_tasks: list[dict] = None,
|
||||
) -> list:
|
||||
self._transcript_turn_base = None
|
||||
self._transcript_turn_tail = None
|
||||
if getattr(self._transcript_cfg, "enabled", False):
|
||||
try:
|
||||
return await self._build_prompt_transcript(
|
||||
@@ -243,7 +243,7 @@ class OperatorNode:
|
||||
f"Transcript prompt path failed; falling back to the legacy"
|
||||
f" 2-message build for this turn: {e}"
|
||||
)
|
||||
self._transcript_turn_base = None
|
||||
self._transcript_turn_tail = None
|
||||
|
||||
plan_and_history = self._build_plan_and_history(steps, task_plan)
|
||||
|
||||
@@ -468,18 +468,19 @@ class OperatorNode:
|
||||
mark_ephemeral(tail, builder.ephemeral_indices)
|
||||
|
||||
messages = ledger.render([tail])
|
||||
self._transcript_turn_base = len(messages) - 1
|
||||
self._transcript_turn_tail = tail
|
||||
return messages
|
||||
|
||||
def _stage_transcript_turn(self, messages: list) -> None:
|
||||
"""Hand this turn's tail + tool-loop products to the ledger."""
|
||||
base = self._transcript_turn_base
|
||||
self._transcript_turn_base = None
|
||||
if base is None:
|
||||
tail = self._transcript_turn_tail
|
||||
self._transcript_turn_tail = None
|
||||
if tail is None:
|
||||
return
|
||||
try:
|
||||
ledger = getattr(self.ctx, "transcript_ledger", None)
|
||||
if ledger is not None:
|
||||
base = next(i for i, message in enumerate(messages) if message is tail)
|
||||
ledger.stage_turn(messages[base:])
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to stage transcript turn: {e}")
|
||||
|
||||
Reference in new issue
Block a user