-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[codex] prototype mcp_history thread hint injection #29259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ pub(crate) struct TokenBudgetContext { | |
| first_window_id: Uuid, | ||
| previous_window_id: Option<Uuid>, | ||
| window_id: Uuid, | ||
| tokens_left: i64, | ||
| mcp_result: Option<String>, | ||
| } | ||
|
|
||
| impl TokenBudgetContext { | ||
|
|
@@ -17,14 +17,14 @@ impl TokenBudgetContext { | |
| first_window_id: Uuid, | ||
| previous_window_id: Option<Uuid>, | ||
| window_id: Uuid, | ||
| tokens_left: i64, | ||
| mcp_result: Option<String>, | ||
| ) -> Self { | ||
| Self { | ||
| thread_id, | ||
| first_window_id, | ||
| previous_window_id, | ||
| window_id, | ||
| tokens_left, | ||
| mcp_result, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -49,9 +49,13 @@ impl ContextualUserFragment for TokenBudgetContext { | |
| .previous_window_id | ||
| .map_or_else(|| "none".to_string(), |window_id| window_id.to_string()); | ||
| let window_id = self.window_id; | ||
| let tokens_left = self.tokens_left; | ||
| let mcp_result = self | ||
| .mcp_result | ||
| .as_deref() | ||
| .map(|result| format!("\n{result}")) | ||
| .unwrap_or_default(); | ||
| format!( | ||
| "Thread id {thread_id}.\nFirst context window id {first_window_id}.\nPrevious context window id {previous_window_id}.\nCurrent context window id {window_id}.\nYou have {tokens_left} tokens left in this context window." | ||
| "Thread id {thread_id}.\nFirst context window id {first_window_id}.\nPrevious context window id {previous_window_id}.\nCurrent context window id {window_id}.{mcp_result}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| ) | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3216,15 +3216,38 @@ impl Session { | |
| } | ||
| // This is full-context metadata. Steady-state context diffs should not re-emit it. | ||
| if turn_context.config.features.enabled(Feature::TokenBudget) | ||
| && let Some(model_context_window) = turn_context.model_context_window() | ||
| && turn_context.model_context_window().is_some() | ||
| { | ||
| let mcp_result = self | ||
| .call_tool( | ||
| "notes", | ||
| "thread_hint", | ||
|
Comment on lines
+3221
to
+3224
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| /*arguments*/ None, | ||
| Some(serde_json::json!({ | ||
| "threadId": self.thread_id().to_string(), | ||
| })), | ||
|
Comment on lines
+3226
to
+3228
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For an Useful? React with 👍 / 👎. |
||
| ) | ||
| .await | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a configured Useful? React with 👍 / 👎. |
||
| .ok() | ||
| .and_then(|result| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If Useful? React with 👍 / 👎. |
||
| let text = result | ||
| .content | ||
| .iter() | ||
| .filter_map(|content| { | ||
| content.get("text").and_then(serde_json::Value::as_str) | ||
| }) | ||
| .filter(|text| !text.is_empty()) | ||
| .collect::<Vec<_>>() | ||
| .join("\n"); | ||
|
Comment on lines
+3240
to
+3241
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a configured AGENTS.md reference: AGENTS.md:L98-L100 Useful? React with 👍 / 👎. |
||
| (!text.is_empty()).then_some(text) | ||
| }); | ||
| developer_sections.push( | ||
| crate::context::TokenBudgetContext::new( | ||
| self.thread_id(), | ||
| auto_compact_window_ids.first_window_id, | ||
| auto_compact_window_ids.previous_window_id, | ||
| auto_compact_window_ids.window_id, | ||
| model_context_window, | ||
| mcp_result, | ||
| ) | ||
| .render(), | ||
| ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.