refactor(agent): snapshot generation without provider mutation

This commit is contained in:
chengyongru
2026-07-10 17:54:34 +08:00
committed by Xubin Ren
parent bd94fefd1a
commit cb03d2c748
5 changed files with 33 additions and 7 deletions
+10 -2
View File
@@ -173,9 +173,15 @@ class AgentLoop:
return self.tools.tool_names
def llm_runtime(self) -> LLMRuntime:
"""Return the current provider/model pair owned by this loop."""
"""Capture the current provider/model settings owned by this loop."""
self._refresh_provider_snapshot()
return LLMRuntime(self.provider, self.model)
return LLMRuntime.capture(
self.provider,
self.model,
context_window_tokens=self.context_window_tokens,
model_preset=self.model_preset,
snapshot_signature=self._provider_signature,
)
_RUNTIME_CHECKPOINT_KEY = "runtime_checkpoint"
_PENDING_USER_TURN_KEY = "pending_user_turn"
@@ -444,6 +450,8 @@ class AgentLoop:
provider = snapshot.provider
model = snapshot.model
context_window_tokens = snapshot.context_window_tokens
if snapshot.generation is not None:
provider.generation = snapshot.generation
old_model = self.model
self.provider = provider
self.model = model