Skip to content

Commit

Permalink
Merge branch 'main' into list_messages_support
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhu authored Dec 4, 2024
2 parents 7ce97dc + 8b05e03 commit 65f9bcb
Show file tree
Hide file tree
Showing 207 changed files with 1,581 additions and 1,203 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<div align="center">
<img src="https://microsoft.github.io/autogen/0.2/img/ag.svg" alt="AutoGen Logo" width="100">

[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Follow%20%40pyautogen)](https://twitter.com/pyautogen) [![GitHub Discussions](https://img.shields.io/badge/Discussions-Q%26A-green?logo=github)](https://github.com/microsoft/autogen/discussions) [![0.2 Docs](https://img.shields.io/badge/Docs-0.2-blue)](https://microsoft.github.io/autogen/0.2/) [![0.4 Docs](https://img.shields.io/badge/Docs-0.4-blue)](https://microsoft.github.io/autogen/dev/)
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Follow%20%40pyautogen)](https://twitter.com/pyautogen) [![LinkedIn](https://img.shields.io/badge/LinkedIn-Company?style=flat&logo=linkedin&logoColor=white)](https://www.linkedin.com/company/105812540)
[![GitHub Discussions](https://img.shields.io/badge/Discussions-Q%26A-green?logo=github)](https://github.com/microsoft/autogen/discussions) [![0.2 Docs](https://img.shields.io/badge/Docs-0.2-blue)](https://microsoft.github.io/autogen/0.2/) [![0.4 Docs](https://img.shields.io/badge/Docs-0.4-blue)](https://microsoft.github.io/autogen/dev/)
[![PyPi autogen-core](https://img.shields.io/badge/PyPi-autogen--core-blue?logo=pypi)](https://pypi.org/project/autogen-core/0.4.0.dev8/) [![PyPi autogen-agentchat](https://img.shields.io/badge/PyPi-autogen--agentchat-blue?logo=pypi)](https://pypi.org/project/autogen-agentchat/0.4.0.dev8/) [![PyPi autogen-ext](https://img.shields.io/badge/PyPi-autogen--ext-blue?logo=pypi)](https://pypi.org/project/autogen-ext/0.4.0.dev8/)

</div>
Expand Down Expand Up @@ -115,7 +116,8 @@ To use Azure OpenAI models, follow the instruction
```python
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.task import Console, TextMentionTermination
from autogen_agentchat.ui import Console
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models import OpenAIChatCompletionClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

from typing import List

from autogen_core.base import AgentId, AgentProxy, TopicId
from autogen_core import AgentId, AgentProxy, TopicId
from autogen_core.application import SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.components.models import (
ChatCompletionClient,
UserMessage,
LLMMessage,
)
from autogen_core.components import DefaultSubscription, DefaultTopicId
from autogen_core import DefaultSubscription, DefaultTopicId
from autogen_core.components.code_executor import LocalCommandLineCodeExecutor
from autogen_core.components.models import AssistantMessage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from typing import List

from autogen_core.base import AgentId, AgentProxy, TopicId
from autogen_core import AgentId, AgentProxy, TopicId
from autogen_core.application import SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.components.models import (
Expand All @@ -17,7 +17,7 @@
UserMessage,
LLMMessage,
)
from autogen_core.components import DefaultSubscription, DefaultTopicId
from autogen_core import DefaultSubscription, DefaultTopicId
from autogen_core.components.code_executor import LocalCommandLineCodeExecutor
from autogen_core.components.models import AssistantMessage

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import logging

from autogen_core.base import AgentId, AgentProxy, TopicId
from autogen_core import AgentId, AgentProxy, TopicId
from autogen_core.application import SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.components import DefaultSubscription, DefaultTopicId
from autogen_core import DefaultSubscription, DefaultTopicId
from autogen_core.components.code_executor import LocalCommandLineCodeExecutor
from autogen_core.components.models import (
UserMessage,
Expand Down Expand Up @@ -41,7 +41,7 @@ async def main() -> None:
executor = AgentProxy(AgentId("Executor", "default"), runtime)

await runtime.register(
"Orchestrator",
"Orchestrator",
lambda: RoundRobinOrchestrator([coder, executor]),
subscriptions=lambda: [DefaultSubscription()],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from typing import Any, Dict, List, Tuple, Union

from autogen_core.base import AgentId, AgentProxy, TopicId
from autogen_core import AgentId, AgentProxy, TopicId
from autogen_core.application import SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.components import DefaultSubscription, DefaultTopicId
from autogen_core import DefaultSubscription, DefaultTopicId
from autogen_core.components.code_executor import LocalCommandLineCodeExecutor
from autogen_core.components.models import (
ChatCompletionClient,
Expand Down Expand Up @@ -105,7 +105,7 @@ async def main() -> None:
task_prompt = task_prompt.replace(k, REPLACEMENTS[k])
fh.write(task_prompt)
TASK = json.loads(task_prompt)
if TASK["start_url"] == REDDIT:
if TASK["start_url"] == REDDIT:
TASK["start_url"] = TASK["start_url"] + "/forums/all"

full_task = ""
Expand Down Expand Up @@ -150,7 +150,7 @@ async def main() -> None:

# Round-robin orchestrator
await runtime.register(
"round_robin_orc",
"round_robin_orc",
lambda: RoundRobinOrchestrator(agents=[web_surfer, login_assistant],),
subscriptions=lambda: [DefaultSubscription()],
)
Expand All @@ -163,7 +163,7 @@ async def main() -> None:

runtime.start()
await runtime.publish_message(
ResetMessage(),
ResetMessage(),
topic_id=DefaultTopicId(),
)
await runtime.publish_message(
Expand Down Expand Up @@ -192,16 +192,16 @@ async def main() -> None:
subscriptions=lambda: [DefaultSubscription()],
)
executor = AgentProxy(AgentId("ComputerTerminal", "default"), runtime)

await runtime.register(
"FileSurfer",
lambda: FileSurfer(model_client=client),
subscriptions=lambda: [DefaultSubscription()],
)
file_surfer = AgentProxy(AgentId("FileSurfer", "default"), runtime)

await runtime.register(
"orchestrator",
"orchestrator",
lambda: LedgerOrchestrator(
agents=[coder, executor, file_surfer, web_surfer],
model_client=client,
Expand Down Expand Up @@ -251,7 +251,7 @@ async def main() -> None:
page = actual_surfer._page
cdp_session = await context.new_cdp_session(page)
config_file = "full_task.json"

evaluator = evaluation_harness.evaluator_router(config_file)
score = await evaluator(
trajectory=evaluation_harness.make_answer_trajecotry(final_answer),
Expand All @@ -260,7 +260,7 @@ async def main() -> None:
client=cdp_session,
# azure_config=llm_config,
)

print("FINAL SCORE: " + str(score))


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._assistant_agent import AssistantAgent, Handoff
from ._assistant_agent import AssistantAgent, Handoff # type: ignore
from ._base_chat_agent import BaseChatAgent
from ._code_executor_agent import CodeExecutorAgent
from ._coding_assistant_agent import CodingAssistantAgent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import json
import logging
import warnings
from typing import Any, AsyncGenerator, Awaitable, Callable, Dict, List, Sequence

from autogen_core.base import CancellationToken
from autogen_core.components import FunctionCall
from autogen_core import CancellationToken, FunctionCall
from autogen_core.components.models import (
AssistantMessage,
ChatCompletionClient,
Expand All @@ -15,9 +15,10 @@
UserMessage,
)
from autogen_core.components.tools import FunctionTool, Tool
from pydantic import BaseModel, Field, model_validator
from typing_extensions import deprecated

from .. import EVENT_LOGGER_NAME
from ..base import Handoff as HandoffBase
from ..base import Response
from ..messages import (
AgentMessage,
Expand All @@ -33,51 +34,16 @@
event_logger = logging.getLogger(EVENT_LOGGER_NAME)


class Handoff(BaseModel):
"""Handoff configuration for :class:`AssistantAgent`."""
@deprecated("Moved to autogen_agentchat.base.Handoff. Will remove in 0.4.0.", stacklevel=2)
class Handoff(HandoffBase):
"""[DEPRECATED] Handoff configuration. Moved to :class:`autogen_agentchat.base.Handoff`. Will remove in 0.4.0."""

target: str
"""The name of the target agent to handoff to."""

description: str = Field(default=None)
"""The description of the handoff such as the condition under which it should happen and the target agent's ability.
If not provided, it is generated from the target agent's name."""

name: str = Field(default=None)
"""The name of this handoff configuration. If not provided, it is generated from the target agent's name."""

message: str = Field(default=None)
"""The message to the target agent.
If not provided, it is generated from the target agent's name."""

@model_validator(mode="before")
@classmethod
def set_defaults(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if values.get("description") is None:
values["description"] = f"Handoff to {values['target']}."
if values.get("name") is None:
values["name"] = f"transfer_to_{values['target']}".lower()
else:
name = values["name"]
if not isinstance(name, str):
raise ValueError(f"Handoff name must be a string: {values['name']}")
# Check if name is a valid identifier.
if not name.isidentifier():
raise ValueError(f"Handoff name must be a valid identifier: {values['name']}")
if values.get("message") is None:
values["message"] = (
f"Transferred to {values['target']}, adopting the role of {values['target']} immediately."
)
return values

@property
def handoff_tool(self) -> Tool:
"""Create a handoff tool from this handoff configuration."""

def _handoff_tool() -> str:
return self.message

return FunctionTool(_handoff_tool, name=self.name, description=self.description)
def model_post_init(self, __context: Any) -> None:
warnings.warn(
"Handoff was moved to autogen_agentchat.base.Handoff. Importing from this will be removed in 0.4.0.",
DeprecationWarning,
stacklevel=2,
)


class AssistantAgent(BaseChatAgent):
Expand All @@ -87,7 +53,7 @@ class AssistantAgent(BaseChatAgent):
name (str): The name of the agent.
model_client (ChatCompletionClient): The model client to use for inference.
tools (List[Tool | Callable[..., Any] | Callable[..., Awaitable[Any]]] | None, optional): The tools to register with the agent.
handoffs (List[Handoff | str] | None, optional): The handoff configurations for the agent,
handoffs (List[HandoffBase | str] | None, optional): The handoff configurations for the agent,
allowing it to transfer to other agents by responding with a :class:`HandoffMessage`.
The transfer is only executed when the team is in :class:`~autogen_agentchat.teams.Swarm`.
If a handoff is a string, it should represent the target agent's name.
Expand All @@ -107,7 +73,7 @@ class AssistantAgent(BaseChatAgent):
.. code-block:: python
import asyncio
from autogen_core.base import CancellationToken
from autogen_core import CancellationToken
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
Expand Down Expand Up @@ -139,8 +105,8 @@ async def main() -> None:
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from autogen_agentchat.task import Console
from autogen_core.base import CancellationToken
from autogen_agentchat.ui import Console
from autogen_core import CancellationToken
async def get_current_time() -> str:
Expand Down Expand Up @@ -169,7 +135,7 @@ async def main() -> None:
.. code-block:: python
import asyncio
from autogen_core.base import CancellationToken
from autogen_core import CancellationToken
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
Expand Down Expand Up @@ -204,7 +170,7 @@ def __init__(
model_client: ChatCompletionClient,
*,
tools: List[Tool | Callable[..., Any] | Callable[..., Awaitable[Any]]] | None = None,
handoffs: List[Handoff | str] | None = None,
handoffs: List[HandoffBase | str] | None = None,
description: str = "An agent that provides assistance with ability to use tools.",
system_message: str
| None = "You are a helpful AI assistant. Solve tasks using your tools. Reply with TERMINATE when the task has been completed.",
Expand Down Expand Up @@ -236,14 +202,14 @@ def __init__(
raise ValueError(f"Tool names must be unique: {tool_names}")
# Handoff tools.
self._handoff_tools: List[Tool] = []
self._handoffs: Dict[str, Handoff] = {}
self._handoffs: Dict[str, HandoffBase] = {}
if handoffs is not None:
if model_client.capabilities["function_calling"] is False:
raise ValueError("The model does not support function calling, which is needed for handoffs.")
for handoff in handoffs:
if isinstance(handoff, str):
handoff = Handoff(target=handoff)
if isinstance(handoff, Handoff):
handoff = HandoffBase(target=handoff)
if isinstance(handoff, HandoffBase):
self._handoff_tools.append(handoff.handoff_tool)
self._handoffs[handoff.name] = handoff
else:
Expand Down Expand Up @@ -312,7 +278,7 @@ async def on_messages_stream(
yield tool_call_result_msg

# Detect handoff requests.
handoffs: List[Handoff] = []
handoffs: List[HandoffBase] = []
for call in result.content:
if call.name in self._handoffs:
handoffs.append(self._handoffs[call.name])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from typing import AsyncGenerator, List, Sequence

from autogen_core.base import CancellationToken
from autogen_core import CancellationToken

from ..base import ChatAgent, Response, TaskResult
from ..messages import AgentMessage, ChatMessage, HandoffMessage, MultiModalMessage, StopMessage, TextMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Sequence

from autogen_core.base import CancellationToken
from autogen_core import CancellationToken
from autogen_core.components.code_executor import CodeBlock, CodeExecutor, extract_markdown_code_blocks

from ..base import Response
Expand Down Expand Up @@ -28,7 +28,7 @@ class CodeExecutorAgent(BaseChatAgent):
from autogen_agentchat.agents import CodeExecutorAgent
from autogen_agentchat.messages import TextMessage
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_core.base import CancellationToken
from autogen_core import CancellationToken
async def run_code_executor_agent() -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import AsyncGenerator, List, Sequence

from autogen_core.base import CancellationToken
from autogen_core.components import Image
from autogen_core import CancellationToken, Image
from autogen_core.components.models import ChatCompletionClient
from autogen_core.components.models._types import SystemMessage

Expand Down Expand Up @@ -43,7 +42,7 @@ class SocietyOfMindAgent(BaseChatAgent):
from autogen_agentchat.agents import AssistantAgent, SocietyOfMindAgent
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.task import MaxMessageTermination
from autogen_agentchat.conditions import MaxMessageTermination
async def main() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from inspect import iscoroutinefunction
from typing import Awaitable, Callable, List, Optional, Sequence, Union, cast

from autogen_core.base import CancellationToken
from autogen_core import CancellationToken

from ..base import Response
from ..messages import ChatMessage, HandoffMessage, TextMessage
Expand Down Expand Up @@ -33,7 +33,7 @@ class UserProxyAgent(BaseChatAgent):
For typical use cases that involve
slow human responses, it is recommended to use termination conditions
such as :class:`~autogen_agentchat.task.HandoffTermination` or :class:`~autogen_agentchat.task.SourceMatchTermination`
such as :class:`~autogen_agentchat.conditions.HandoffTermination` or :class:`~autogen_agentchat.conditions.SourceMatchTermination`
to stop the running team and return the control to the application.
You can run the team again with the user input. This way, the state of the team
can be saved and restored when the user responds.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ._chat_agent import ChatAgent, Response
from ._handoff import Handoff
from ._task import TaskResult, TaskRunner
from ._team import Team
from ._termination import TerminatedException, TerminationCondition
Expand All @@ -11,4 +12,5 @@
"TerminationCondition",
"TaskResult",
"TaskRunner",
"Handoff",
]
Loading

0 comments on commit 65f9bcb

Please sign in to comment.