diff --git a/src/ai_client.py b/src/ai_client.py
index 21ccd42d..3b20a94f 100644
--- a/src/ai_client.py
+++ b/src/ai_client.py
@@ -2183,6 +2183,7 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
if not api_key:
if monitor.enabled: monitor.end_component("ai_client._send_deepseek")
raise ValueError("DeepSeek API key not found in credentials.toml")
+ history = provider_state.get_history("deepseek")
api_url = "https://api.deepseek.com/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
@@ -2192,13 +2193,13 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
is_reasoner = _model in ("deepseek-reasoner", "deepseek-r1")
# Update history following Anthropic pattern
- with _deepseek_history_lock:
- _repair_deepseek_history(_deepseek_history)
- if discussion_history and not _deepseek_history:
+ with history.lock:
+ _repair_deepseek_history(history)
+ if discussion_history and not history:
user_content = f"[DISCUSSION HISTORY]\n\n{discussion_history}\n\n---\n\n{user_message}"
else:
user_content = user_message
- _deepseek_history.append({"role": "user", "content": user_content})
+ history.append({"role": "user", "content": user_content})
all_text_parts: list[str] = []
_cumulative_tool_bytes = 0
@@ -2212,8 +2213,8 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
sys_msg = {"role": "system", "content": f"{_get_combined_system_prompt()}\n\n\n{md_content}\n"}
current_api_messages.append(sys_msg)
- with _deepseek_history_lock:
- for i, msg in enumerate(_deepseek_history):
+ with history.lock:
+ for i, msg in enumerate(history):
# Create a clean copy of the message for the API
role = msg.get("role")
api_msg = {"role": role}
@@ -2344,14 +2345,14 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
thinking_tags = f"\n{reasoning_content}\n\n"
full_assistant_text = thinking_tags + assistant_text
- with _deepseek_history_lock:
+ with history.lock:
# DeepSeek/OpenAI: If tool_calls are present, content can be null but should usually be present
msg_to_store: Metadata = {"role": "assistant", "content": assistant_text or None}
if reasoning_content:
msg_to_store["reasoning_content"] = reasoning_content
if tool_calls_raw:
msg_to_store["tool_calls"] = tool_calls_raw
- _deepseek_history.append(msg_to_store)
+ history.append(msg_to_store)
if full_assistant_text:
all_text_parts.append(full_assistant_text)
@@ -2409,9 +2410,9 @@ def _send_deepseek(md_content: str, user_message: str, base_dir: str,
})
_append_comms("OUT", "request", {"message": f"[TOOL OUTPUT BUDGET EXCEEDED: {_cumulative_tool_bytes} bytes]"})
- with _deepseek_history_lock:
+ with history.lock:
for tr in tool_results_for_history:
- _deepseek_history.append(tr)
+ history.append(tr)
res = "\n\n".join(all_text_parts) if all_text_parts else "(No text returned)"
if monitor.enabled: monitor.end_component("ai_client._send_deepseek")