Skip to content

[codex] Add context remaining tool - #27518

Merged
pakrym-oai merged 9 commits into
mainfrom
pakrym/get-context-remaining-tool
Jun 11, 2026
Merged

[codex] Add context remaining tool#27518
pakrym-oai merged 9 commits into
mainfrom
pakrym/get-context-remaining-tool

Conversation

@pakrym-oai

Copy link
Copy Markdown
Contributor

Why

The token budget feature can inject remaining-context notices into model-visible context, but the model does not have a direct way to ask for that same remaining-token fragment on demand.

This PR adds a small model tool for the token budget feature so the model can request the current remaining context window message without duplicating the fragment format.

What changed

  • Adds a get_context_remaining direct-model tool behind Feature::TokenBudget.
  • Renders the tool output through TokenBudgetRemainingContext, matching the existing budget message shape.
  • Registers the tool alongside new_context in the token budget tool set.
  • Adds integration coverage that verifies the tool is exposed and returns the same <token_budget> remaining fragment already present in context.

Validation

  • just test -p codex-core token_budget

@pakrym-oai
pakrym-oai marked this pull request as ready for review June 11, 2026 02:47
@pakrym-oai
pakrym-oai requested a review from a team as a code owner June 11, 2026 02:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a29a07eb8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread codex-rs/core/src/tools/handlers/get_context_remaining.rs Outdated
};
let active_context_tokens = match invocation.session.token_usage_info().await {
Some(token_info) => token_info.last_token_usage.total_tokens,
None => invocation.session.get_total_token_usage().await,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token_usage_info and get_total_token_usage

we are really good at naming

@pakrym-oai
pakrym-oai force-pushed the pakrym/get-context-remaining-tool branch from 3a29a07 to 7926acc Compare June 11, 2026 03:01
…maining-tool

# Conflicts:
#	codex-rs/core/src/context/token_budget_context.rs
#	codex-rs/core/src/session/turn.rs
#	codex-rs/core/tests/suite/token_budget.rs
…indow-tool

# Conflicts:
#	codex-rs/core/src/session/turn.rs
#	codex-rs/core/tests/suite/token_budget.rs
Base automatically changed from pakrym/token-budget-window-tool to main June 11, 2026 03:39
…maining-tool

# Conflicts:
#	codex-rs/core/src/tools/spec_plan.rs
@pakrym-oai
pakrym-oai enabled auto-merge (squash) June 11, 2026 04:08
@pakrym-oai
pakrym-oai merged commit dac5f07 into main Jun 11, 2026
31 checks passed
@pakrym-oai
pakrym-oai deleted the pakrym/get-context-remaining-tool branch June 11, 2026 04:17
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 11, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants