Skip to content

Python: Bug: Restoring AgentGroupChat state using history does not restore history in individual agents #12095

Closed
@matthiasblondeel

Description

@matthiasblondeel

Describe the bug
In SK version 1.20 it was possible to initialize a AgentGroupChat and passing in a previously used ChatHistory. All agents would then have the shared context/history when participating in the AgentGroupChat.

We run SK in a stateless webserver, where between each call, we store the history in a DB, then reload the history on the next call, to recreate a AgentGroupChat (restoring state).

In SK version 1.29 this no longer works, and while the AgentGroupChat itself has the full history, and the channels have the messages, it appears the thread on each individual agent no longer has the history of messages.

To Reproduce

history = ChatHistory()

history.add_user_message("Message a")
history.add_user_message("Message b")
history.add_user_message("Message c")
history.add_user_message("Message d")

agent1 = ChatCompletionAgent(kernel=kernel,
                             name="agent1",
                             instructions="You are a helpful assistant. How many messages are in the chat history?",)
chat = AgentGroupChat(
        agents=[agent1],
        chat_history=history,        
    )

async for response in chat.invoke(agent=agent1):
        print(f"# {response.role} - {response.name or '*'}: '{response.content}'")
for key,value in chat.agent_channels.items():
    print(f"key: {key}, thread messages: {len(value.thread._chat_history.messages)}, history messages: {len(value.messages)}")

Output:

# AuthorRole.ASSISTANT - agent1: 'There are two messages in the chat history prior to this response:

1. Your first message: "How many messages are in the chat history?"
2. Your second message: "Message d"

Including this response, there are now three messages in total.'
key: fr6BCLq1QJaqCSUrtvW/ei/WBkg6qB/FWaJdwa6Ioro=, thread messages: 2, history messages: 5

Expected behavior
In previous versions of semantic kernel, the full chat history would be restored and available to each agent

Screenshots
If applicable, add screenshots to help explain your problem.

Platform

  • Language: Python
  • Source: pip package 1.29.0
  • AI model: gpt4.1
  • IDE: VS Code
  • OS: WSL

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpythonPull requests for the Python Semantic Kerneltriage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions