turingpulse-sdk-strands 1.0.0__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.
@@ -0,0 +1,42 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Virtual environments
7
+ .venv/
8
+ venv/
9
+ ENV/
10
+
11
+ # Distribution / packaging
12
+ dist/
13
+ build/
14
+ *.egg-info/
15
+
16
+ # Database files
17
+ *.db
18
+ *.sqlite3
19
+
20
+ # Environment variables
21
+ .env
22
+ .env.local
23
+
24
+ # IDE
25
+ .idea/
26
+ .vscode/
27
+ *.swp
28
+ *.swo
29
+
30
+ # Testing
31
+ .pytest_cache/
32
+ .coverage
33
+ htmlcov/
34
+ .tox/
35
+
36
+ # Logs
37
+ *.log
38
+ logs/
39
+
40
+ # OS files
41
+ .DS_Store
42
+ Thumbs.db
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: turingpulse-sdk-strands
3
+ Version: 1.0.0
4
+ Summary: TuringPulse SDK integration for Strands Agents
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.11
7
+ Requires-Dist: strands-agents>=1.27.0
8
+ Requires-Dist: turingpulse-sdk>=1.0.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
11
+ Requires-Dist: pytest>=8.0; extra == 'dev'
@@ -0,0 +1,17 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "turingpulse-sdk-strands"
7
+ version = "1.0.0"
8
+ description = "TuringPulse SDK integration for Strands Agents"
9
+ requires-python = ">=3.11"
10
+ license = "Apache-2.0"
11
+ dependencies = [
12
+ "turingpulse-sdk>=1.0.0",
13
+ "strands-agents>=1.27.0",
14
+ ]
15
+
16
+ [project.optional-dependencies]
17
+ dev = ["pytest>=8.0", "pytest-asyncio>=0.23"]
@@ -0,0 +1,6 @@
1
+ """TuringPulse SDK integration for Strands Agents."""
2
+
3
+ from ._wrapper import instrument_strands
4
+
5
+ __version__ = "0.1.0"
6
+ __all__ = ["instrument_strands"]
@@ -0,0 +1,77 @@
1
+ """Strands Agents instrumentation for TuringPulse.
2
+
3
+ Wraps Strands agent invocations to capture tool calls,
4
+ model interactions, and reasoning chains.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import logging
10
+ from contextvars import ContextVar
11
+ from typing import Any, Dict, Optional, Sequence
12
+
13
+ from turingpulse_sdk import instrument, GovernanceDirective
14
+ from turingpulse_sdk.config import MAX_FIELD_SIZE
15
+ from turingpulse_sdk.context import current_context
16
+
17
+ logger = logging.getLogger("turingpulse.sdk.strands")
18
+
19
+ _INSTRUMENTING: ContextVar[bool] = ContextVar("_tp_strands_instrumenting", default=False)
20
+
21
+
22
+ def instrument_strands(
23
+ agent,
24
+ *,
25
+ name: str,
26
+ governance: Optional[GovernanceDirective] = None,
27
+ model: Optional[str] = None,
28
+ provider: str = "bedrock",
29
+ kpis: Optional[Sequence["KPIConfig"]] = None,
30
+ metadata: Optional[Dict[str, str]] = None,
31
+ ):
32
+ """Wrap a Strands Agent for TuringPulse observability.
33
+
34
+ Returns a callable that instruments the agent invocation.
35
+
36
+ Args:
37
+ agent: A Strands ``Agent`` instance.
38
+ name: Workflow display name.
39
+ governance: Optional governance directive.
40
+ model: LLM model name override.
41
+ provider: LLM provider name.
42
+
43
+ Returns:
44
+ A callable wrapping the agent's __call__ method.
45
+ """
46
+
47
+ @instrument(name=name, governance=governance, kpis=kpis, metadata=metadata or {})
48
+ def _run(*args: Any, **kwargs: Any) -> Any:
49
+ token = _INSTRUMENTING.set(True)
50
+ try:
51
+ result = agent(*args, **kwargs)
52
+
53
+ ctx = current_context()
54
+ if ctx:
55
+ ctx.framework = "strands"
56
+ ctx.node_type = "workflow"
57
+
58
+ ctx.set_io(
59
+ input_data=str(args[0]) if args else str(kwargs),
60
+ output_data=str(result)[:MAX_FIELD_SIZE],
61
+ )
62
+
63
+ if model:
64
+ ctx.set_model(model, provider)
65
+
66
+ if hasattr(result, "metrics") and result.metrics:
67
+ metrics = result.metrics
68
+ ctx.set_tokens(
69
+ getattr(metrics, "input_tokens", 0) or 0,
70
+ getattr(metrics, "output_tokens", 0) or 0,
71
+ )
72
+
73
+ return result
74
+ finally:
75
+ _INSTRUMENTING.reset(token)
76
+
77
+ return _run