Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def notify_event_received(self, request_id: str) -> None:
self.input_events[request_id].set()
else:
event = asyncio.Event()
event.set()
self.input_events[request_id] = event


Expand Down
15 changes: 15 additions & 0 deletions python/packages/autogen-agentchat/tests/test_userproxy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from autogen_agentchat.agents import UserProxyAgent
from autogen_agentchat.base import Response
from autogen_agentchat.messages import BaseChatMessage, HandoffMessage, TextMessage
from autogen_agentchat.ui import Console, UserInputManager
from autogen_core import CancellationToken


Expand Down Expand Up @@ -118,3 +119,17 @@ def failing_input(_: str) -> str:
with pytest.raises(RuntimeError) as exc_info:
await agent.on_messages(messages, CancellationToken())
assert "Failed to get user input" in str(exc_info.value)


@pytest.mark.asyncio
async def test_console_user_input_manager_handles_event_before_input_waiter() -> None:
manager = UserInputManager(lambda _: "console response")
agent = UserProxyAgent(name="test_user", input_func=manager.get_wrapped_callback())

response = await asyncio.wait_for(
Console(agent.on_messages_stream([], CancellationToken()), user_input_manager=manager),
timeout=1,
)

assert isinstance(response.chat_message, TextMessage)
assert response.chat_message.content == "console response"