From f7cced15aca6ca2804c26b3de8a35047b76df69a Mon Sep 17 00:00:00 2001 From: Karan Vaidya Date: Mon, 19 Aug 2024 14:45:03 +0530 Subject: [PATCH] Update metadata when error comes --- python/composio/client/enums/base.py | 11 ++++++++--- python/composio/tools/local/base/decorators.py | 4 +++- python/composio/tools/toolset.py | 8 ++------ python/composio/utils/logging.py | 3 +++ python/swe/examples/langgraph_agent/benchmark.py | 3 ++- python/swe/examples/langgraph_agent/inputs.py | 1 - python/swe/examples/langgraph_agent/main.py | 3 ++- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/python/composio/client/enums/base.py b/python/composio/client/enums/base.py index 0f050ea55fb..1c835a46177 100644 --- a/python/composio/client/enums/base.py +++ b/python/composio/client/enums/base.py @@ -11,6 +11,7 @@ from composio.constants import LOCAL_CACHE_DIRECTORY from composio.exceptions import ComposioSDKError from composio.storage.base import LocalStorage +from composio.utils.logging import get_logger _model_cache: t.Dict[str, LocalStorage] = {} @@ -152,10 +153,14 @@ def load(self) -> EntityType: if self._slug in _runtime_actions: return _runtime_actions[self._slug] # type: ignore if not (self._path / self._slug).exists(): - raise MetadataFileNotFound( - f"Metadata file for `{self._slug}` not found, " - "Please run `composio apps update` to fix this" + from composio.cli.apps import update + from composio.cli.context import get_context + + logger = get_logger() + logger.debug( + f"Metadata file for `{self._slug}` not found, updating metadata" ) + update(context=get_context()) if self._slug not in _model_cache: _model_cache[self._slug] = self._model.load(self._path / self._slug) return t.cast(EntityType, _model_cache[self._slug]) diff --git a/python/composio/tools/local/base/decorators.py b/python/composio/tools/local/base/decorators.py index ff2d52b49e6..8c39e05c4f0 100644 --- a/python/composio/tools/local/base/decorators.py +++ b/python/composio/tools/local/base/decorators.py @@ -128,7 +128,9 @@ def _parse_docstring( ) -> t.Tuple[str, t.Dict[str, str], t.Optional[t.Tuple[str, str]],]: """Parse docstring for descriptions.""" if docstr is None: - raise ValueError("Docstring is None, Please provide a docstring for runtime tools") + raise ValueError( + "Docstring is None, Please provide a docstring for runtime tools" + ) header, *descriptions = docstr.lstrip().rstrip().split("\n") params = {} returns = None diff --git a/python/composio/tools/toolset.py b/python/composio/tools/toolset.py index f32bcb9e2a2..fce50c1182f 100644 --- a/python/composio/tools/toolset.py +++ b/python/composio/tools/toolset.py @@ -498,13 +498,9 @@ def execute_action( action = Action(action) is_runtime = action.is_runtime self.logger.debug(f"Action: {action}, runtime: {is_runtime}") + params = self._serialize_execute_params(param=params) if not is_runtime: - params = self._process_request( - action=action, - request=self._serialize_execute_params( - param=params, - ), - ) + params = self._process_request(action=action, request=params) metadata = self._add_metadata(action=action, metadata=metadata) response = ( self._execute_local( diff --git a/python/composio/utils/logging.py b/python/composio/utils/logging.py index 342a5a99c08..887dc0050a0 100644 --- a/python/composio/utils/logging.py +++ b/python/composio/utils/logging.py @@ -106,3 +106,6 @@ def __init__( def logger(self) -> logging.Logger: """Get the component logger.""" return t.cast(logging.Logger, self._logger) + + +get_logger = get diff --git a/python/swe/examples/langgraph_agent/benchmark.py b/python/swe/examples/langgraph_agent/benchmark.py index a1fcd9c8875..0a133a6b38d 100644 --- a/python/swe/examples/langgraph_agent/benchmark.py +++ b/python/swe/examples/langgraph_agent/benchmark.py @@ -1,8 +1,9 @@ import argparse -from agent import composio_toolset, graph from langchain_core.messages import HumanMessage +from agent import composio_toolset, graph + from composio_langgraph import Action from swekit.benchmark.run_evaluation import evaluate diff --git a/python/swe/examples/langgraph_agent/inputs.py b/python/swe/examples/langgraph_agent/inputs.py index e8d357bf49b..65a8158187a 100644 --- a/python/swe/examples/langgraph_agent/inputs.py +++ b/python/swe/examples/langgraph_agent/inputs.py @@ -3,7 +3,6 @@ from pathlib import Path from agent import composio_toolset - from composio import Action diff --git a/python/swe/examples/langgraph_agent/main.py b/python/swe/examples/langgraph_agent/main.py index 454488be53b..e10b1b00c7d 100644 --- a/python/swe/examples/langgraph_agent/main.py +++ b/python/swe/examples/langgraph_agent/main.py @@ -1,7 +1,8 @@ -from agent import composio_toolset, graph from inputs import from_github from langchain_core.messages import HumanMessage +from agent import composio_toolset, graph + from composio_langgraph import Action