Skip to content

Commit

Permalink
Merge branch 'main' into remove_deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits authored Dec 30, 2024
2 parents 2d8e6ad + 5ee2190 commit 1e87058
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 87 deletions.
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 @@ -72,40 +71,47 @@ class AssistantAgent(BaseChatAgent):
the inner messages as they are created, and the :class:`~autogen_agentchat.base.Response`
object as the last item before closing the generator.
.. note::
The caller must only pass the new messages to the agent on each call
to the :meth:`on_messages` or :meth:`on_messages_stream` method.
The agent maintains its state between calls to these methods.
Do not pass the entire conversation history to the agent on each call.
.. note::
The assistant agent is not thread-safe or coroutine-safe.
It should not be shared between multiple tasks or coroutines, and it should
not call its methods concurrently.
Tool call behavior:
* If the model returns no tool call, then the response is immediately returned as a :class:`~autogen_agentchat.messages.TextMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`.
* When the model returns tool calls, they will be executed right away:
- When `reflect_on_tool_use` is False (default), the tool call results are returned as a :class:`~autogen_agentchat.messages.ToolCallSummaryMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`. `tool_call_summary_format` can be used to customize the tool call summary.
- When `reflect_on_tool_use` is True, the another model inference is made using the tool calls and results, and the text response is returned as a :class:`~autogen_agentchat.messages.TextMessage` in :attr:`~autogen_agentchat.base.Response.chat_message`.
.. note::
By default, the tool call results are returned as response when tool calls are made.
So it is recommended to pay attention to the formatting of the tools return values,
especially if another agent is expecting them in a specific format.
Use `tool_call_summary_format` to customize the tool call summary, if needed.
Hand off behavior:
* If a handoff is triggered, a :class:`~autogen_agentchat.messages.HandoffMessage` will be returned in :attr:`~autogen_agentchat.base.Response.chat_message`.
* If there are tool calls, they will also be executed right away before returning the handoff.
.. note::
The assistant agent is not thread-safe or coroutine-safe.
It should not be shared between multiple tasks or coroutines, and it should
not call its methods concurrently.
If multiple handoffs are detected, only the first handoff is executed.
.. note::
By default, the tool call results are returned as response when tool calls are made.
So it is recommended to pay attention to the formatting of the tools return values,
especially if another agent is expecting them in a specific format.
Use `tool_call_summary_format` to customize the tool call summary, if needed.
.. note::
If multiple handoffs are detected, only the first handoff is executed.
Limit context size sent to the model:
You can limit the number of messages sent to the model by setting
the `model_context` parameter to a :class:`~autogen_core.model_context.BufferedChatCompletionContext`.
This will limit the number of recent messages sent to the model and can be useful
when the model has a limit on the number of tokens it can process.
Args:
Expand Down Expand Up @@ -305,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
Loading

0 comments on commit 1e87058

Please sign in to comment.