fix: truncate context logic
C++ / fmt (pull_request) Successful in 4s
C++ / build (pull_request) Failing after 2m6s
C++ / clang-tidy (pull_request) Failing after 2m5s
JS/TS / fmt (pull_request) Failing after 3m8s
Python / static (pull_request) Successful in 24s
Python / verify (pull_request) Successful in 1m21s
JS/TS / lint (pull_request) Successful in 5m10s
Rust / fmt (pull_request) Successful in 30s
Rust / build (pull_request) Successful in 56s
Rust / clippy (pull_request) Successful in 46s

This commit is contained in:
2026-09-04 02:20:37 +02:00
parent 34dde4bbfb
commit cd3da1941b
15 changed files with 238 additions and 126 deletions
+1 -10
View File
@@ -21,29 +21,21 @@ class LlmTool : public QObject {
[[nodiscard]] virtual QString description() const = 0;
[[nodiscard]] virtual QJsonObject parameters() const = 0;
// toolCallId identifies the call within the conversation; tools may use
// it to name files they write for later retrieval.
virtual void execute(
const QString& toolCallId,
const QJsonObject& args,
int outputBudgetChars,
std::function<void(const QJsonObject& result)> done) = 0;
virtual void cancel();
[[nodiscard]] QJsonObject specification() const;
// The endpoint's context size in tokens (0 = unknown). Set by LlmClient.
[[nodiscard]] int contextSize() const { return m_contextSize; }
void setContextSize(int value);
// Rough cap, in characters, for tool output embedded in a tool result
// message. Scales with the context size so a single result cannot
// consume the whole window.
[[nodiscard]] int inlineBudgetChars() const;
// ~4 characters per token; a deliberately coarse estimate used for
// budgeting (never for exact accounting).
static constexpr int CharsPerToken = 4;
// Inline budget when the context size is unknown.
static constexpr int DefaultInlineChars = 64 * 1024;
protected:
@@ -66,7 +58,6 @@ class ToolRegistry : public QObject {
[[nodiscard]] QJsonArray specifications() const;
void cancelAll();
// Propagated to every registered tool, including later ones.
void setContextSize(int value);
Q_SIGNALS: