Context debug: guardar system_prompt + messages completos del último build
El endpoint /context-debug ahora devuelve full_context con el system_prompt y messages exactos enviados al modelo. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -309,11 +309,13 @@ async def get_context_debug(session_id: str) -> dict[str, Any]:
|
|||||||
|
|
||||||
history = ctx_engine.get_debug_history(session_id)
|
history = ctx_engine.get_debug_history(session_id)
|
||||||
last = ctx_engine.get_last_context_debug(session_id)
|
last = ctx_engine.get_last_context_debug(session_id)
|
||||||
|
full_context = ctx_engine.get_last_full_context(session_id)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"session_id": session_id,
|
"session_id": session_id,
|
||||||
"total_builds": len(history),
|
"total_builds": len(history),
|
||||||
"last_build": last,
|
"last_build": last,
|
||||||
|
"full_context": full_context,
|
||||||
"history": history,
|
"history": history,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class ContextEngine:
|
|||||||
# Debug history: last N context builds per session
|
# Debug history: last N context builds per session
|
||||||
self._history: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
self._history: dict[str, list[dict[str, Any]]] = defaultdict(list)
|
||||||
self._max_history = 20
|
self._max_history = 20
|
||||||
|
# Full context of the LAST build per session (not accumulated)
|
||||||
|
self._last_full_context: dict[str, dict[str, Any]] = {}
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Public — build context for a model call
|
# Public — build context for a model call
|
||||||
@@ -117,6 +119,14 @@ class ContextEngine:
|
|||||||
total_token_estimate=total_tokens,
|
total_token_estimate=total_tokens,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Guardar contexto completo del último build (solo el último por sesión)
|
||||||
|
self._last_full_context[session.session_id] = {
|
||||||
|
"system_prompt": system_prompt,
|
||||||
|
"messages": messages,
|
||||||
|
"total_tokens": total_tokens,
|
||||||
|
"timestamp": time.time(),
|
||||||
|
}
|
||||||
|
|
||||||
# --- Debug: log and store context build ---
|
# --- Debug: log and store context build ---
|
||||||
section_summary = []
|
section_summary = []
|
||||||
for s in sections:
|
for s in sections:
|
||||||
@@ -169,6 +179,10 @@ class ContextEngine:
|
|||||||
history = self._history.get(session_id, [])
|
history = self._history.get(session_id, [])
|
||||||
return history[-1] if history else None
|
return history[-1] if history else None
|
||||||
|
|
||||||
|
def get_last_full_context(self, session_id: str) -> dict[str, Any] | None:
|
||||||
|
"""Return the full context (system_prompt + messages) of the last build."""
|
||||||
|
return self._last_full_context.get(session_id)
|
||||||
|
|
||||||
def rehydrate_artifact(
|
def rehydrate_artifact(
|
||||||
self,
|
self,
|
||||||
artifact: ArtifactSummary,
|
artifact: ArtifactSummary,
|
||||||
|
|||||||
Reference in New Issue
Block a user