fix(tools): scope file-read dedup to model context (#5775)
* fix(tools): scope file-read dedup to model context * refactor(tools): narrow file-read context and build results lazily
This commit is contained in:
1 parent
47f77bdbcc
commit
d386ba138e
10 files changed
+417
-176
No files matched your search
@@ -11,7 +11,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
from collections.abc import Awaitable, Callable
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass, replace
|
||||
from dataclasses import dataclass, field, replace
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
@@ -200,6 +200,7 @@ class ModelRequestState:
|
||||
tool_definitions: list[dict[str, Any]] | None = None
|
||||
compaction: ContextCompactionState | None = None
|
||||
provider_compaction_applied: bool = False
|
||||
compacted_tool_results: set[str] = field(default_factory=set)
|
||||
events: EventSink = NO_EVENTS
|
||||
|
||||
|
||||
@@ -444,6 +445,19 @@ class ContextGovernor:
|
||||
) -> None:
|
||||
"""Materialize the exact input replaced by provider-native compaction."""
|
||||
compaction = state.compaction
|
||||
if response.provider_compaction_applied:
|
||||
# Native compaction can omit results while the local transcript keeps
|
||||
# their full text. They no longer prove what the model can read.
|
||||
replaced_messages = (
|
||||
compaction.accepted_messages
|
||||
if response.provider_compaction_scope == "prior_context" and compaction is not None
|
||||
else state.messages or []
|
||||
)
|
||||
state.compacted_tool_results.update(
|
||||
message["tool_call_id"] for message in replaced_messages
|
||||
if message.get("role") == "tool"
|
||||
and isinstance(message.get("tool_call_id"), str)
|
||||
)
|
||||
if (
|
||||
not response.provider_compaction_applied
|
||||
or response.provider_compaction_state is None
|
||||
|
||||
Reference in new issue
Block a user