Skip to content

Conversation

@dbraduan
Copy link
Contributor

@dbraduan dbraduan commented Apr 23, 2025

Exposing # of tokens used in a last message(total_tokens = input_tokens + output_tokens) to the end user for UX improvement.

How this looks like:
image

@dbraduan dbraduan changed the title wip: show active context length wip: show active context length in CLI Apr 23, 2025
Copy link
Contributor Author

@dbraduan dbraduan left a comment

Choose a reason for hiding this comment

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

self-review


// Calculate system prompt tokens (approximate using a simpler system prompt)
// Since we can't directly access the built system prompt
let system_prompt = "You are an AI assistant.";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a hack to get it working for now, we should probably load context prompt similar to how we do it truncate.rs

.provider()
.get_model_config()
.context_limit
.unwrap_or(32000); // Default to 32k if not specified
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to truncate.rs, perhaps there could be one place where this is exposed, but don't have that much of knowledge about the codebase yet to tell where that should be.

@dbraduan dbraduan changed the title wip: show active context length in CLI Show active context length in CLI May 1, 2025
Comment on lines 81 to 85
name if name.contains("gpt-4.1")
|| name.contains("gpt-4-1")
|| name.contains("gpt-41") =>
{
Some(1_000_000)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be just a thing for our internal proxies, let me know if that's not a good addition, can remove.

all_tools.extend(toolshim_tools.iter().cloned());

// Create a token counter using the same tokenizer as the model
let token_counter = TokenCounter::new(model_config.tokenizer_name());
Copy link
Collaborator

Choose a reason for hiding this comment

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

the token counting i think can be somewhat slow and inaccurate (the anthropic ones are proprietary and we've seen our estimates be off by as much as 30%). Instead i think we can save the current token usage from the most recent model inference? that way we know more exactly and don't spend any extra time on it during the iteration loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed, @baxen!

@dbraduan dbraduan changed the title Show active context length in CLI cli(ux): Show active context length in CLI May 24, 2025
@angiejones
Copy link
Collaborator

hey @dbraduan - couple of merge conflicts to address

@dbraduan
Copy link
Contributor Author

dbraduan commented Jun 3, 2025

should be good to go, @angiejones ?

@angiejones angiejones merged commit 3a22d6b into block:main Jun 3, 2025
6 checks passed
katzdave added a commit to katzdave/goose that referenced this pull request Jun 3, 2025
* upstream/main:
  Feat: Refined the documentation for Goose (block#2751)
  mcp(developer): add fallback on .gitignore if no .gooseignore is present (block#2661)
  cli(ux): Show active context length in CLI (block#2315)
  cli(config): Add GOOSE_CONTEXT_STRATEGY setting (block#2666)
  fix: new models have different messages for context length exceeded (block#2763)
lifeizhou-ap added a commit that referenced this pull request Jun 4, 2025
* main:
  fix: pr comment build cli workflow (#2774)
  hotfix: don't always run prompt (#2773)
  Lifei/test workflow (#2772)
  chore: use hermit to install node, rust and protoc (#2766)
  Feat: Refined the documentation for Goose (#2751)
  mcp(developer): add fallback on .gitignore if no .gooseignore is present (#2661)
  cli(ux): Show active context length in CLI (#2315)
  cli(config): Add GOOSE_CONTEXT_STRATEGY setting (#2666)
  fix: new models have different messages for context length exceeded (#2763)
  fix: increase limit for direct to disk for performance (#2762)
  Revert "chore: use hermit in goose" (#2759)
  alexhancock/remove-settings-v1 (#2744)
  blog: Democratizing Detection Engineering at Block with Goose and Panther MCP (#2746)
michaelneale added a commit that referenced this pull request Jun 5, 2025
* main: (82 commits)
  feat: lead/worker model (#2719)
  fix: pass ref in pr comment workflow (#2777)
  feat: goose web for local terminal alternative (#2718)
  chore: run CI on merge_group (#2786)
  fix: Don't break from consuming subprocess output in shell tool until both streams are done (#2771)
  Add retries w/ exponential backoff for databricks provider (#2764)
  Fix paths in google drive mcp documentation (#2775)
  testing windows build (#2770)
  docs: Add Context7 YouTube Video (#2779)
  cli(command): Add `export` command to CLI for markdown export of sessions (#2533)
  fix(copilot): gh copilot auth token conflicts w/ gh mcp env var (#2743)
  feat(providers): Add support for Gemini 2.5 Flash Preview and Pro Preview models (#2780)
  fix: pr comment build cli workflow (#2774)
  hotfix: don't always run prompt (#2773)
  Lifei/test workflow (#2772)
  chore: use hermit to install node, rust and protoc (#2766)
  Feat: Refined the documentation for Goose (#2751)
  mcp(developer): add fallback on .gitignore if no .gooseignore is present (#2661)
  cli(ux): Show active context length in CLI (#2315)
  cli(config): Add GOOSE_CONTEXT_STRATEGY setting (#2666)
  ...
iandouglas pushed a commit that referenced this pull request Jun 5, 2025
Co-authored-by: Angie Jones <jones.angie@gmail.com>
cbruyndoncx pushed a commit to cbruyndoncx/goose that referenced this pull request Jul 20, 2025
Co-authored-by: Angie Jones <jones.angie@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants