diff --git a/openbb_agents/agent.py b/openbb_agents/agent.py index c039534..47f5747 100644 --- a/openbb_agents/agent.py +++ b/openbb_agents/agent.py @@ -19,13 +19,16 @@ get_valid_list_of_providers, map_name_to_openbb_function_description, ) -from .utils import get_dependencies +from .utils import configure_logging, get_dependencies logger = logging.getLogger(__name__) def openbb_agent( - query: str, openbb_tools: list[str] | None = None, openbb_pat: str | None = None + query: str, + openbb_tools: list[str] | None = None, + openbb_pat: str | None = None, + verbose: bool = True, ) -> str: """Answer a query using the OpenBB Agent equipped with tools. @@ -54,14 +57,16 @@ def openbb_agent( ... openbb_tools=['.equity.price.quote']) """ + configure_logging(verbose) if openbb_pat: from openbb import obb obb.account.login(pat=openbb_pat) tool_vector_index = _handle_tool_vector_index(openbb_tools) - subquestions = generate_subquestions_from_query(user_query=query) + logger.info("Generating subquestions for user query: %s", query) + subquestions = generate_subquestions_from_query(user_query=query) logger.info("Generated subquestions: %s", subquestions) answered_subquestions = [] @@ -85,7 +90,9 @@ def openbb_agent( ) -async def aopenbb_agent(query: str, openbb_tools: list[str] | None = None) -> str: +async def aopenbb_agent( + query: str, openbb_tools: list[str] | None = None, verbose: bool = True +) -> str: """Answer a query using the OpenBB Agent equipped with tools. Async variant of `openbb_agent`. @@ -111,6 +118,7 @@ async def aopenbb_agent(query: str, openbb_tools: list[str] | None = None) -> st ... openbb_tools=['.equity.price.quote']) """ + configure_logging(verbose) tool_vector_index = _handle_tool_vector_index(openbb_tools) subquestions = await agenerate_subquestions_from_query(user_query=query) diff --git a/openbb_agents/utils.py b/openbb_agents/utils.py index 3781475..c85eb97 100644 --- a/openbb_agents/utils.py +++ b/openbb_agents/utils.py @@ -1,3 +1,5 @@ +import logging +import logging.config import os from .models import AnsweredSubQuestion, SubQuestion @@ -7,6 +9,52 @@ def get_verbosity() -> bool: return os.environ.get("VERBOSE", "False") == "True" +def configure_logging(verbose: bool): + logging_config = { + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "standard": { + "format": "%(asctime)s - %(levelname)s - %(name)s - %(message)s", + } + }, + "handlers": { + "console": { + "class": "logging.StreamHandler", + "stream": "ext://sys.stdout", # Default is stderr + "formatter": "standard", + }, + }, + "loggers": { + "openbb_agents.agent": { + "handlers": ["console"], + "level": "INFO" if verbose else "CRITICAL", + "propagate": False, + }, + "openbb_agents.utils": { + "handlers": ["console"], + "level": "INFO" if verbose else "CRITICAL", + "propagate": False, + }, + "openbb_agents.tools": { + "handlers": ["console"], + "level": "INFO" if verbose else "CRITICAL", + "propagate": False, + }, + "openbb_agents.chains": { + "handlers": ["console"], + "level": "INFO" if verbose else "CRITICAL", + "propagate": False, + }, + }, + "root": { + "handlers": ["console"], + "level": "WARNING" if verbose else "CRITICAL", + }, + } + logging.config.dictConfig(logging_config) + + def get_dependencies( answered_subquestions: list[AnsweredSubQuestion], subquestion: SubQuestion ) -> list[AnsweredSubQuestion]: