Agents: per-agent policy to replay a root agent's own tool calls from earlier turns
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 12/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- ai-infra-agents, sql, typescript
- Ambito
- ai-infra-agents
Direzione di ricerca
Start with BaseAgent.injectPriorTurnToolResults and PriorTurnToolResultCache, then readPromptStepStack, loadStoppedRunContinuation and RunAIAgentFromConversationDetail to see how history is built today. The proposal adds a per-agent replay policy with four modes, plus a lastRunId chain walk and a token budget. Done means the ToolCalls policy passes the three-turn, replaced-row, off-branch and byte-identical-prefix tests listed in the issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
Add a per-agent policy for replaying a root agent's own tool calls from earlier turns into its history, so an orchestrator agent remembers what it did, not just what it said.
Today, between turns a root agent sees only the text of each conversation message. The only exceptions are a two-turn carry-forward of read-only tool results and a full stack rebuild for runs the user stopped. For simple chat agents that's a sensible default. For an orchestrator that delegates to sub-agents over a long conversation, it loses the information it most needs on the next turn:
- what it delegated,
- the brief it sent,
- what came back,
- which lookups it already did.
Current behavior
What MJ does today (on next):
- History is text only.
RunAIAgentFromConversationDetailbuilds history from ConversationDetail rows: the newest summary plus the tail, or the last N rows. Only each row'sMessagetext is carried. No tool calls, action results, sub-agent result messages or reasoning from earlier turns. - Read-tool carry-forward.
BaseAgent.injectPriorTurnToolResultswithPriorTurnToolResultCachecarries completedToolstep outputs from the previous settled root run of the same agent, limited to read-tool families (CarryForwardToolFamilies). They arrive as one user message (buildCarryForwardMessage) that expires after 2 turns. Only the direct predecessor is used, and only when the run has aconversationId. - Stopped-run resume.
loadStoppedRunContinuation/tryResumeStoppedRunStack/readPromptStepStackalready rebuild a run's full message stack from its Prompt steps'InputData.conversationMessages, but only for runs the user stopped (stopContinuationMode: 'full_stack'). lastRunIddoesn't restore messages. It restores the payload (withautoPopulateLastRunPayload), bound action parameters and open sub-agent consults. The caller always suppliesconversationMessages.- Thinking. It's replayed within a run on the native tool path (
BuildAssistantToolCallTurn, with signatures), but never across turns.
So most of the machinery exists: rebuilding a stack from steps, carrying results forward, and the cache. It just isn't available as a general option for continuing a conversation turn to turn.
Why it matters
Agentic coding tools keep the main agent's own tool calls and results in the transcript across turns and compact them as the context fills. Sub-agent internals stay out: the parent sees only each sub-agent's final report. Anthropic's context-engineering guidance makes the same split. Keep the orchestrator's tool-call history, condense what sub-agents return, and clear old tool results (not the calls) once they're stale.
An MJ orchestrator built as a Loop agent with sub-agents can't do this today. On turn N+1 it doesn't know which sub-agent it called on turn N, what brief it gave, or what came back, unless that happened to be in its reply text. Follow-ups like "no, I meant renewals" or "why did you pick that table?" then depend on the model guessing.
Proposal
A per-agent replay policy
Add an agent field (or ExecuteAgentParams option, with the agent field as the default):
| Policy | Replays from earlier turns |
|---|---|
None |
Nothing beyond the conversation text |
ReadToolResults |
Today's carry-forward (the default, unchanged) |
ToolCalls |
The agent's own tool calls / action invocations / sub-agent delegations with their briefs, plus results; results older than PriorTurnReplayKeepResults turns are replaced by a placeholder or their existing compacted form |
Full |
The full rebuilt stack of each earlier turn, as stopped-run resume does today |
What gets replayed:
- Sub-agent results are replayed as the existing
sub-agent-resultmessage, which is already condensed. A sub-agent's internal steps are never replayed. - Reasoning and thinking blocks are excluded by default. They cost tokens on every turn, and they break when earlier history changes. If ever needed, they could be a separate opt-in.
Source: run steps, not a new store
Generalize readPromptStepStack so it can read any earlier root run, not just a stopped one. Each turn's record comes from that run's steps:
- Native tool mode: the stored assistant tool-call turns plus
toolresults. - JSON envelope mode: the action-invocation and result annotations the loop already writes.
Interleaving with the conversation text
Each earlier root run is tied to the AI reply it produced; the cache already tracks the reply detail ID. Insert that run's turn record immediately before its reply message.
- Runs whose reply row was replaced, or that sit off the current branch, are skipped.
- Turns before a compaction boundary are covered by
SummaryOfEarlierConversationand are not replayed.
Two ways to find earlier runs
- By
conversationId, when MJ owns the conversation (MJ's own chat). This works likeinjectPriorTurnToolResultsdoes today, but across more than one earlier turn. - By the
lastRunIdchain, when the caller suppliesconversationMessagesitself because the conversation lives in another system or database. WalkLastRunIDback up toPriorTurnReplayMaxTurnsruns. External hosts can't use theconversationIdpath today, because the ConversationDetail rows aren't in the agent's database.
Limits and prompt caching
- Limits:
PriorTurnReplayMaxTurns, plus a token budget. When the budget is exceeded, the oldest replayed turns drop first, then compaction takes over. - Caching: replay is append-only from turn to turn, so the cached prefix stays stable. Clear old results in batches, so the prefix changes once per batch rather than every turn (the same idea as
clear_at_leastin Anthropic's context editing).
Out of scope
- Replaying sub-agent internals.
- Replaying thinking across turns.
- Changing how ConversationDetail text history is windowed.
Tests
ToolCallspolicy over a three-turn conversation: delegations and briefs from turns 1 and 2 are present on turn 3, and results older than the keep window are cleared.- A replaced reply row and an off-branch run are both excluded.
- The
lastRunIdchain path works with caller-suppliedconversationMessagesand noconversationId. - With the default policy (
ReadToolResults), behavior is unchanged. - The rendered prefix is byte-identical between two consecutive turns, apart from the appended turn.
Motivation and backport
This comes from Skip, an external host that runs its agents on its own MJ instance while the conversation lives in the client's MJ database. Skip is redesigning its top-level orchestrator as a Loop agent. It needs the lastRunId chain path and the ToolCalls policy. Skip is on the 6.2 LTS line, so a backport to lts/6.2 would be very helpful if the change is small enough to qualify.
🤖 Generated with Claude Code
- Lingua principale
- TSQL
- Stelle
- 32
- Fork
- 7
- Merge medio
- 1g 16h
- PR unite (30g)
- 504
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di MemberJunction/MJ
-
DBAutoDoc: export --state-file writes SQL Server SQL for a PostgreSQL database, ignoring --providerAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
MemberJunction/MJ#7094 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
MemberJunction/MJ#6971 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
MemberJunction/MJ#6947 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MemberJunction/MJ#6800 ·
I maintainer di solito rispondono entro 1 giorno
-
Convention: saved-query discoverability follows Status — Approved is canon, Pending is a draftAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
MemberJunction/MJ#6746 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di MemberJunction/MJ
Issue simili
-
[Feature]: Skill Workshop skill diet should use the configured utility model, not always the primaryApertaclawsweeper:fix-shape-clear clawsweeper:needs-live-repro clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr impact:auth-provider issue-rating: 🐚 platinum hermit P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
openclaw/openclaw#210348 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
ai-generated tests
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
danielmiessler/LifeOS#3121 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
diegosouzapw/OmniRoute#21908 ·
-
bug help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100