crewplus 0.2.63__tar.gz → 0.2.64__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.63 → crewplus-0.2.64}/PKG-INFO +1 -1
  2. crewplus-0.2.64/crewplus/callbacks/run_id_handler.py +73 -0
  3. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/services/tracing_manager.py +11 -5
  4. {crewplus-0.2.63 → crewplus-0.2.64}/pyproject.toml +1 -1
  5. {crewplus-0.2.63 → crewplus-0.2.64}/LICENSE +0 -0
  6. {crewplus-0.2.63 → crewplus-0.2.64}/README.md +0 -0
  7. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/__init__.py +0 -0
  8. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/callbacks/__init__.py +0 -0
  9. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/callbacks/async_langfuse_handler.py +0 -0
  10. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/services/__init__.py +0 -0
  11. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/services/azure_chat_model.py +0 -0
  12. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/services/gemini_chat_model.py +0 -0
  13. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/services/init_services.py +0 -0
  14. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/services/model_load_balancer.py +0 -0
  15. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/utils/__init__.py +0 -0
  16. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/utils/schema_action.py +0 -0
  17. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/utils/schema_document_updater.py +0 -0
  18. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/vectorstores/milvus/__init__.py +0 -0
  19. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/vectorstores/milvus/milvus_schema_manager.py +0 -0
  20. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/vectorstores/milvus/schema_milvus.py +0 -0
  21. {crewplus-0.2.63 → crewplus-0.2.64}/crewplus/vectorstores/milvus/vdb_service.py +0 -0
  22. {crewplus-0.2.63 → crewplus-0.2.64}/docs/GeminiChatModel.md +0 -0
  23. {crewplus-0.2.63 → crewplus-0.2.64}/docs/ModelLoadBalancer.md +0 -0
  24. {crewplus-0.2.63 → crewplus-0.2.64}/docs/VDBService.md +0 -0
  25. {crewplus-0.2.63 → crewplus-0.2.64}/docs/index.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crewplus
3
- Version: 0.2.63
3
+ Version: 0.2.64
4
4
  Summary: Base services for CrewPlus AI applications
5
5
  Author-Email: Tim Liu <tim@opsmateai.com>
6
6
  License: MIT
@@ -0,0 +1,73 @@
1
+ # File: crewplus/callbacks/run_id_handler.py
2
+
3
+ from typing import Any, Dict
4
+ from uuid import UUID
5
+ import logging
6
+
7
+ # Langfuse imports with graceful fallback
8
+ try:
9
+ from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
10
+ from .async_langfuse_handler import AsyncLangfuseCallbackHandler
11
+ from langfuse import get_client
12
+ LANGFUSE_AVAILABLE = True
13
+ except ImportError:
14
+ LANGFUSE_AVAILABLE = False
15
+ # Define dummy base classes if langfuse is not available to avoid runtime errors
16
+ class LangfuseCallbackHandler: pass
17
+ class AsyncLangfuseCallbackHandler: pass
18
+ get_client = None
19
+
20
+ # --- Custom Callback Handlers to capture the run_id ---
21
+ if LANGFUSE_AVAILABLE:
22
+ class RunIdCallbackHandler(LangfuseCallbackHandler):
23
+ """
24
+ A custom synchronous callback handler that captures the Langchain run_id
25
+ and adds it to the Langfuse trace metadata.
26
+ """
27
+ def on_chain_start(
28
+ self,
29
+ serialized: Dict[str, Any],
30
+ inputs: Dict[str, Any],
31
+ run_id: UUID,
32
+ **kwargs: Any,
33
+ ) -> Any:
34
+ # First, let the base handler do its work, which includes creating the trace
35
+ run = super().on_chain_start(serialized, inputs, run_id, **kwargs)
36
+
37
+ try:
38
+ # Then, update the created trace with the run_id as metadata
39
+ langfuse_client = get_client()
40
+ langfuse_client.update_current_trace(
41
+ metadata={"langchain_run_id": str(run_id)}
42
+ )
43
+ except Exception as e:
44
+ logging.getLogger(__name__).warning(f"Failed to add run_id to Langfuse trace: {e}")
45
+
46
+ return run
47
+
48
+ class AsyncRunIdCallbackHandler(AsyncLangfuseCallbackHandler):
49
+ """
50
+ A custom asynchronous callback handler that captures the Langchain run_id
51
+ and adds it to the Langfuse trace metadata.
52
+ """
53
+ async def on_chain_start(
54
+ self,
55
+ serialized: Dict[str, Any],
56
+ inputs: Dict[str, Any],
57
+ run_id: UUID,
58
+ **kwargs: Any,
59
+ ) -> Any:
60
+ # First, let the base handler do its work, which includes creating the trace
61
+ run = await super().on_chain_start(serialized, inputs, run_id, **kwargs)
62
+
63
+ try:
64
+ # The get_client() is thread-safe and can be used in async contexts
65
+ # for this type of single, atomic update.
66
+ langfuse_client = get_client()
67
+ langfuse_client.update_current_trace(
68
+ metadata={"langchain_run_id": str(run_id)}
69
+ )
70
+ except Exception as e:
71
+ logging.getLogger(__name__).warning(f"Failed to add run_id to async Langfuse trace: {e}")
72
+
73
+ return run
@@ -9,11 +9,16 @@ import logging
9
9
  try:
10
10
  from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler
11
11
  from ..callbacks.async_langfuse_handler import AsyncLangfuseCallbackHandler
12
+ # Import the new custom handlers
13
+ from ..callbacks.run_id_handler import RunIdCallbackHandler, AsyncRunIdCallbackHandler
12
14
  LANGFUSE_AVAILABLE = True
13
15
  except ImportError:
14
16
  LANGFUSE_AVAILABLE = False
15
17
  LangfuseCallbackHandler = None
16
18
  AsyncLangfuseCallbackHandler = None
19
+ # Define dummy classes for the custom handlers to prevent errors if langfuse is not installed
20
+ class RunIdCallbackHandler: pass
21
+ class AsyncRunIdCallbackHandler: pass
17
22
 
18
23
  class TracingContext(Protocol):
19
24
  """
@@ -98,13 +103,14 @@ class TracingManager:
98
103
 
99
104
  if enable_langfuse:
100
105
  try:
101
- # Create both sync and async handlers. We'll pick one at runtime.
102
- sync_handler = LangfuseCallbackHandler()
103
- self._sync_handlers.append(sync_handler)
106
+ # Create and add both the standard and the run_id-capturing handlers.
107
+ # The standard handler creates the trace, and the custom one updates it.
108
+ self._sync_handlers.append(LangfuseCallbackHandler())
109
+ self._sync_handlers.append(RunIdCallbackHandler())
104
110
 
105
111
  if AsyncLangfuseCallbackHandler:
106
- async_handler = AsyncLangfuseCallbackHandler()
107
- self._async_handlers.append(async_handler)
112
+ self._async_handlers.append(AsyncLangfuseCallbackHandler())
113
+ self._async_handlers.append(AsyncRunIdCallbackHandler())
108
114
 
109
115
  self.context.logger.info(f"Langfuse tracing enabled for {self.context.get_model_identifier()}")
110
116
  except Exception as e:
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
6
6
 
7
7
  [project]
8
8
  name = "crewplus"
9
- version = "0.2.63"
9
+ version = "0.2.64"
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