gohumanloop 0.0.7__py3-none-any.whl → 0.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gohumanloop/__init__.py CHANGED
@@ -17,6 +17,8 @@ from gohumanloop.providers.terminal_provider import TerminalProvider
17
17
 
18
18
  from gohumanloop.utils import run_async_safely, get_secret_from_env
19
19
 
20
+ from gohumanloop.adapters import HumanloopAdapter, AgentOpsHumanLoopCallback
21
+
20
22
  # Conditionally import EmailProvider
21
23
  try:
22
24
  from gohumanloop.providers.email_provider import EmailProvider # noqa: F401
@@ -60,6 +62,9 @@ __all__ = [
60
62
  "APIProvider",
61
63
  "GoHumanLoopProvider",
62
64
  "TerminalProvider",
65
+ # Adapter Implementations
66
+ "HumanloopAdapter",
67
+ "AgentOpsHumanLoopCallback",
63
68
  # Utility Functions
64
69
  "run_async_safely",
65
70
  "get_secret_from_env",
@@ -1,5 +1,8 @@
1
- from .langgraph_adapter import (
1
+ from .base_adapter import (
2
2
  HumanloopAdapter,
3
+ AgentOpsHumanLoopCallback,
4
+ )
5
+ from .langgraph_adapter import (
3
6
  LangGraphHumanLoopCallback,
4
7
  default_langgraph_callback_factory,
5
8
  interrupt,
@@ -9,6 +12,7 @@ from .langgraph_adapter import (
9
12
 
10
13
  __all__ = [
11
14
  "HumanloopAdapter",
15
+ "AgentOpsHumanLoopCallback",
12
16
  "LangGraphHumanLoopCallback",
13
17
  "default_langgraph_callback_factory",
14
18
  "interrupt",
@@ -708,36 +708,42 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
708
708
  It records events, tracks metrics, and provides observability for human-agent interactions.
709
709
  """
710
710
 
711
- import importlib.util
712
-
713
- if importlib.util.find_spec("agentops") is not None:
714
- from agentops.sdk import session, agent, operation, task # type: ignore
715
- else:
716
- logger.debug(
717
- "AgentOps package not installed. AgentOps features disabled. Please pip install agentops"
718
- )
719
-
720
711
  def __init__(self, session_tags: Optional[List[str]] = None) -> None:
721
- """Initialize the AgentOps human loop callback.
722
-
723
- Args:
724
- session_tags: Optional tags for AgentOps session tracking
725
- """
726
712
  self.session_tags = session_tags or ["gohumanloop"]
713
+ self._operation = None
714
+ self._initialize_agentops()
727
715
 
716
+ def _initialize_agentops(self) -> None:
717
+ """Initialize AgentOps if available, otherwise fall back gracefully."""
728
718
  try:
729
- import agentops # type: ignore
719
+ import importlib.util
720
+
721
+ if importlib.util.find_spec("agentops"):
722
+ from agentops.sdk import operation # type: ignore
723
+ import agentops # type: ignore
730
724
 
731
- agentops.init(tags=self.session_tags)
725
+ self._operation = operation
726
+ agentops.init(tags=self.session_tags)
727
+ else:
728
+ raise ImportError(
729
+ "AgentOps package not installed. Features disabled. "
730
+ "Please install with: pip install agentops"
731
+ )
732
732
  except Exception as e:
733
- logger.warning(f"Failed to initialize AgentOps: {str(e)}")
733
+ logger.warning(f"AgentOps initialization failed: {e}")
734
+
735
+ @property
736
+ def operation_decorator(self) -> Callable:
737
+ """Return the appropriate decorator based on AgentOps availability."""
738
+ return self._operation if self._operation is not None else lambda f: f
734
739
 
735
- @operation
736
740
  async def async_on_humanloop_request(
737
741
  self, provider: HumanLoopProvider, request: HumanLoopRequest
738
742
  ) -> Any:
739
743
  """Handle human loop start events."""
740
- try:
744
+
745
+ @self.operation_decorator
746
+ async def callback_humanloop_request() -> Any:
741
747
  # Create event data
742
748
  event_data = {
743
749
  "event_type": "gohumanloop_request",
@@ -752,10 +758,9 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
752
758
  "created_at": request.created_at,
753
759
  }
754
760
  return event_data
755
- except (ImportError, Exception) as e:
756
- logger.warning(f"Failed to record AgentOps event: {str(e)}")
757
761
 
758
- @operation
762
+ return await callback_humanloop_request()
763
+
759
764
  async def async_on_humanloop_update(
760
765
  self, provider: HumanLoopProvider, result: HumanLoopResult
761
766
  ) -> Any:
@@ -765,7 +770,9 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
765
770
  provider: The human loop provider instance
766
771
  result: The human loop result containing status and response
767
772
  """
768
- try:
773
+
774
+ @self.operation_decorator
775
+ async def callback_humanloop_update() -> Any:
769
776
  # Create event data
770
777
  event_data = {
771
778
  "event_type": "gohumanloop_update",
@@ -782,10 +789,9 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
782
789
  }
783
790
 
784
791
  return event_data
785
- except Exception as e:
786
- logger.warning(f"Failed to record AgentOps event: {str(e)}")
787
792
 
788
- @operation
793
+ return await callback_humanloop_update()
794
+
789
795
  async def async_on_humanloop_timeout(
790
796
  self, provider: HumanLoopProvider, result: HumanLoopResult
791
797
  ) -> Any:
@@ -794,7 +800,9 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
794
800
  Args:
795
801
  provider: The human loop provider instance
796
802
  """
797
- try:
803
+
804
+ @self.operation_decorator
805
+ async def callback_humanloop_timeout() -> Any:
798
806
  # Create error event
799
807
  error_data = {
800
808
  "event_type": "gohumanloop_timeout",
@@ -811,10 +819,9 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
811
819
  }
812
820
 
813
821
  return error_data
814
- except Exception as e:
815
- logger.warning(f"Failed to record AgentOps timeout event: {str(e)}")
816
822
 
817
- @operation
823
+ return await callback_humanloop_timeout()
824
+
818
825
  async def async_on_humanloop_error(
819
826
  self, provider: HumanLoopProvider, error: Exception
820
827
  ) -> Any:
@@ -824,7 +831,9 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
824
831
  provider: The human loop provider instance
825
832
  error: The exception that occurred
826
833
  """
827
- try:
834
+
835
+ @self.operation_decorator
836
+ async def callback_humanloop_error() -> Any:
828
837
  # Create error event
829
838
  error_data = {
830
839
  "event_type": "gohumanloop_error",
@@ -834,5 +843,5 @@ class AgentOpsHumanLoopCallback(HumanLoopCallback):
834
843
 
835
844
  # Record the error event
836
845
  return error_data
837
- except Exception as e:
838
- logger.warning(f"Failed to record AgentOps error event: {str(e)}")
846
+
847
+ return await callback_humanloop_error()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gohumanloop
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: Perfecting AI workflows with human intelligence
5
5
  Author-email: gohumanloop authors <baird0917@163.com>
6
6
  Project-URL: repository, https://github.com/ptonlix/gohumanloop
@@ -33,7 +33,7 @@ Dynamic: license-file
33
33
  **GoHumanLoop**: A Python library empowering AI agents to dynamically request human input (approval/feedback/conversation) at critical stages. Core features:
34
34
 
35
35
  - `Human-in-the-loop control`: Lets AI agent systems pause and escalate decisions, enhancing safety and trust.
36
- - `Multi-channel integration`: Supports Terminal, Email, API, and frameworks like LangGraph/CrewAI (soon).
36
+ - `Multi-channel integration`: Supports Terminal, Email, API, and frameworks like LangGraph/CrewAI/...(soon)
37
37
  - `Flexible workflows`: Combines automated reasoning with human oversight for reliable AI operations.
38
38
 
39
39
  Ensures responsible AI deployment by bridging autonomous agents and human judgment.
@@ -59,9 +59,10 @@ Ensures responsible AI deployment by bridging autonomous agents and human judgme
59
59
 
60
60
  ## 🎹 Getting Started
61
61
 
62
- To get started, check out the following example or jump straight into one of the [Examples](./examples/):
62
+ To get started, check out the following example or jump straight into one of the [Examples Repo](https://github.com/ptonlix/gohumanloop-examples):
63
63
 
64
- - 🦜⛓️ [LangGraph](./examples/langgraph/)
64
+ - 🦜⛓️ [LangGraph](https://github.com/ptonlix/gohumanloop-examples/tree/main/LangGraph)
65
+ - 🚣‍ [CrewAI](https://github.com/ptonlix/gohumanloop-examples/tree/main/CrewAI)
65
66
 
66
67
  ### Installation
67
68
 
@@ -206,7 +207,7 @@ Perform `human-in-the-loop` interaction by entering:
206
207
 
207
208
  🚀🚀🚀 Completed successfully ~
208
209
 
209
- ➡️ Check out more examples in the [Examples Directory](./examples/) and we look foward to your contributions!
210
+ ➡️ Check out more examples in the [Examples Repository](https://github.com/ptonlix/gohumanloop-examples) and we look foward to your contributions!
210
211
 
211
212
  ## 🎵 Why GoHumanloop?
212
213
 
@@ -1,7 +1,7 @@
1
- gohumanloop/__init__.py,sha256=oJqVOtRRDHNxwxZ2Blw7ycBRwcTBMTURUCx-XcL2YJ0,1969
1
+ gohumanloop/__init__.py,sha256=KiY2ncM6OQvkBYcz5rsbob_GuV8hQHOARA-EsxAylEU,2134
2
2
  gohumanloop/__main__.py,sha256=zdGKN92H9SgwZfL4xLqPkE1YaiRcHhVg_GqC-H1VurA,75
3
- gohumanloop/adapters/__init__.py,sha256=GTEonjk1NogjtUVtgiLWciWR_e9-PbAlZfQUdA8paik,390
4
- gohumanloop/adapters/base_adapter.py,sha256=LTnjVnownYqJCQQeD3V53STEOvIm9n9cNYPaENULMJQ,32244
3
+ gohumanloop/adapters/__init__.py,sha256=_XqJ6eaUBLJJJyjfBQJykBZ4X9HvC3VYOVTn2KnBlqo,484
4
+ gohumanloop/adapters/base_adapter.py,sha256=Eokhz6fsCcxqq_X0damHQJ2BfGqEUnx2ZQv9gDcpOhU,32605
5
5
  gohumanloop/adapters/langgraph_adapter.py,sha256=AHJv_b6g8xjeq_9X2cGiW76pSGlfgCGBUvjrZQcbR9s,11621
6
6
  gohumanloop/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  gohumanloop/cli/main.py,sha256=Txjk31MlkiX9zeHZfFEXEu0s2IBESY8sxrxBEzZKk2U,767
@@ -23,9 +23,9 @@ gohumanloop/utils/__init__.py,sha256=l0e3lnOVrt6HwaxidNGFXORX4awCKemhJZ_t3k-5u-s
23
23
  gohumanloop/utils/context_formatter.py,sha256=sAWrKJpxmsHga6gsyBwFBlAsHW8bjR1hkaGhk1PoE1M,2064
24
24
  gohumanloop/utils/threadsafedict.py,sha256=9uyewnwmvS3u1fCx3SK0YWFxHMcyIwlye1Ev7WW7WHA,9588
25
25
  gohumanloop/utils/utils.py,sha256=-bti65OaVh5dlvc5BIgiTw6dqxmqdKnOQHE0V-LKjek,2107
26
- gohumanloop-0.0.7.dist-info/licenses/LICENSE,sha256=-U5tuCcSpndQwSKWtZbFbazb-_AtZcZL2kQgHbSLg-M,1064
27
- gohumanloop-0.0.7.dist-info/METADATA,sha256=3TYk0bxxF9ynRetWwdi_IOlmjb30W1ZI4yTxzpv69WI,11216
28
- gohumanloop-0.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
- gohumanloop-0.0.7.dist-info/entry_points.txt,sha256=wM6jqRRD8bQXkvIduRVCuAJIlbyWg_F5EDXo5OZ_PwY,88
30
- gohumanloop-0.0.7.dist-info/top_level.txt,sha256=LvOXBqS6Mspmcuqp81uz0Vjx_m_YI0w06DOPCiI1BfY,12
31
- gohumanloop-0.0.7.dist-info/RECORD,,
26
+ gohumanloop-0.0.9.dist-info/licenses/LICENSE,sha256=-U5tuCcSpndQwSKWtZbFbazb-_AtZcZL2kQgHbSLg-M,1064
27
+ gohumanloop-0.0.9.dist-info/METADATA,sha256=E9DyAVAdkVPxP0K465Jrm4eq44AEXKe-riSCDN-67zM,11427
28
+ gohumanloop-0.0.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
+ gohumanloop-0.0.9.dist-info/entry_points.txt,sha256=wM6jqRRD8bQXkvIduRVCuAJIlbyWg_F5EDXo5OZ_PwY,88
30
+ gohumanloop-0.0.9.dist-info/top_level.txt,sha256=LvOXBqS6Mspmcuqp81uz0Vjx_m_YI0w06DOPCiI1BfY,12
31
+ gohumanloop-0.0.9.dist-info/RECORD,,