Eilen Shin aaca3eeaeb
refactor(agent): ground runtime decisions in structured evidence (#7986)
* refactor(agent): ground runtime decisions in structured evidence

Use producer status and structured errors for tool recovery, preserve memory context without lexical confirmation, and remove predetermined receipt and skill conclusions.

Require explicit MCP discovery and authenticated schedule trial actions. Preserve authorization, ownership, isolation, and bounded execution; update documentation and regression coverage.

* test(sandbox): expect read_file initialization error callback

* fix(agent): address evidence review follow-ups

* fix(agent): preserve retry budgets for OpenAI transport errors

* fix(agent): expose tool execution status in model requests

Project validated execution metadata and exact tool text into request-only JSON so status survives provider serialization. Preserve stored results and receipt hashes, cover SDK and graph boundaries, and migrate replay input hashes without changing recorded responses.

---------

Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-11-08 22:00:23 +08:00

25 lines
1.0 KiB
Python

"""OpenAI-compatible adapters that preserve structured response failures."""
from __future__ import annotations
from typing import Any
from langchain_core.outputs import ChatResult
from langchain_openai import ChatOpenAI
from deerflow.models.response_errors import EmptyModelResponseError
class OpenAIEmptyChoicesMixin:
"""Raise a typed error before LangChain indexes an empty choices list."""
def _create_chat_result(self, response: Any, generation_info: dict | None = None) -> ChatResult:
choices = response.get("choices") if isinstance(response, dict) else getattr(response, "choices", None)
if isinstance(choices, (list, tuple)) and not choices:
raise EmptyModelResponseError("Model returned an HTTP-success response with an empty choices list")
return super()._create_chat_result(response, generation_info=generation_info)
class GuardedChatOpenAI(OpenAIEmptyChoicesMixin, ChatOpenAI):
"""ChatOpenAI with typed handling for valid HTTP responses with no choices."""