fix: improve cross-device evidence, request diagnostics and prompt efficiency
This commit is contained in:
1 parent
621f30e437
commit
a66803651a
60 files changed
+3097
-160
No files matched your search
@@ -52,7 +52,7 @@ import json
|
||||
import time
|
||||
from typing import Any, Callable
|
||||
|
||||
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
|
||||
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, ToolMessage
|
||||
|
||||
from artemis.memory.step_memory import StepMemoryService
|
||||
from artemis.utils.logger import get_logger
|
||||
@@ -288,6 +288,7 @@ class TranscriptLedger:
|
||||
self._restored: list[BaseMessage] = []
|
||||
self._active: list[BaseMessage] = []
|
||||
self._staged: list[BaseMessage] | None = None
|
||||
self._fresh_tool_messages: set[int] = set()
|
||||
self._turn_count = 0
|
||||
|
||||
# L2/L3 chunk compression. ``_turns`` records each committed
|
||||
@@ -623,6 +624,7 @@ class TranscriptLedger:
|
||||
step_key: str | None = None,
|
||||
validator_result: Any | None = None,
|
||||
extra_step_keys: tuple[str, ...] | list[str] = (),
|
||||
tool_results: dict[str, list[BaseMessage]] | None = None,
|
||||
) -> None:
|
||||
"""Move the staged turn into the active region.
|
||||
|
||||
@@ -642,12 +644,34 @@ class TranscriptLedger:
|
||||
return
|
||||
staged = self._staged
|
||||
self._staged = None
|
||||
if tool_results:
|
||||
self._fresh_tool_messages.update(
|
||||
id(message) for messages in tool_results.values() for message in messages
|
||||
)
|
||||
# Replace declaration acknowledgements before committing the turn.
|
||||
# Each result retains the model's original call id, including bursts
|
||||
# containing several calls to the same plugin tool.
|
||||
staged = [
|
||||
replacement
|
||||
for message in staged
|
||||
for replacement in (
|
||||
tool_results.get(message.tool_call_id, [message])
|
||||
if isinstance(message, ToolMessage) and message.content == "Action Recorded"
|
||||
else [message]
|
||||
)
|
||||
]
|
||||
self._last_turn_silent = self._turn_is_silent(staged)
|
||||
|
||||
if step_key is not None:
|
||||
observation = self._first_image_message(staged)
|
||||
if observation is not None:
|
||||
self._step_keys[id(observation)] = str(step_key)
|
||||
if tool_results:
|
||||
# The turn's initial phone image is not evidence of a plugin
|
||||
# action. Associate the summary only with the returned images.
|
||||
observations = [m for result in tool_results.values() for m in result]
|
||||
else:
|
||||
observations = [self._first_image_message(staged)]
|
||||
for observation in observations:
|
||||
if observation is not None and self._first_image_message([observation]) is not None:
|
||||
self._step_keys[id(observation)] = str(step_key)
|
||||
|
||||
span_start = len(self._active)
|
||||
self._active.extend(staged)
|
||||
@@ -783,7 +807,12 @@ class TranscriptLedger:
|
||||
appending to it (the operator's in-turn tool loop) never mutates the
|
||||
ledger regions.
|
||||
"""
|
||||
self._compressor.compress(self._active, image_scrub_depth=self.effective_image_scrub_depth)
|
||||
self._compressor.compress(
|
||||
self._active,
|
||||
image_scrub_depth=self.effective_image_scrub_depth,
|
||||
protected_message_ids=self._fresh_tool_messages,
|
||||
)
|
||||
self._fresh_tool_messages.clear()
|
||||
if self._chunker is not None:
|
||||
try:
|
||||
self._chunker.on_render(self)
|
||||
|
||||
Reference in new issue
Block a user