crewplus 0.2.71__tar.gz → 0.2.72__tar.gz

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.

Potentially problematic release.


This version of crewplus might be problematic. Click here for more details.

Files changed (25) hide show
  1. {crewplus-0.2.71 → crewplus-0.2.72}/PKG-INFO +1 -1
  2. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/services/tracing_manager.py +29 -10
  3. crewplus-0.2.72/crewplus/utils/tracing_util.py +51 -0
  4. {crewplus-0.2.71 → crewplus-0.2.72}/pyproject.toml +1 -1
  5. {crewplus-0.2.71 → crewplus-0.2.72}/LICENSE +0 -0
  6. {crewplus-0.2.71 → crewplus-0.2.72}/README.md +0 -0
  7. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/__init__.py +0 -0
  8. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/callbacks/__init__.py +0 -0
  9. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/callbacks/async_langfuse_handler.py +0 -0
  10. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/services/__init__.py +0 -0
  11. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/services/azure_chat_model.py +0 -0
  12. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/services/gemini_chat_model.py +0 -0
  13. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/services/init_services.py +0 -0
  14. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/services/model_load_balancer.py +0 -0
  15. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/utils/__init__.py +0 -0
  16. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/utils/schema_action.py +0 -0
  17. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/utils/schema_document_updater.py +0 -0
  18. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/vectorstores/milvus/__init__.py +0 -0
  19. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/vectorstores/milvus/milvus_schema_manager.py +0 -0
  20. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/vectorstores/milvus/schema_milvus.py +0 -0
  21. {crewplus-0.2.71 → crewplus-0.2.72}/crewplus/vectorstores/milvus/vdb_service.py +0 -0
  22. {crewplus-0.2.71 → crewplus-0.2.72}/docs/GeminiChatModel.md +0 -0
  23. {crewplus-0.2.71 → crewplus-0.2.72}/docs/ModelLoadBalancer.md +0 -0
  24. {crewplus-0.2.71 → crewplus-0.2.72}/docs/VDBService.md +0 -0
  25. {crewplus-0.2.71 → crewplus-0.2.72}/docs/index.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crewplus
3
- Version: 0.2.71
3
+ Version: 0.2.72
4
4
  Summary: Base services for CrewPlus AI applications
5
5
  Author-Email: Tim Liu <tim@opsmateai.com>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  # File: crewplus/services/tracing_manager.py
2
2
 
3
- from typing import Any, Optional, List, Protocol
3
+ from typing import Any, Optional, List, Protocol, Dict
4
4
  import os
5
5
  import logging
6
6
 
@@ -9,11 +9,14 @@ import logging
9
9
  try:
10
10
  from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
11
11
  from ..callbacks.async_langfuse_handler import AsyncLangfuseCallbackHandler
12
+ from ..utils.tracing_util import get_langfuse_handler, get_async_langfuse_handler
12
13
  LANGFUSE_AVAILABLE = True
13
14
  except ImportError:
14
15
  LANGFUSE_AVAILABLE = False
15
16
  LangfuseCallbackHandler = None
16
17
  AsyncLangfuseCallbackHandler = None
18
+ get_langfuse_handler = None
19
+ get_async_langfuse_handler = None
17
20
 
18
21
  class TracingContext(Protocol):
19
22
  """
@@ -102,11 +105,11 @@ class TracingManager:
102
105
  if enable_langfuse:
103
106
  try:
104
107
  # Create both sync and async handlers. We'll pick one at runtime.
105
- sync_handler = LangfuseCallbackHandler()
108
+ sync_handler = get_langfuse_handler()
106
109
  self._sync_handlers.append(sync_handler)
107
110
 
108
111
  if AsyncLangfuseCallbackHandler:
109
- async_handler = AsyncLangfuseCallbackHandler()
112
+ async_handler = get_async_langfuse_handler()
110
113
  self._async_handlers.append(async_handler)
111
114
 
112
115
  self.context.logger.info(f"Langfuse tracing enabled for {self.context.get_model_identifier()}")
@@ -115,7 +118,7 @@ class TracingManager:
115
118
  else:
116
119
  self.context.logger.info("Langfuse is not enabled, skipping handler initialization.")
117
120
 
118
- def _add_callbacks_to_config(self, config: Optional[dict], handlers: List[Any]) -> dict:
121
+ def add_callbacks_to_config(self, config: Optional[dict], handlers: List[Any]) -> dict:
119
122
  """A generic helper to add a list of handlers to a config object."""
120
123
  if config is None:
121
124
  config = {}
@@ -154,10 +157,26 @@ class TracingManager:
154
157
 
155
158
  return config
156
159
 
157
- def add_sync_callbacks_to_config(self, config: Optional[dict]) -> dict:
158
- """Adds synchronous tracing handlers to the request configuration."""
159
- return self._add_callbacks_to_config(config, self._sync_handlers)
160
+ def add_sync_callbacks_to_config(self, config: Optional[dict], handlers: Optional[List[Any]] = None) -> dict:
161
+ """
162
+ Adds synchronous tracing handlers to the request configuration.
163
+
164
+ Args:
165
+ config: The configuration dictionary to which callbacks will be added.
166
+ handlers: An optional list of handlers to add. If not provided,
167
+ the manager's default synchronous handlers are used.
168
+ """
169
+ handlers_to_add = self._sync_handlers if handlers is None else handlers
170
+ return self.add_callbacks_to_config(config, handlers_to_add)
160
171
 
161
- def add_async_callbacks_to_config(self, config: Optional[dict]) -> dict:
162
- """Adds asynchronous tracing handlers to the request configuration."""
163
- return self._add_callbacks_to_config(config, self._async_handlers)
172
+ def add_async_callbacks_to_config(self, config: Optional[dict], handlers: Optional[List[Any]] = None) -> dict:
173
+ """
174
+ Adds asynchronous tracing handlers to the request configuration.
175
+
176
+ Args:
177
+ config: The configuration dictionary to which callbacks will be added.
178
+ handlers: An optional list of handlers to add. If not provided,
179
+ the manager's default asynchronous handlers are used.
180
+ """
181
+ handlers_to_add = self._async_handlers if handlers is None else handlers
182
+ return self.add_callbacks_to_config(config, handlers_to_add)
@@ -0,0 +1,51 @@
1
+ from typing import Dict, Any, Optional
2
+ from langchain_core.runnables import RunnableConfig
3
+ from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
4
+ from ..callbacks.async_langfuse_handler import AsyncLangfuseCallbackHandler
5
+
6
+ # Singleton holder for the Langfuse handler to avoid multiple instances per run
7
+ _LANGFUSE_HANDLER: Optional[LangfuseCallbackHandler] = None
8
+ _ASYNC_LANGFUSE_HANDLER: Optional[AsyncLangfuseCallbackHandler] = None
9
+
10
+ def _get_langfuse_handler() -> LangfuseCallbackHandler:
11
+ global _LANGFUSE_HANDLER
12
+ if _LANGFUSE_HANDLER is None:
13
+ _LANGFUSE_HANDLER = LangfuseCallbackHandler()
14
+ return _LANGFUSE_HANDLER
15
+
16
+ def get_langfuse_handler() -> LangfuseCallbackHandler:
17
+ return _get_langfuse_handler()
18
+
19
+ def get_async_langfuse_handler() -> "AsyncLangfuseCallbackHandler":
20
+ """Returns a singleton instance of the async Langfuse handler."""
21
+ global _ASYNC_LANGFUSE_HANDLER
22
+ if _ASYNC_LANGFUSE_HANDLER is None:
23
+ _ASYNC_LANGFUSE_HANDLER = AsyncLangfuseCallbackHandler()
24
+ return _ASYNC_LANGFUSE_HANDLER
25
+
26
+ def prepare_trace_config(context: Dict[str, Any]) -> RunnableConfig:
27
+ """
28
+ Prepares a minimal RunnableConfig for tracing, primarily for Langfuse.
29
+
30
+ - Creates a new config containing only tracing-related information.
31
+ - Extracts 'trace_metadata' from the context's 'configurable' dict
32
+ and uses it as the 'metadata' for the new trace config.
33
+ - Adds a singleton Langfuse callback handler.
34
+ """
35
+ # The full config is passed in the 'config' key of the context
36
+ # Start with a copy of the existing config from the graph to preserve its state
37
+ run_config = context.get("config", {}).copy()
38
+
39
+ # Extract trace_metadata from the 'configurable' part of the full config
40
+ trace_metadata = run_config.get("trace_metadata", {})
41
+ if not trace_metadata:
42
+ trace_metadata = run_config.get("configurable", {}).get("trace_metadata", {})
43
+
44
+ # If trace_metadata exists, merge all its fields into the main metadata key
45
+ if trace_metadata and isinstance(trace_metadata, dict):
46
+ if "metadata" not in run_config:
47
+ run_config["metadata"] = {}
48
+ run_config["metadata"].update(trace_metadata)
49
+
50
+ return run_config
51
+
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "crewplus"
9
- version = "0.2.71"
9
+ version = "0.2.72"
10
10
  description = "Base services for CrewPlus AI applications"
11
11
  authors = [
12
12
  { name = "Tim Liu", email = "tim@opsmateai.com" },
File without changes
File without changes
File without changes
File without changes