Skip to content

fix(chat): pass conversation history to agent for multi-turn memory#592

Open
behealthy28 wants to merge 1 commit into
open-jarvis:mainfrom
behealthy28:fix/chat-multiturn-history
Open

fix(chat): pass conversation history to agent for multi-turn memory#592
behealthy28 wants to merge 1 commit into
open-jarvis:mainfrom
behealthy28:fix/chat-multiturn-history

Conversation

@behealthy28

Copy link
Copy Markdown

Bug: jarvis chat is stateless across turns when an agent is active

Summary

In jarvis chat, multi-turn memory is lost whenever an agent (e.g. the default simple agent) is active. Each turn is answered in isolation — the model never sees prior turns.

Reproduction

$ jarvis chat            # default agent = simple
You> What is 17 times 3?
17 times 3 is 51.
You> Now add 9 to that.
I see you want me to add 9 to something. Could you please specify what you want me to add 9 to?

Expected: "60". The model has no access to the previous turn.

Root cause

src/openjarvis/cli/chat_cmd.py maintains a history: List[Message] and appends each user/assistant turn, but the agent branch calls:

response = agent.run(user_input)        # no context passed

BaseAgent._build_messages(input, context) only includes prior conversation when context.conversation.messages is 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 AgentContext from the prior history (excluding the just-appended user turn, which _build_messages re-adds from input) and pass it to agent.run:

from openjarvis.agents._stubs import AgentContext
ctx = AgentContext(conversation=Conversation(messages=list(history[:-1])))
response = agent.run(user_input, context=ctx)

Verified: with the patch, the default simple agent chains correctly — 51 → 60 → 120 — and agent tools remain available.

Environment

  • OpenJarvis main (post v1.0.3.dev857)
  • macOS, Apple M1, engine = mlx (mlx_lm.server), model mlx-community/Qwen2.5-3B-Instruct-4bit
  • Behavior is engine-independent (logic bug in chat_cmd.py)

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.
@behealthy28 behealthy28 force-pushed the fix/chat-multiturn-history branch from 34fd898 to c408eff Compare June 25, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants