Repository navigation
perf(api): skip saved prompts when loading agent history - #44529
Open
Takuya-ops wants to merge 1 commit into
Open
Takuya-ops wants to merge 1 commit into
Takuya-ops wants to merge 1 commit into
Conversation
BaseAgentRunner.organize_agent_history selected whole Message rows for the entire conversation. Message.message stores the full prompt of each turn, earlier history and tool results included, so every agent reply decoded about n^2/2 turns of text even though history is rebuilt from query and answer. Load only the columns the history needs. The rebuilt history is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fixes #<issue number>.Summary
Fixes #44528
This is the agent-app counterpart of #44521, which covers chat history and the chatflow thread-length helper. The two PRs touch different files and can be merged in either order.
On every agent reply,
BaseAgentRunner.organize_agent_historyloads everyMessagerow of the conversation, with no limit, as whole rows. Those rows includeMessage.message, which stores the full prompt of the turn: earlier history, the query and that turn's tool calls and results. Building history therefore decoded about n²/2 turns of text on every reply. The method never reads that column. It rebuilds history fromquery,answerand the agent thoughts.This PR adds
load_onlyto the query, so it selects justid,conversation_id,parent_message_id,queryandanswer.conversation_idis needed becauseorganize_agent_user_promptcallsMessage.app_model_config_with_sessionwhen a message has files. The rebuilt history is unchanged.Tests:
FROM messagesquery does not selectmessages.message, and no per-row lazy load follows. It also checks the rebuilt prompts. The test fails onmainand passes with this change.make lintandmake type-checkpass.pytest tests/unit_tests/core tests/unit_tests/services: 15,834 passed, 4 skipped.Screenshots
These numbers come from calling the real
organize_agent_historyagainst PostgreSQL 15, with one call per fresh process. The conversation and the saved prompts are described in #44528, which also has the script.The remaining time comes from the existing per-message
MessageFileandMessageAgentThoughtqueries. This PR does not change them.Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods🤖 Generated with Claude Code
From Claude Code