mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
feat(openai): support automatic server-side compaction (#35212)
This commit is contained in:
@@ -799,6 +799,11 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
passed in the parameter during invocation.
|
||||
"""
|
||||
|
||||
context_management: list[dict[str, Any]] | None = None
|
||||
"""Configuration for
|
||||
[context management](https://developers.openai.com/api/docs/guides/compaction).
|
||||
"""
|
||||
|
||||
include: list[str] | None = None
|
||||
"""Additional fields to include in generations from Responses API.
|
||||
|
||||
@@ -1096,6 +1101,7 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
"reasoning_effort": self.reasoning_effort,
|
||||
"reasoning": self.reasoning,
|
||||
"verbosity": self.verbosity,
|
||||
"context_management": self.context_management,
|
||||
"include": self.include,
|
||||
"service_tier": self.service_tier,
|
||||
"truncation": self.truncation,
|
||||
@@ -1482,6 +1488,7 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
return self.use_responses_api
|
||||
if (
|
||||
self.output_version == "responses/v1"
|
||||
or self.context_management is not None
|
||||
or self.include is not None
|
||||
or self.reasoning is not None
|
||||
or self.truncation is not None
|
||||
@@ -3894,6 +3901,7 @@ def _use_responses_api(payload: dict) -> bool:
|
||||
_is_builtin_tool(tool) for tool in payload["tools"]
|
||||
)
|
||||
responses_only_args = {
|
||||
"context_management",
|
||||
"include",
|
||||
"previous_response_id",
|
||||
"reasoning",
|
||||
@@ -4273,6 +4281,7 @@ def _construct_responses_api_input(messages: Sequence[BaseMessage]) -> list:
|
||||
)
|
||||
elif block_type in (
|
||||
"reasoning",
|
||||
"compaction",
|
||||
"web_search_call",
|
||||
"file_search_call",
|
||||
"function_call",
|
||||
@@ -4475,6 +4484,7 @@ def _construct_lc_result_from_responses_api(
|
||||
tool_calls.append(tool_call)
|
||||
elif output.type in (
|
||||
"reasoning",
|
||||
"compaction",
|
||||
"web_search_call",
|
||||
"file_search_call",
|
||||
"computer_call",
|
||||
@@ -4683,6 +4693,7 @@ def _convert_responses_chunk_to_generation_chunk(
|
||||
}
|
||||
)
|
||||
elif chunk.type == "response.output_item.done" and chunk.item.type in (
|
||||
"compaction",
|
||||
"web_search_call",
|
||||
"file_search_call",
|
||||
"computer_call",
|
||||
|
||||
Reference in New Issue
Block a user