mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Forward truncation policies to the history notes backend (#41062)
## What changed - Serialize each history and notes request's output truncation policy into the `x-openai-tool-output-truncation-policy` header. - Forward the invoking tool call's policy for tool requests and use the thread hint byte limit for context-contributor requests. GitOrigin-RevId: 9d4e61480397b325efdb033861893e88c708de3b
This commit is contained in:
1 parent
d5caceccb1
commit
4cb8d8679c
4 files changed
+17
No files matched your search
@@ -5,6 +5,7 @@ use codex_client::HttpTransport;
|
||||
use codex_client::RequestBody;
|
||||
use codex_login::default_client::create_client;
|
||||
use codex_model_provider::SharedModelProvider;
|
||||
use codex_utils_output_truncation::TruncationPolicy;
|
||||
use http::HeaderValue;
|
||||
use http::Method;
|
||||
use serde_json::Value;
|
||||
@@ -12,6 +13,7 @@ use serde_json::json;
|
||||
|
||||
const HISTORY_NOTES_BACKEND_TIMEOUT: Duration = Duration::from_secs(35);
|
||||
const ENCRYPTED_TOOL_ARGUMENTS_HEADER: &str = "x-openai-encrypted-tool-arguments";
|
||||
const TOOL_OUTPUT_TRUNCATION_POLICY_HEADER: &str = "x-openai-tool-output-truncation-policy";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct HistoryNotesBackend {
|
||||
@@ -29,6 +31,7 @@ impl HistoryNotesBackend {
|
||||
session_id: &str,
|
||||
current_agent_name: &str,
|
||||
mut arguments: Value,
|
||||
truncation_policy: TruncationPolicy,
|
||||
) -> Result<Value, String> {
|
||||
let Some(arguments_object) = arguments.as_object_mut() else {
|
||||
return Err("History tool arguments must be a JSON object".to_string());
|
||||
@@ -52,6 +55,14 @@ impl HistoryNotesBackend {
|
||||
.map_err(|error| format!("History backend auth could not be resolved: {error}"))?;
|
||||
|
||||
let mut request = provider.build_request(Method::POST, path);
|
||||
let encoded_truncation_policy = serde_json::to_string(&truncation_policy)
|
||||
.map_err(|error| format!("Could not encode tool output truncation policy: {error}"))?;
|
||||
request.headers.insert(
|
||||
TOOL_OUTPUT_TRUNCATION_POLICY_HEADER,
|
||||
HeaderValue::from_str(&encoded_truncation_policy).map_err(|error| {
|
||||
format!("Invalid tool output truncation policy header: {error}")
|
||||
})?,
|
||||
);
|
||||
if matches!(
|
||||
path,
|
||||
"alpha/history/v2/search_contents"
|
||||
|
||||
Reference in new issue
Block a user