feat(agent): enhance reasoning handling and configuration

Added support for processing encrypted reasoning content within the AIAgent class. Introduced logic to determine reasoning effort and enable/disable reasoning based on configuration settings. Updated the kwargs to reflect these changes, ensuring proper handling of reasoning parameters during agent execution.
This commit is contained in:
teknium1 2026-03-01 16:15:20 -08:00
parent c84d5ce738
commit 92da8e7e62

View file

@ -1585,6 +1585,16 @@ class AIAgent:
) )
continue continue
if item_type == "reasoning":
encrypted = item.get("encrypted_content")
if isinstance(encrypted, str) and encrypted:
reasoning_item = {"type": "reasoning", "encrypted_content": encrypted}
item_id = item.get("id")
if isinstance(item_id, str) and item_id:
reasoning_item["id"] = item_id
normalized.append(reasoning_item)
continue
role = item.get("role") role = item.get("role")
if role in {"user", "assistant"}: if role in {"user", "assistant"}:
content = item.get("content", "") content = item.get("content", "")
@ -2036,23 +2046,28 @@ class AIAgent:
if not instructions: if not instructions:
instructions = DEFAULT_AGENT_IDENTITY instructions = DEFAULT_AGENT_IDENTITY
# Resolve reasoning effort: config > default (xhigh)
reasoning_effort = "xhigh"
reasoning_enabled = True
if self.reasoning_config and isinstance(self.reasoning_config, dict):
if self.reasoning_config.get("enabled") is False:
reasoning_enabled = False
elif self.reasoning_config.get("effort"):
reasoning_effort = self.reasoning_config["effort"]
kwargs = { kwargs = {
"model": self.model, "model": self.model,
"instructions": instructions, "instructions": instructions,
"input": self._chat_messages_to_responses_input(payload_messages), "input": self._chat_messages_to_responses_input(payload_messages),
"tools": self._responses_tools(), "tools": self._responses_tools(),
"store": False, "store": False,
"reasoning": {"effort": "medium", "summary": "auto"},
"include": ["reasoning.encrypted_content"],
} }
# Apply reasoning effort from config if set if reasoning_enabled:
if self.reasoning_config and isinstance(self.reasoning_config, dict): kwargs["reasoning"] = {"effort": reasoning_effort, "summary": "auto"}
if self.reasoning_config.get("enabled") is False: kwargs["include"] = ["reasoning.encrypted_content"]
kwargs.pop("reasoning", None) else:
kwargs["include"] = [] kwargs["include"] = []
elif self.reasoning_config.get("effort"):
kwargs["reasoning"]["effort"] = self.reasoning_config["effort"]
if self.max_tokens is not None: if self.max_tokens is not None:
kwargs["max_output_tokens"] = self.max_tokens kwargs["max_output_tokens"] = self.max_tokens
@ -3159,7 +3174,7 @@ class AIAgent:
if self._try_refresh_codex_client_credentials(force=True): if self._try_refresh_codex_client_credentials(force=True):
print(f"{self.log_prefix}🔐 Codex auth refreshed after 401. Retrying request...") print(f"{self.log_prefix}🔐 Codex auth refreshed after 401. Retrying request...")
continue continue
retry_count += 1 retry_count += 1
elapsed_time = time.time() - api_start_time elapsed_time = time.time() - api_start_time