Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Tuple[type[ChatMessage], ...] with Sequence[type[ChatMessage]] #4857

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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 @@ -11,7 +11,6 @@
List,
Mapping,
Sequence,
Tuple,
)

from autogen_core import CancellationToken, FunctionCall
Expand Down Expand Up @@ -312,7 +311,7 @@ def __init__(
self._is_running = False

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
"""The types of messages that the assistant agent produces."""
message_types: List[type[ChatMessage]] = [TextMessage]
if self._handoffs:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Any, AsyncGenerator, List, Mapping, Sequence, Tuple
from typing import Any, AsyncGenerator, List, Mapping, Sequence

from autogen_core import CancellationToken

Expand Down Expand Up @@ -56,7 +56,7 @@ def description(self) -> str:

@property
@abstractmethod
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
"""The types of messages that the agent produces in the
:attr:`Response.chat_message` field. They must be :class:`ChatMessage` types."""
...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import List, Sequence, Tuple
from typing import List, Sequence

from autogen_core import CancellationToken
from autogen_core.code_executor import CodeBlock, CodeExecutor
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(
self._code_executor = code_executor

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
"""The types of messages that the code executor agent produces."""
return (TextMessage,)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, AsyncGenerator, List, Mapping, Sequence, Tuple
from typing import Any, AsyncGenerator, List, Mapping, Sequence

from autogen_core import CancellationToken
from autogen_core.models import ChatCompletionClient, LLMMessage, SystemMessage, UserMessage
Expand Down Expand Up @@ -103,7 +103,7 @@ def __init__(
self._response_prompt = response_prompt

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
return (TextMessage,)

async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from inspect import iscoroutinefunction
from typing import Awaitable, Callable, Optional, Sequence, Tuple, Union, cast
from typing import Awaitable, Callable, Optional, Sequence, Union, cast

from aioconsole import ainput # type: ignore
from autogen_core import CancellationToken
Expand Down Expand Up @@ -122,7 +122,7 @@ def __init__(
self._is_async = iscoroutinefunction(self.input_func)

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
"""Message types this agent can produce."""
return (TextMessage, HandoffMessage)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, AsyncGenerator, Mapping, Protocol, Sequence, Tuple, runtime_checkable
from typing import Any, AsyncGenerator, Mapping, Protocol, Sequence, runtime_checkable

from autogen_core import CancellationToken

Expand Down Expand Up @@ -37,7 +37,7 @@ def description(self) -> str:
...

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
"""The types of messages that the agent produces in the
:attr:`Response.chat_message` field. They must be :class:`ChatMessage` types."""
...
Expand Down
8 changes: 4 additions & 4 deletions python/packages/autogen-agentchat/tests/test_group_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import logging
import tempfile
from typing import Any, AsyncGenerator, List, Sequence, Tuple
from typing import Any, AsyncGenerator, List, Sequence

import pytest
from autogen_agentchat import EVENT_LOGGER_NAME
Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(self, name: str, description: str) -> None:
self._total_messages = 0

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
return (TextMessage,)

@property
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(self, name: str, description: str, *, stop_at: int = 1) -> None:
self._stop_at = stop_at

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
return (TextMessage, StopMessage)

async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:
Expand Down Expand Up @@ -797,7 +797,7 @@ def __init__(self, name: str, description: str, next_agent: str) -> None:
self._next_agent = next_agent

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
return (HandoffMessage,)

async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import json
import logging
from typing import Sequence, Tuple
from typing import Sequence

import pytest
from autogen_agentchat import EVENT_LOGGER_NAME
Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(self, name: str, description: str) -> None:
self._total_messages = 0

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
return (TextMessage,)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
" self._count = count\n",
"\n",
" @property\n",
" def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:\n",
" def produced_message_types(self) -> Sequence[type[ChatMessage]]:\n",
" return (TextMessage,)\n",
"\n",
" async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:\n",
Expand Down Expand Up @@ -130,7 +130,7 @@
"metadata": {},
"outputs": [],
"source": [
"from typing import Callable, Sequence, Tuple\n",
"from typing import Callable, Sequence\n",
"\n",
"from autogen_agentchat.agents import BaseChatAgent\n",
"from autogen_agentchat.base import Response\n",
Expand All @@ -149,7 +149,7 @@
" self._message_history: List[ChatMessage] = []\n",
"\n",
" @property\n",
" def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:\n",
" def produced_message_types(self) -> Sequence[type[ChatMessage]]:\n",
" return (TextMessage,)\n",
"\n",
" async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:\n",
Expand Down Expand Up @@ -310,4 +310,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(
self._browser = MarkdownFileBrowser(viewport_size=1024 * 5)

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
return (TextMessage,)

async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> Response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Optional,
Sequence,
Set,
Tuple,
Union,
cast,
)
Expand Down Expand Up @@ -299,7 +298,7 @@ async def _retrieve_initial_state(self) -> None:
self._initial_message_ids = initial_message_ids

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
"""The types of messages that the assistant agent produces."""
return (TextMessage,)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
List,
Optional,
Sequence,
Tuple,
cast,
)
from urllib.parse import quote_plus
Expand Down Expand Up @@ -322,7 +321,7 @@ async def _set_debug_dir(self, debug_dir: str | None) -> None:
)

@property
def produced_message_types(self) -> Tuple[type[ChatMessage], ...]:
def produced_message_types(self) -> Sequence[type[ChatMessage]]:
return (MultiModalMessage,)

async def on_reset(self, cancellation_token: CancellationToken) -> None:
Expand Down
Loading