Support disabling logging to terminal (#512)

This commit is contained in:
Albert Villanova del Moral 2025-02-07 13:44:21 +01:00 committed by GitHub
parent 3d5d526ef5
commit 932298696c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View File

@ -92,7 +92,7 @@ class MultiStepAgent:
max_steps (`int`, default `6`): Maximum number of steps the agent can take to solve the task.
tool_parser (`Callable`, *optional*): Function used to parse the tool calls from the LLM output.
add_base_tools (`bool`, default `False`): Whether to add the base tools to the agent's tools.
verbosity_level (`int`, default `1`): Level of verbosity of the agent's logs.
verbosity_level (`LogLevel`, default `LogLevel.INFO`): Level of verbosity of the agent's logs.
grammar (`dict[str, str]`, *optional*): Grammar used to parse the LLM output.
managed_agents (`list`, *optional*): Managed agents that the agent can call.
step_callbacks (`list[Callable]`, *optional*): Callbacks that will be called at each step.
@ -111,7 +111,7 @@ class MultiStepAgent:
max_steps: int = 6,
tool_parser: Optional[Callable] = None,
add_base_tools: bool = False,
verbosity_level: int = 1,
verbosity_level: LogLevel = LogLevel.INFO,
grammar: Optional[Dict[str, str]] = None,
managed_agents: Optional[List] = None,
step_callbacks: Optional[List[Callable]] = None,

View File

@ -28,6 +28,9 @@ from rich.text import Text
from rich.tree import Tree
__all__ = ["AgentLogger", "LogLevel", "Monitor"]
class Monitor:
def __init__(self, tracked_model, logger):
self.step_durations = []
@ -69,6 +72,7 @@ class Monitor:
class LogLevel(IntEnum):
OFF = -1 # No output
ERROR = 0 # Only errors
INFO = 1 # Normal output (default)
DEBUG = 2 # Detailed output
@ -206,6 +210,3 @@ class AgentLogger:
)
build_agent_tree(main_tree, agent)
self.console.print(main_tree)
__all__ = ["AgentLogger", "Monitor"]

View File

@ -3,6 +3,7 @@ from unittest.mock import patch
import pytest
from smolagents.agents import MultiStepAgent
from smolagents.monitoring import LogLevel
original_multi_step_agent_init = MultiStepAgent.__init__
@ -12,7 +13,7 @@ original_multi_step_agent_init = MultiStepAgent.__init__
def patch_multi_step_agent_with_suppressed_logging():
with patch.object(MultiStepAgent, "__init__", autospec=True) as mock_init:
def init_with_suppressed_logging(self, *args, verbosity_level=-1, **kwargs):
def init_with_suppressed_logging(self, *args, verbosity_level=LogLevel.OFF, **kwargs):
original_multi_step_agent_init(self, *args, verbosity_level=verbosity_level, **kwargs)
mock_init.side_effect = init_with_suppressed_logging