Skip to content

[BUG] clone() drops the parent's message window: no memory class exposes a public window_size #4360

Description

@ebarkhordar

Required prerequisites

  • I have read the documentation.
  • I have searched the Issue Tracker and Discussions and this has not already been reported.

What version of camel are you using?

0.2.91a7 (master fc27907e)

System information

Source checkout of master fc27907e, Python 3.11.16 on Linux, python:3.11-slim container, deps installed with pip.

Problem description

ChatAgent.clone() builds the new agent with message_window_size=getattr(self.memory, "window_size", None) (camel/agents/chat_agent.py:6233). ChatHistoryMemory stores the window as self._window_size and only exposes agent_id as a property, so there is no public window_size to read and that getattr always takes its default. Every clone comes back with an unbounded window.

The line right below it does resolve, which is what makes this look like an oversight rather than a decision: token_limit=getattr(self.memory.get_context_creator(), "token_limit", None) reads a real property on ScoreBasedContextCreator.

CriticAgent.clone() is the worse one. Its default is 6 (camel/agents/critic_agent.py:250), so a critic built with message_window_size=3 clones into a critic with a window of 6.

Five call sites read the same missing attribute: chat_agent.py:6233, critic_agent.py:250, toolkits/agent_toolkit.py:179, societies/workforce/workforce.py:447 and :514. That is the complete set from an ast walk over camel/ for getattr(_, "window_size", _), and the same walk finds no def window_size and no self.window_size = ... anywhere in the package.

Reproducible example code

The Python snippets:

from camel.agents import ChatAgent, CriticAgent

a = ChatAgent("You are helpful.", message_window_size=2)
print(a.memory._window_size)                                   # 2
print(getattr(a.memory, "window_size", "DEFAULT_RETURNED"))    # DEFAULT_RETURNED
print(a.clone().memory._window_size)                           # None
print(a.clone(with_memory=True).memory._window_size)           # None

c = CriticAgent("You are a critic.", message_window_size=3)
print(c.clone().memory._window_size)                           # 6

Command lines:

OPENAI_API_KEY=sk-dummy python repro.py

Extra dependencies:

none beyond a source checkout

Steps to reproduce:

  1. Check out master fc27907e.
  2. Run the snippet above.
  3. The parent has a window of 2 and both clones report None.

Expected behavior

clone() keeps the parent's message window, the way it already keeps token_limit.

Additional context

A read-only window_size property on ChatHistoryMemory returning self._window_size repairs all five call sites at once, and MemantoMemory inherits it. VectorDBMemory and LongtermAgentMemory take no window argument, so the None default stays correct for them. I have that change and its tests ready and will open the PR against this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions