fix(chat): pass conversation history to agent for multi-turn memory#592
Open
behealthy28 wants to merge 1 commit into
Open
fix(chat): pass conversation history to agent for multi-turn memory#592behealthy28 wants to merge 1 commit into
behealthy28 wants to merge 1 commit into
Conversation
chat_cmd invoked agent.run(user_input) with no context, so when any agent was active every turn was stateless (the REPL's history list was never handed to the agent). Build an AgentContext from prior history (excluding the just-appended user turn, which _build_messages re-adds) so agents see past turns. The no-agent path already passed full history.
34fd898 to
c408eff
Compare
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.
Bug:
jarvis chatis stateless across turns when an agent is activeSummary
In
jarvis chat, multi-turn memory is lost whenever an agent (e.g. the defaultsimpleagent) is active. Each turn is answered in isolation — the model never sees prior turns.Reproduction
Expected: "60". The model has no access to the previous turn.
Root cause
src/openjarvis/cli/chat_cmd.pymaintains ahistory: List[Message]and appends each user/assistant turn, but the agent branch calls:BaseAgent._build_messages(input, context)only includes prior conversation whencontext.conversation.messagesis populated. With no context, every call is single-turn. The no-agent branch (engine.generate(history, ...)) already passes full history, so the bug only manifests when an agent is configured — which is the default.Fix
Build an
AgentContextfrom the prior history (excluding the just-appended user turn, which_build_messagesre-adds frominput) and pass it toagent.run:Verified: with the patch, the default
simpleagent chains correctly — 51 → 60 → 120 — and agent tools remain available.Environment
mlx_lm.server), modelmlx-community/Qwen2.5-3B-Instruct-4bitchat_cmd.py)