From addbdcb0ef1c2b8fb99f90d6ece66dde1f050570 Mon Sep 17 00:00:00 2001 From: tanzhenxin Date: Tue, 10 Mar 2026 20:37:08 +0800 Subject: [PATCH] feat(arena): add info message for forwarded chat history - Add info message when chatHistory is passed to spawned agents - Add tests for info message presence and absence This provides visibility to users when chat history context is included in spawned agent sessions. Co-authored-by: Qwen-Coder --- .../agents/runtime/agent-interactive.test.ts | 31 +++++++++++++++++++ .../src/agents/runtime/agent-interactive.ts | 7 +++++ 2 files changed, 38 insertions(+) diff --git a/packages/core/src/agents/runtime/agent-interactive.test.ts b/packages/core/src/agents/runtime/agent-interactive.test.ts index 40ed6f3c1..2683a6783 100644 --- a/packages/core/src/agents/runtime/agent-interactive.test.ts +++ b/packages/core/src/agents/runtime/agent-interactive.test.ts @@ -554,6 +554,37 @@ describe('AgentInteractive', () => { await agent.shutdown(); }); + it('should add info message when chatHistory is present', async () => { + const { core } = createMockCore(); + const chatHistory = [ + { role: 'user' as const, parts: [{ text: 'earlier question' }] }, + { role: 'model' as const, parts: [{ text: 'earlier answer' }] }, + ]; + const agent = new AgentInteractive(createConfig({ chatHistory }), core); + + await agent.start(context); + + const messages = agent.getMessages(); + expect(messages).toHaveLength(1); + expect(messages[0]).toMatchObject({ + role: 'info', + content: 'History context from parent session included (2 messages)', + }); + + await agent.shutdown(); + }); + + it('should not add info message when chatHistory is absent', async () => { + const { core } = createMockCore(); + const agent = new AgentInteractive(createConfig(), core); + + await agent.start(context); + + expect(agent.getMessages()).toHaveLength(0); + + await agent.shutdown(); + }); + it('should pass undefined extraHistory when chatHistory is not set', async () => { const { core } = createMockCore(); const config = createConfig(); diff --git a/packages/core/src/agents/runtime/agent-interactive.ts b/packages/core/src/agents/runtime/agent-interactive.ts index 5abc035dd..c7883f669 100644 --- a/packages/core/src/agents/runtime/agent-interactive.ts +++ b/packages/core/src/agents/runtime/agent-interactive.ts @@ -111,6 +111,13 @@ export class AgentInteractive { this.toolsList = this.core.prepareTools(); this.core.stats.start(Date.now()); + if (this.config.chatHistory?.length) { + this.addMessage( + 'info', + `History context from parent session included (${this.config.chatHistory.length} messages)`, + ); + } + if (this.config.initialTask) { this.queue.enqueue(this.config.initialTask); this.executionPromise = this.runLoop();