-
Notifications
You must be signed in to change notification settings - Fork 502
Description
Is your feature request related to a problem? Please describe.
Context
I work with multiple internal packages that are maintained separately inside my team. They have a hierarchy like this:
repo: app -> repo: domain -> repo: core
At each level we have ag2 agents being utilized.
Problem
At the app level, we want to setup logging handlers and filters specific to that app.
The current ag2 event processing functionality has a event.print mechanism in ag2 processors that utilizes the python standard print function, which means that it directly sends the message to sys.stdout. There doesn't seem to be a good way to override this globally meaning we can't make it output as json, add extra info, nor easily shut it off (in case the ag2 event process logs are too verbose).
The only way to override this is to mess with python's sys.__stdout__ and sys.__stderr__ global variable, which in the end is not ideal and likely can break functionality or lose information.
It is worth mentioning that overriding of the logging mechanism is possible by creating my own event processor and passing it into the process method of an agent run.
response: RunResponseProtocol = agent.run(message=message)
response.process(OverridedProcessor)I can possibly create the OverrideProcessor at the lowest level repo: core and import and attach it to all the agent runs across repo: app and repo: domain but that is very sphagetti.
Describe the solution you'd like
I want to suggest refactoring the event.print functionality of the default event processor to utilize a logger with a name such as ag2.event.processor
logger = logging.getLogger("ag2.event.processor")
such that in my repo: app I can retrieve this logger by that name and update its handlers, filters, and formatters.
You can do this while retaining backwards compatibility by setting the default logger to just run python's default print function.
By allowing this, I can update my logging configuration at the top-most layer (repo: app) and it will propagate to the installed packages (repo: domain and repo: core).
Additional context
Followup: It would be nice to see this implemented at every instance where ag2 prints to stdout.