Skip to content

Python: Rejected system messages leave AgentChat permanently active #14638

Open

Description

@March-7

AgentChat.add_chat_messages() sets its activity signal before validating message roles. If it rejects a system message, it raises before entering the try/finally that clears the signal. After the caller catches this validation error, the same AgentGroupChat cannot accept a corrected message, read its history, or reset: each operation reports that another agent is active.

Reproduced against current main, commit 25501830b9483ad6b23955dee340c8590fa54152, with Python 3.12.13 on macOS arm64:

import asyncio

from semantic_kernel.agents import AgentGroupChat
from semantic_kernel.contents import ChatMessageContent
from semantic_kernel.contents.utils.author_role import AuthorRole
from semantic_kernel.exceptions.agent_exceptions import AgentChatException


async def main():
    chat = AgentGroupChat()
    await chat.add_chat_message("seed")

    try:
        await chat.add_chat_message(
            ChatMessageContent(role=AuthorRole.SYSTEM, content="unsupported")
        )
    except AgentChatException:
        pass

    print(chat.is_active)  # True, although no operation is running
    await chat.add_chat_message("corrected input")
    # Exception: Unable to proceed while another agent is active.


asyncio.run(main())

Expected behavior: keep rejecting system messages, preserve the existing history, and release the activity signal so the caller can recover. A mixed user/system batch is correctly rejected without partially appending the user message, but it leaves the same stuck activity signal.

The existing test_add_chat_messages_throws_exception_for_system_role checks the rejection but does not check recovery. The existing group-chat and strategy tests pass (77 tests) while six real-API rejection/recovery scenarios reproduce the problem and three valid-message controls succeed. These checks require no model or provider API.

I would like to take on a small fix that keeps role validation inside the activity cleanup scope, with regression coverage for history preservation and recovery. The activity acquisition would remain outside the try so a rejected competing operation cannot release another operation's signal. Is this correction still welcome in the legacy group-chat API given the Agent Framework migration?

This issue and the offline reproduction were prepared with Codex assistance. No implementation patch has been submitted.

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

    pythonPull requests for the Python Semantic Kerneltriage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions