feat: persist reasoning across gateway session turns (schema v6) (#2974)
feat: persist reasoning across gateway session turns (schema v6) Tested against OpenAI Codex (direct), Anthropic (direct + OAI-compat), and OpenRouter → 6 backends. All reasoning field types (reasoning, reasoning_details, codex_reasoning_items) round-trip through the DB correctly.
This commit is contained in:
@@ -5288,7 +5288,18 @@ class GatewayRunner:
|
||||
if msg.get("mirror"):
|
||||
mirror_src = msg.get("mirror_source", "another session")
|
||||
content = f"[Delivered from {mirror_src}] {content}"
|
||||
agent_history.append({"role": role, "content": content})
|
||||
entry = {"role": role, "content": content}
|
||||
# Preserve reasoning fields on assistant messages so
|
||||
# multi-turn reasoning context survives session reload.
|
||||
# The agent's _build_api_kwargs converts these to the
|
||||
# provider-specific format (reasoning_content, etc.).
|
||||
if role == "assistant":
|
||||
for _rkey in ("reasoning", "reasoning_details",
|
||||
"codex_reasoning_items"):
|
||||
_rval = msg.get(_rkey)
|
||||
if _rval:
|
||||
entry[_rkey] = _rval
|
||||
agent_history.append(entry)
|
||||
|
||||
# Collect MEDIA paths already in history so we can exclude them
|
||||
# from the current turn's extraction. This is compression-safe:
|
||||
|
||||
@@ -891,13 +891,17 @@ class SessionStore:
|
||||
# Write to SQLite (unless the agent already handled it)
|
||||
if self._db and not skip_db:
|
||||
try:
|
||||
_role = message.get("role", "unknown")
|
||||
self._db.append_message(
|
||||
session_id=session_id,
|
||||
role=message.get("role", "unknown"),
|
||||
role=_role,
|
||||
content=message.get("content"),
|
||||
tool_name=message.get("tool_name"),
|
||||
tool_calls=message.get("tool_calls"),
|
||||
tool_call_id=message.get("tool_call_id"),
|
||||
reasoning=message.get("reasoning") if _role == "assistant" else None,
|
||||
reasoning_details=message.get("reasoning_details") if _role == "assistant" else None,
|
||||
codex_reasoning_items=message.get("codex_reasoning_items") if _role == "assistant" else None,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug("Session DB operation failed: %s", e)
|
||||
@@ -918,13 +922,17 @@ class SessionStore:
|
||||
try:
|
||||
self._db.clear_messages(session_id)
|
||||
for msg in messages:
|
||||
_role = msg.get("role", "unknown")
|
||||
self._db.append_message(
|
||||
session_id=session_id,
|
||||
role=msg.get("role", "unknown"),
|
||||
role=_role,
|
||||
content=msg.get("content"),
|
||||
tool_name=msg.get("tool_name"),
|
||||
tool_calls=msg.get("tool_calls"),
|
||||
tool_call_id=msg.get("tool_call_id"),
|
||||
reasoning=msg.get("reasoning") if _role == "assistant" else None,
|
||||
reasoning_details=msg.get("reasoning_details") if _role == "assistant" else None,
|
||||
codex_reasoning_items=msg.get("codex_reasoning_items") if _role == "assistant" else None,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug("Failed to rewrite transcript in DB: %s", e)
|
||||
|
||||
Reference in New Issue
Block a user