Skip to content

fix: make Ask output token budget configurable - #1247

Open
bferanmi806-sketch wants to merge 2 commits into
lfnovo:mainfrom
bferanmi806-sketch:fix/1221-ask-output-token-budget
Open

fix: make Ask output token budget configurable#1247
bferanmi806-sketch wants to merge 2 commits into
lfnovo:mainfrom
bferanmi806-sketch:fix/1221-ask-output-token-budget

Conversation

@bferanmi806-sketch

@bferanmi806-sketch bferanmi806-sketch commented Aug 6, 2026

Copy link
Copy Markdown

Description

Make the Ask/Q&A output token budget configurable so intermediate and final answers are not silently truncated at the strategy step's smaller budget.

  • Structured strategy generation remains fixed at 2000 tokens.
  • Intermediate answers and final answers use OPEN_NOTEBOOK_ASK_MAX_TOKENS.
  • The default is 8192 tokens.
  • Malformed, zero, and negative values safely fall back to 8192 with a warning.
  • Added focused regression tests and configuration documentation.
  • No API, frontend, provider, dependency, or database behavior changed.

Related Issue

Fixes #1221

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (bug or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Performance improvement
  • Test coverage improvement

How Has This Been Tested?

  • Tested locally with Docker
  • Tested locally with development setup
  • Added new unit tests
  • Existing tests pass (uv run pytest)
  • Manual testing performed (describe below)

Test Details:

  • uv sync - completed successfully.
  • uv run pytest tests/test_ask_token_budget.py -v - 9 passed, 1 dependency deprecation warning.
  • uv run pytest tests/ -v - 611 passed, 3 failed, 49 errors, 2 dependency warnings. The failures and errors are pre-existing Windows path, proxy-environment, and temp-directory permission issues; the same representative failures reproduce on clean upstream a7de90d38aaf18ee85fd661854d35c11e44613e2.
  • uv run ruff check . - passed.
  • uv run ruff format --check open_notebook/graphs/ask.py tests/test_ask_token_budget.py - 2 files already formatted.
  • uv run python -m mypy . - no issues found in 131 source files.
  • git diff --check - passed.

Design Alignment

Which design principles does this PR support? (See VISION.md)

  • Privacy First
  • Simplicity Over Features
  • API-First Architecture
  • Multi-Provider Flexibility
  • Extensibility Through Standards
  • Async-First for Performance

Explanation:

The change adds one narrow, process-level configuration helper instead of expanding the request/API contract. It preserves provider-agnostic model selection and passes the budget through the existing per-call Esperanto configuration path.

Checklist

Code Quality

  • My code follows PEP 8 style guidelines (Python)
  • My code follows TypeScript best practices (Frontend; no frontend changes)
  • I have added type hints to my code (Python)
  • I have added JSDoc comments where appropriate (no TypeScript changes)
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas (the helper is self-documenting and has no complex undocumented logic)
  • My changes generate no new warnings or errors

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (focused tests pass; unrelated baseline failures are documented above)
  • I ran linting: make ruff or ruff check . --fix
  • I ran type checking: make lint or uv run python -m mypy .

Documentation

  • I have updated the relevant documentation in /docs (if applicable)
  • I have added/updated docstrings for new/modified functions
  • I have updated the API documentation (no API changes)
  • I have added comments to complex logic (no complex logic was added)

Database Changes

  • I have created migration scripts for any database schema changes (no database changes)
  • Migration includes both up and down scripts
  • Migration has been tested locally

Breaking Changes

  • This PR includes breaking changes
  • I have documented the migration path for users
  • I have updated MIGRATION.md (if applicable)

Screenshots (if applicable)

Not applicable; this is a backend-only change.

Additional Context

The strategy step remains deliberately small because it produces a bounded structured Strategy object with at most five searches. The two prose-generation stages have different output requirements and therefore use the configurable budget independently.

Pre-Submission Verification

Before submitting, please verify:


Thank you for contributing to Open Notebook!

Review in cubic

@bferanmi806-sketch
bferanmi806-sketch marked this pull request as ready for review August 6, 2026 11:14

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread open_notebook/graphs/ask.py
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.

[Bug] Ask (Q&A) answers are silently truncated due to hardcoded max_tokens=2000 in graphs/ask.py — especially visible in non-English languages

1 participant