A programming framework for agentic AI
Remove logging from autogen agentchat (#4510)
Eric Zhub62f8f63dc79
diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/logging/__init__.py b/python/packages/autogen-agentchat/src/autogen_agentchat/logging/__init__.pydeleted file mode 100644index 8da6243cc..000000000--- a/python/packages/autogen-agentchat/src/autogen_agentchat/logging/__init__.py+++ /dev/null@@ -1,4 +0,0 @@-from ._console_log_handler import ConsoleLogHandler-from ._file_log_handler import FileLogHandler--__all__ = ["ConsoleLogHandler", "FileLogHandler"]diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/logging/_console_log_handler.py b/python/packages/autogen-agentchat/src/autogen_agentchat/logging/_console_log_handler.pydeleted file mode 100644index cc292e76c..000000000--- a/python/packages/autogen-agentchat/src/autogen_agentchat/logging/_console_log_handler.py+++ /dev/null@@ -1,20 +0,0 @@-import json-import logging-import sys-from datetime import datetime--from pydantic import BaseModel---class ConsoleLogHandler(logging.Handler):- def emit(self, record: logging.LogRecord) -> None:- ts = datetime.fromtimestamp(record.created).isoformat()- if isinstance(record.msg, BaseModel):- record.msg = json.dumps(- {- "timestamp": ts,- "message": record.msg.model_dump_json(indent=2),- "type": record.msg.__class__.__name__,- },- )- sys.stdout.write(f"{record.msg}\n")diff --git a/python/packages/autogen-agentchat/tests/test_assistant_agent.py b/python/packages/autogen-agentchat/tests/test_assistant_agent.pyindex 69a71a65b..2828893bc 100644--- a/python/packages/autogen-agentchat/tests/test_assistant_agent.py+++ b/python/packages/autogen-agentchat/tests/test_assistant_agent.py@@ -7,7 +7,6 @@ import pytestfrom autogen_agentchat import EVENT_LOGGER_NAMEfrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.base import Handoff, TaskResult-from autogen_agentchat.logging import FileLogHandlerfrom autogen_agentchat.messages import (HandoffMessage,MultiModalMessage,@@ -24,6 +23,7 @@ from openai.types.chat.chat_completion_chunk import ChatCompletionChunkfrom openai.types.chat.chat_completion_message import ChatCompletionMessagefrom openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall, Functionfrom openai.types.completion_usage import CompletionUsage+from utils import FileLogHandlerlogger = logging.getLogger(EVENT_LOGGER_NAME)logger.setLevel(logging.DEBUG)diff --git a/python/packages/autogen-agentchat/tests/test_group_chat.py b/python/packages/autogen-agentchat/tests/test_group_chat.pyindex 2cf862aaa..bd901d45b 100644--- a/python/packages/autogen-agentchat/tests/test_group_chat.py+++ b/python/packages/autogen-agentchat/tests/test_group_chat.py@@ -12,7 +12,6 @@ from autogen_agentchat.agents import (CodeExecutorAgent,)from autogen_agentchat.base import Handoff, Response, TaskResult-from autogen_agentchat.logging import FileLogHandlerfrom autogen_agentchat.messages import (AgentMessage,ChatMessage,@@ -41,6 +40,7 @@ from openai.types.chat.chat_completion_chunk import ChatCompletionChunkfrom openai.types.chat.chat_completion_message import ChatCompletionMessagefrom openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall, Functionfrom openai.types.completion_usage import CompletionUsage+from utils import FileLogHandlerlogger = logging.getLogger(EVENT_LOGGER_NAME)logger.setLevel(logging.DEBUG)diff --git a/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py b/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.pyindex a5c8d5761..1ce4bf11a 100644--- a/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py+++ b/python/packages/autogen-agentchat/tests/test_magentic_one_group_chat.py@@ -9,7 +9,6 @@ from autogen_agentchat.agents import (BaseChatAgent,)from autogen_agentchat.base import Response-from autogen_agentchat.logging import FileLogHandlerfrom autogen_agentchat.messages import (ChatMessage,TextMessage,@@ -19,6 +18,7 @@ from autogen_agentchat.teams import ()from autogen_core.base import CancellationTokenfrom autogen_ext.models import ReplayChatCompletionClient+from utils import FileLogHandlerlogger = logging.getLogger(EVENT_LOGGER_NAME)logger.setLevel(logging.DEBUG)diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/logging/_file_log_handler.py b/python/packages/autogen-agentchat/tests/utils.pysimilarity index 58%rename from python/packages/autogen-agentchat/src/autogen_agentchat/logging/_file_log_handler.pyrename to python/packages/autogen-agentchat/tests/utils.pyindex 1e4b402da..90d66f0ba 100644--- a/python/packages/autogen-agentchat/src/autogen_agentchat/logging/_file_log_handler.py+++ b/python/packages/autogen-agentchat/tests/utils.py@@ -1,5 +1,6 @@import jsonimport logging+import sysfrom datetime import datetimefrom pydantic import BaseModel@@ -22,3 +23,17 @@ class FileLogHandler(logging.Handler):},)self.file_handler.emit(record)+++class ConsoleLogHandler(logging.Handler):+ def emit(self, record: logging.LogRecord) -> None:+ ts = datetime.fromtimestamp(record.created).isoformat()+ if isinstance(record.msg, BaseModel):+ record.msg = json.dumps(+ {+ "timestamp": ts,+ "message": record.msg.model_dump_json(indent=2),+ "type": record.msg.__class__.__name__,+ },+ )+ sys.stdout.write(f"{record.msg}\n")