agentsystems-notary 0.1.4__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.
- agentsystems_notary/__init__.py +26 -0
- agentsystems_notary/core.py +180 -0
- agentsystems_notary/crewai_adapter.py +134 -0
- agentsystems_notary/langchain_adapter.py +92 -0
- agentsystems_notary-0.1.4.dist-info/METADATA +208 -0
- agentsystems_notary-0.1.4.dist-info/RECORD +9 -0
- agentsystems_notary-0.1.4.dist-info/WHEEL +5 -0
- agentsystems_notary-0.1.4.dist-info/licenses/LICENSE +201 -0
- agentsystems_notary-0.1.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""AgentSystems Notary - Audit logging for LLM interactions."""
|
|
2
|
+
|
|
3
|
+
from importlib import metadata as _metadata
|
|
4
|
+
|
|
5
|
+
from .core import NotaryCore
|
|
6
|
+
|
|
7
|
+
__version__ = (
|
|
8
|
+
_metadata.version(__name__.replace("_", "-")) if __name__ != "__main__" else "0.0.0"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = ["__version__", "NotaryCore"]
|
|
12
|
+
|
|
13
|
+
# Framework adapters (optional - only available if dependencies installed)
|
|
14
|
+
try:
|
|
15
|
+
from .langchain_adapter import LangChainNotary # noqa: F401
|
|
16
|
+
|
|
17
|
+
__all__.append("LangChainNotary")
|
|
18
|
+
except ImportError:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
from .crewai_adapter import CrewAINotary # noqa: F401
|
|
23
|
+
|
|
24
|
+
__all__.append("CrewAINotary")
|
|
25
|
+
except ImportError:
|
|
26
|
+
pass
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Framework-agnostic core logic for Notary compliance logging."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import uuid
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
from importlib import metadata
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import boto3
|
|
10
|
+
import httpx
|
|
11
|
+
import jcs
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
__version__ = metadata.version("agentsystems-notary")
|
|
15
|
+
except metadata.PackageNotFoundError:
|
|
16
|
+
__version__ = "0.0.0"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class NotaryCore:
|
|
20
|
+
"""
|
|
21
|
+
Framework-agnostic notary logging core.
|
|
22
|
+
|
|
23
|
+
Handles canonicalization, hashing, and dual-write for any AI framework.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
api_key: Notary API key (from notary.agentsystems.ai)
|
|
27
|
+
slug: Tenant slug (e.g., "tnt_acme_corp")
|
|
28
|
+
vendor_bucket_name: S3 bucket name for raw logs
|
|
29
|
+
api_url: Notary API endpoint (default: production)
|
|
30
|
+
debug: Enable debug output (default: False)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
api_key: str,
|
|
36
|
+
slug: str,
|
|
37
|
+
vendor_bucket_name: str,
|
|
38
|
+
api_url: str = "https://notary-api.agentsystems.ai/v1/notary",
|
|
39
|
+
debug: bool = False,
|
|
40
|
+
):
|
|
41
|
+
self.api_key = api_key
|
|
42
|
+
self.slug = slug
|
|
43
|
+
self.bucket_name = vendor_bucket_name
|
|
44
|
+
self.api_url = api_url
|
|
45
|
+
self.debug = debug
|
|
46
|
+
|
|
47
|
+
# Detect environment from API key prefix
|
|
48
|
+
self.is_test_mode = api_key.startswith("sk_asn_test_")
|
|
49
|
+
|
|
50
|
+
# Initialize S3 client (uses AWS credentials from environment)
|
|
51
|
+
self.s3 = boto3.client("s3")
|
|
52
|
+
|
|
53
|
+
# Session tracking
|
|
54
|
+
self.session_id = str(uuid.uuid4())
|
|
55
|
+
self.sequence = 0
|
|
56
|
+
|
|
57
|
+
if self.debug and self.is_test_mode:
|
|
58
|
+
print("[Notary] Running in TEST mode - logs will not be notarized")
|
|
59
|
+
|
|
60
|
+
def log_interaction(
|
|
61
|
+
self,
|
|
62
|
+
input_data: dict[str, Any],
|
|
63
|
+
output_data: dict[str, Any],
|
|
64
|
+
metadata: dict[str, Any] | None = None,
|
|
65
|
+
) -> None:
|
|
66
|
+
"""
|
|
67
|
+
Log an LLM interaction with cryptographic verification.
|
|
68
|
+
|
|
69
|
+
This is the main entry point called by framework adapters.
|
|
70
|
+
Performs: canonicalization -> hashing -> dual-write
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
input_data: Framework-specific input (prompts, messages, etc.)
|
|
74
|
+
output_data: Framework-specific output (response text, etc.)
|
|
75
|
+
metadata: Additional metadata to include
|
|
76
|
+
"""
|
|
77
|
+
self.sequence += 1
|
|
78
|
+
|
|
79
|
+
# Build payload
|
|
80
|
+
payload = {
|
|
81
|
+
"metadata": {
|
|
82
|
+
"session_id": self.session_id,
|
|
83
|
+
"sequence": self.sequence,
|
|
84
|
+
"timestamp": datetime.now(UTC).isoformat(),
|
|
85
|
+
"slug": self.slug,
|
|
86
|
+
**(metadata or {}),
|
|
87
|
+
},
|
|
88
|
+
"input": input_data,
|
|
89
|
+
"output": output_data,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# 1. Canonicalize (deterministic JSON serialization)
|
|
93
|
+
canonical_bytes = jcs.canonicalize(payload)
|
|
94
|
+
|
|
95
|
+
if self.debug:
|
|
96
|
+
print("\n" + "=" * 80)
|
|
97
|
+
print("DATA_TO_HASH (canonical JSON):")
|
|
98
|
+
print(canonical_bytes.decode("utf-8"))
|
|
99
|
+
print("=" * 80)
|
|
100
|
+
|
|
101
|
+
# 2. Hash
|
|
102
|
+
content_hash = hashlib.sha256(canonical_bytes).hexdigest()
|
|
103
|
+
|
|
104
|
+
if self.debug:
|
|
105
|
+
print(f"HASH: {content_hash}")
|
|
106
|
+
print("=" * 80 + "\n")
|
|
107
|
+
|
|
108
|
+
# 3. Dual-Write
|
|
109
|
+
try:
|
|
110
|
+
self._upload_and_notarize(
|
|
111
|
+
canonical_bytes, content_hash, payload["metadata"]
|
|
112
|
+
)
|
|
113
|
+
except Exception as e:
|
|
114
|
+
print(f"Notary Log Failed: {e}")
|
|
115
|
+
|
|
116
|
+
def _upload_and_notarize(
|
|
117
|
+
self, data_bytes: bytes, content_hash: str, metadata: dict[str, Any]
|
|
118
|
+
) -> None:
|
|
119
|
+
"""
|
|
120
|
+
Perform dual-write to vendor S3 and Notary API.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
data_bytes: Canonical JSON bytes to store in S3
|
|
124
|
+
content_hash: SHA256 hash of canonical bytes
|
|
125
|
+
metadata: Event metadata (session_id, slug, etc.)
|
|
126
|
+
"""
|
|
127
|
+
# A. Neutral Notary (AgentSystems API) - call first to get tenant_id
|
|
128
|
+
# Always call API (handles tenant auto-creation, feed updates)
|
|
129
|
+
# API will skip ledger write for test keys
|
|
130
|
+
tenant_id: str | None = None
|
|
131
|
+
try:
|
|
132
|
+
with httpx.Client(timeout=5.0) as client:
|
|
133
|
+
resp = client.post(
|
|
134
|
+
self.api_url,
|
|
135
|
+
headers={
|
|
136
|
+
"X-API-Key": self.api_key,
|
|
137
|
+
"X-SDK-Version": __version__,
|
|
138
|
+
},
|
|
139
|
+
json={
|
|
140
|
+
"hash": content_hash,
|
|
141
|
+
"slug": self.slug,
|
|
142
|
+
"metadata": metadata,
|
|
143
|
+
},
|
|
144
|
+
)
|
|
145
|
+
if resp.status_code == 200:
|
|
146
|
+
result = resp.json()
|
|
147
|
+
receipt = result["receipt"]
|
|
148
|
+
tenant_id = result.get("tenant_id")
|
|
149
|
+
if self.debug:
|
|
150
|
+
print(f"[Notary] Verified! Receipt: {receipt[:8]}...")
|
|
151
|
+
else:
|
|
152
|
+
print(f"[Notary] Failed ({resp.status_code}): {resp.text}")
|
|
153
|
+
return # Don't write to S3 if notary failed
|
|
154
|
+
except Exception as e:
|
|
155
|
+
print(f"[Notary] Connection Error: {e}")
|
|
156
|
+
return # Don't write to S3 if notary failed
|
|
157
|
+
|
|
158
|
+
# B. Vendor Storage (Customer's S3 Bucket)
|
|
159
|
+
# Path: {env}/{tenant_id}/{YYYY}/{MM}/{DD}/{hash}.json
|
|
160
|
+
# Uses tenant UUID from API response (globally unique)
|
|
161
|
+
if not tenant_id:
|
|
162
|
+
print("[Vendor S3] Skipped: missing tenant_id from API")
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
env_prefix = "test" if self.is_test_mode else "prod"
|
|
166
|
+
date_path = datetime.now(UTC).strftime("%Y/%m/%d")
|
|
167
|
+
key = f"{env_prefix}/{tenant_id}/{date_path}/{content_hash}.json"
|
|
168
|
+
|
|
169
|
+
try:
|
|
170
|
+
self.s3.put_object(
|
|
171
|
+
Bucket=self.bucket_name,
|
|
172
|
+
Key=key,
|
|
173
|
+
Body=data_bytes,
|
|
174
|
+
ContentType="application/json",
|
|
175
|
+
Metadata={"hash": content_hash},
|
|
176
|
+
)
|
|
177
|
+
if self.debug:
|
|
178
|
+
print(f"[Vendor S3] Saved to {self.bucket_name}/{key}")
|
|
179
|
+
except Exception as e:
|
|
180
|
+
print(f"[Vendor S3] Failed: {e} (Check your AWS credentials)")
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""CrewAI adapter for Notary compliance logging."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from .core import NotaryCore
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from crewai.hooks import after_llm_call, before_llm_call
|
|
9
|
+
|
|
10
|
+
CREWAI_AVAILABLE = True
|
|
11
|
+
except ImportError:
|
|
12
|
+
CREWAI_AVAILABLE = False
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CrewAINotary:
|
|
16
|
+
"""
|
|
17
|
+
CrewAI hook handler for Notary compliance logging.
|
|
18
|
+
|
|
19
|
+
This is a thin adapter that extracts data from CrewAI's hook context
|
|
20
|
+
and passes it to the framework-agnostic NotaryCore.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
api_key: Notary API key (from notary.agentsystems.ai)
|
|
24
|
+
slug: Tenant slug (e.g., "tnt_acme_corp")
|
|
25
|
+
vendor_bucket_name: S3 bucket name for raw logs
|
|
26
|
+
api_url: Notary API endpoint (default: production)
|
|
27
|
+
debug: Enable debug output (default: False)
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
```python
|
|
31
|
+
from agentsystems_notary import CrewAINotary
|
|
32
|
+
from crewai import Agent, Task, Crew
|
|
33
|
+
|
|
34
|
+
# Initialize notary logging
|
|
35
|
+
notary = CrewAINotary(
|
|
36
|
+
api_key="sk_asn_prod_...",
|
|
37
|
+
slug="tnt_acme_corp",
|
|
38
|
+
vendor_bucket_name="acme-llm-logs"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Create crew - hooks are automatically registered
|
|
42
|
+
agent = Agent(role="Research Analyst", ...)
|
|
43
|
+
task = Task(description="Research AIUC-1 compliance", ...)
|
|
44
|
+
crew = Crew(agents=[agent], tasks=[task])
|
|
45
|
+
|
|
46
|
+
# All LLM calls are logged automatically
|
|
47
|
+
crew.kickoff()
|
|
48
|
+
```
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
def __init__(
|
|
52
|
+
self,
|
|
53
|
+
api_key: str,
|
|
54
|
+
slug: str,
|
|
55
|
+
vendor_bucket_name: str,
|
|
56
|
+
api_url: str = "https://notary-api.agentsystems.ai/v1/notary",
|
|
57
|
+
debug: bool = False,
|
|
58
|
+
):
|
|
59
|
+
if not CREWAI_AVAILABLE:
|
|
60
|
+
raise ImportError(
|
|
61
|
+
"CrewAI is not installed. Install it with: pip install crewai"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Initialize framework-agnostic core
|
|
65
|
+
self.core = NotaryCore(
|
|
66
|
+
api_key=api_key,
|
|
67
|
+
slug=slug,
|
|
68
|
+
vendor_bucket_name=vendor_bucket_name,
|
|
69
|
+
api_url=api_url,
|
|
70
|
+
debug=debug,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# Temporary storage for request data
|
|
74
|
+
self._current_request: dict[str, Any] | None = None
|
|
75
|
+
|
|
76
|
+
# Register hooks with CrewAI
|
|
77
|
+
self._register_hooks()
|
|
78
|
+
|
|
79
|
+
def _register_hooks(self) -> None:
|
|
80
|
+
"""Register before/after hooks with CrewAI."""
|
|
81
|
+
|
|
82
|
+
@before_llm_call # type: ignore
|
|
83
|
+
def _notary_before_llm(context: Any) -> None:
|
|
84
|
+
"""Capture LLM request from CrewAI context."""
|
|
85
|
+
# Extract messages from context
|
|
86
|
+
messages = []
|
|
87
|
+
if hasattr(context, "messages") and context.messages:
|
|
88
|
+
for msg in context.messages:
|
|
89
|
+
messages.append(
|
|
90
|
+
{
|
|
91
|
+
"role": getattr(msg, "role", "unknown"),
|
|
92
|
+
"content": getattr(msg, "content", str(msg)),
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Store request data
|
|
97
|
+
self._current_request = {
|
|
98
|
+
"messages": messages,
|
|
99
|
+
"agent": context.agent.role if context.agent else None,
|
|
100
|
+
"task": context.task.description if context.task else None,
|
|
101
|
+
"crew": context.crew.name if hasattr(context.crew, "name") else None,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return None # Allow execution
|
|
105
|
+
|
|
106
|
+
@after_llm_call # type: ignore
|
|
107
|
+
def _notary_after_llm(context: Any) -> None:
|
|
108
|
+
"""Capture LLM response and log to Notary."""
|
|
109
|
+
if self._current_request is None:
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
# Extract response from context
|
|
113
|
+
output_data = {
|
|
114
|
+
"text": context.response if hasattr(context, "response") else ""
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
# Build metadata from CrewAI context
|
|
118
|
+
metadata: dict[str, Any] = {}
|
|
119
|
+
if context.agent:
|
|
120
|
+
metadata["agent_role"] = context.agent.role
|
|
121
|
+
if context.task:
|
|
122
|
+
# Truncate long descriptions
|
|
123
|
+
metadata["task_description"] = context.task.description[:100]
|
|
124
|
+
if hasattr(context, "iterations"):
|
|
125
|
+
metadata["iteration"] = context.iterations
|
|
126
|
+
|
|
127
|
+
# Call framework-agnostic core
|
|
128
|
+
self.core.log_interaction(
|
|
129
|
+
input_data=self._current_request,
|
|
130
|
+
output_data=output_data,
|
|
131
|
+
metadata=metadata,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
return None # Don't modify response
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""LangChain adapter for Notary compliance logging."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from langchain_core.callbacks import BaseCallbackHandler
|
|
6
|
+
|
|
7
|
+
from .core import NotaryCore
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LangChainNotary(BaseCallbackHandler): # type: ignore[misc]
|
|
11
|
+
"""
|
|
12
|
+
LangChain callback handler for Notary compliance logging.
|
|
13
|
+
|
|
14
|
+
This is a thin adapter that extracts data from LangChain's callback
|
|
15
|
+
interface and passes it to the framework-agnostic NotaryCore.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
api_key: Notary API key (from notary.agentsystems.ai)
|
|
19
|
+
slug: Tenant slug (e.g., "tnt_acme_corp")
|
|
20
|
+
vendor_bucket_name: S3 bucket name for raw logs
|
|
21
|
+
api_url: Notary API endpoint (default: production)
|
|
22
|
+
debug: Enable debug output (default: False)
|
|
23
|
+
|
|
24
|
+
Example:
|
|
25
|
+
```python
|
|
26
|
+
from agentsystems_notary import LangChainNotary
|
|
27
|
+
from langchain_anthropic import ChatAnthropic
|
|
28
|
+
|
|
29
|
+
callback = LangChainNotary(
|
|
30
|
+
api_key="sk_asn_prod_...",
|
|
31
|
+
slug="tnt_acme_corp",
|
|
32
|
+
vendor_bucket_name="acme-llm-logs"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
model = ChatAnthropic(
|
|
36
|
+
model="claude-sonnet-4-5-20250929",
|
|
37
|
+
callbacks=[callback]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
response = model.invoke("What is AIUC-1 compliance?")
|
|
41
|
+
```
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
api_key: str,
|
|
47
|
+
slug: str,
|
|
48
|
+
vendor_bucket_name: str,
|
|
49
|
+
api_url: str = "https://notary-api.agentsystems.ai/v1/notary",
|
|
50
|
+
debug: bool = False,
|
|
51
|
+
):
|
|
52
|
+
# Initialize framework-agnostic core
|
|
53
|
+
self.core = NotaryCore(
|
|
54
|
+
api_key=api_key,
|
|
55
|
+
slug=slug,
|
|
56
|
+
vendor_bucket_name=vendor_bucket_name,
|
|
57
|
+
api_url=api_url,
|
|
58
|
+
debug=debug,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Temporary storage for request data
|
|
62
|
+
self.current_request: dict[str, Any] = {}
|
|
63
|
+
|
|
64
|
+
def on_llm_start(
|
|
65
|
+
self, serialized: dict[str, Any], prompts: list[str], **kwargs: Any
|
|
66
|
+
) -> None:
|
|
67
|
+
"""Capture LLM request metadata."""
|
|
68
|
+
self.current_request = {
|
|
69
|
+
"prompts": prompts,
|
|
70
|
+
"timestamp": kwargs.get("timestamp"),
|
|
71
|
+
"model_config": kwargs.get("invocation_params", {}),
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
def on_llm_end(self, response: Any, **kwargs: Any) -> None:
|
|
75
|
+
"""
|
|
76
|
+
Capture LLM response and log to Notary.
|
|
77
|
+
|
|
78
|
+
Extracts response from LangChain's response object and calls
|
|
79
|
+
the framework-agnostic core logging method.
|
|
80
|
+
"""
|
|
81
|
+
# Extract response text from LangChain's response structure
|
|
82
|
+
if response.generations:
|
|
83
|
+
response_text = response.generations[0][0].text
|
|
84
|
+
else:
|
|
85
|
+
response_text = ""
|
|
86
|
+
|
|
87
|
+
# Call framework-agnostic core
|
|
88
|
+
self.core.log_interaction(
|
|
89
|
+
input_data=self.current_request,
|
|
90
|
+
output_data={"text": response_text},
|
|
91
|
+
metadata={},
|
|
92
|
+
)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentsystems-notary
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Cryptographic notarization SDK for LLM interactions
|
|
5
|
+
Author-email: AgentSystems <support@agentsystems.ai>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: boto3>=1.34.0
|
|
11
|
+
Requires-Dist: httpx>=0.25.0
|
|
12
|
+
Requires-Dist: jcs>=0.2.1
|
|
13
|
+
Provides-Extra: langchain
|
|
14
|
+
Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
|
|
15
|
+
Provides-Extra: crewai
|
|
16
|
+
Requires-Dist: crewai>=0.1.0; extra == "crewai"
|
|
17
|
+
Provides-Extra: all
|
|
18
|
+
Requires-Dist: langchain-core>=0.1.0; extra == "all"
|
|
19
|
+
Requires-Dist: crewai>=0.1.0; extra == "all"
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
23
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
25
|
+
Requires-Dist: mypy>=1.5; extra == "dev"
|
|
26
|
+
Requires-Dist: build; extra == "dev"
|
|
27
|
+
Requires-Dist: twine; extra == "dev"
|
|
28
|
+
Requires-Dist: pip-licenses>=4.0.0; extra == "dev"
|
|
29
|
+
Provides-Extra: license-files
|
|
30
|
+
Requires-Dist: LICENSE; extra == "license-files"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# AgentSystems Notary
|
|
34
|
+
|
|
35
|
+
[](https://pypi.org/project/agentsystems-notary/)
|
|
36
|
+
|
|
37
|
+
> **Audit logging infrastructure for AI systems**
|
|
38
|
+
|
|
39
|
+
AgentSystems Notary provides tamper-evident audit trails for AI systems. It creates cryptographically verifiable logs of all LLM interactions with dual-write architecture: your S3 bucket (raw logs) + Notary ledger (hash receipts).
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Multi-Framework Support**: LangChain and CrewAI adapters (extensible to other frameworks)
|
|
44
|
+
- **Dual-Write Architecture**: Vendor S3 (raw logs) + Notary API (hash receipts)
|
|
45
|
+
- **Cryptographic Verification**: SHA-256 hashes with JCS canonicalization (RFC 8785)
|
|
46
|
+
- **Tenant Isolation**: Multi-tenant support for SaaS applications
|
|
47
|
+
- **Audit Trail Architecture**: Designed with verifiability and auditability in mind
|
|
48
|
+
|
|
49
|
+
## Disclaimer
|
|
50
|
+
|
|
51
|
+
This SDK provides technical infrastructure for audit logging. It does not guarantee regulatory compliance, which depends on your specific jurisdiction, industry, policies, and operational practices. This SDK does not constitute legal, compliance, or regulatory advice. Consult with qualified legal and compliance professionals for your specific requirements.
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Install with LangChain support
|
|
57
|
+
pip install agentsystems-notary[langchain]
|
|
58
|
+
|
|
59
|
+
# Install with CrewAI support
|
|
60
|
+
pip install agentsystems-notary[crewai]
|
|
61
|
+
|
|
62
|
+
# Install with both
|
|
63
|
+
pip install agentsystems-notary[all]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
### LangChain
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from agentsystems_notary import LangChainNotary
|
|
72
|
+
from langchain_anthropic import ChatAnthropic
|
|
73
|
+
|
|
74
|
+
# 1. Create notary callback
|
|
75
|
+
notary = LangChainNotary(
|
|
76
|
+
api_key="sk_asn_prod_...", # From notary.agentsystems.ai
|
|
77
|
+
slug="tnt_acme_corp", # Your tenant slug
|
|
78
|
+
vendor_bucket_name="acme-llm-logs" # Your S3 bucket
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# 2. Add to any LangChain model
|
|
82
|
+
model = ChatAnthropic(
|
|
83
|
+
model="claude-sonnet-4-5-20250929",
|
|
84
|
+
callbacks=[notary]
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# 3. Use normally - logs are automatic
|
|
88
|
+
response = model.invoke("What is AIUC-1 compliance?")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### CrewAI
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from agentsystems_notary import CrewAINotary
|
|
95
|
+
from crewai import Agent, Task, Crew
|
|
96
|
+
|
|
97
|
+
# 1. Initialize notary (registers hooks automatically)
|
|
98
|
+
notary = CrewAINotary(
|
|
99
|
+
api_key="sk_asn_prod_...",
|
|
100
|
+
slug="tnt_acme_corp",
|
|
101
|
+
vendor_bucket_name="acme-llm-logs"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# 2. Create crew normally
|
|
105
|
+
agent = Agent(role="Research Analyst", goal="...", backstory="...")
|
|
106
|
+
task = Task(description="Research AIUC-1 compliance", agent=agent)
|
|
107
|
+
crew = Crew(agents=[agent], tasks=[task])
|
|
108
|
+
|
|
109
|
+
# 3. All LLM calls are logged automatically
|
|
110
|
+
crew.kickoff()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## How It Works
|
|
114
|
+
|
|
115
|
+
1. **Capture**: Intercepts LLM requests/responses via LangChain callbacks
|
|
116
|
+
2. **Canonicalize**: Deterministic JSON serialization (JCS/RFC 8785)
|
|
117
|
+
3. **Hash**: SHA-256 of canonical bytes
|
|
118
|
+
4. **Dual-Write**:
|
|
119
|
+
- Your S3 bucket: Full canonical JSON (verifiable by re-hashing)
|
|
120
|
+
- Notary API: Hash receipt (immutable ledger)
|
|
121
|
+
|
|
122
|
+
## Configuration
|
|
123
|
+
|
|
124
|
+
### Environment Variables
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# AWS credentials (for vendor S3 bucket)
|
|
128
|
+
export AWS_ACCESS_KEY_ID=...
|
|
129
|
+
export AWS_SECRET_ACCESS_KEY=...
|
|
130
|
+
export AWS_DEFAULT_REGION=us-east-1
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Debug Mode
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
notary = LangChainNotary(
|
|
137
|
+
api_key="sk_asn_prod_...",
|
|
138
|
+
slug="tnt_acme_corp",
|
|
139
|
+
vendor_bucket_name="acme-llm-logs",
|
|
140
|
+
debug=True # Prints canonical JSON and hashes
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Multi-Tenant Setup
|
|
145
|
+
|
|
146
|
+
For SaaS applications serving multiple end-customers:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
# Each end-customer gets their own tenant
|
|
150
|
+
notary_bank_a = LangChainNotary(
|
|
151
|
+
api_key="sk_asn_prod_...",
|
|
152
|
+
slug="tnt_bank_a", # Bank A's logs
|
|
153
|
+
vendor_bucket_name="your-logs"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
notary_bank_b = LangChainNotary(
|
|
157
|
+
api_key="sk_asn_prod_...",
|
|
158
|
+
slug="tnt_bank_b", # Bank B's logs (isolated)
|
|
159
|
+
vendor_bucket_name="your-logs"
|
|
160
|
+
)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## API Keys
|
|
164
|
+
|
|
165
|
+
Generate API keys at [notary.agentsystems.ai](https://notary.agentsystems.ai).
|
|
166
|
+
|
|
167
|
+
## S3 Bucket Structure
|
|
168
|
+
|
|
169
|
+
Vendor bucket (your S3):
|
|
170
|
+
```
|
|
171
|
+
logs/
|
|
172
|
+
{slug}/
|
|
173
|
+
{session_id}/
|
|
174
|
+
1.json
|
|
175
|
+
2.json
|
|
176
|
+
3.json
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Each file contains canonical JSON that can be re-hashed to verify the hash receipt.
|
|
180
|
+
|
|
181
|
+
## Verification
|
|
182
|
+
|
|
183
|
+
To verify a log entry:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
import hashlib
|
|
187
|
+
import jcs
|
|
188
|
+
|
|
189
|
+
# 1. Download from your S3 bucket
|
|
190
|
+
log_data = s3.get_object(Bucket="your-bucket", Key="logs/tnt_acme/session-123/1.json")
|
|
191
|
+
|
|
192
|
+
# 2. Re-hash
|
|
193
|
+
canonical_bytes = log_data["Body"].read()
|
|
194
|
+
computed_hash = hashlib.sha256(canonical_bytes).hexdigest()
|
|
195
|
+
|
|
196
|
+
# 3. Compare with Notary receipt
|
|
197
|
+
assert computed_hash == notary_receipt_hash # Proof of integrity
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Support
|
|
201
|
+
|
|
202
|
+
- **Documentation**: [docs.agentsystems.ai/notary](https://docs.agentsystems.ai/notary/)
|
|
203
|
+
- **Dashboard**: [notary.agentsystems.ai](https://notary.agentsystems.ai)
|
|
204
|
+
- **Issues**: [GitHub Issues](https://github.com/agentsystems/agentsystems-notary/issues)
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
Licensed under the [Apache-2.0 license](./LICENSE).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
agentsystems_notary/__init__.py,sha256=MYQ-Ng0X2MlTNIJMYpUUI4Hzo-IfR102Nec_a11IIx4,632
|
|
2
|
+
agentsystems_notary/core.py,sha256=si5GJiElxO8In5gocSgW1NfFGy81BVw4c65oYhd8vhs,6053
|
|
3
|
+
agentsystems_notary/crewai_adapter.py,sha256=8GQ-Zr-fufkFTpwK1kKnp-PvmtwMX9JGmhnzKPgC_hI,4391
|
|
4
|
+
agentsystems_notary/langchain_adapter.py,sha256=N2jBecmUvhDj3cug1forGrLK_g3gs4DjZOYQDUqMwHo,2820
|
|
5
|
+
agentsystems_notary-0.1.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
+
agentsystems_notary-0.1.4.dist-info/METADATA,sha256=yejtYtME1JH9QgCURKvRo3fQkn57r592KLJBBEUnam4,5977
|
|
7
|
+
agentsystems_notary-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
agentsystems_notary-0.1.4.dist-info/top_level.txt,sha256=3VzHkYEwpMkO-el0Ob-xfU4iq2dTbQGh5kFpyqFN68k,20
|
|
9
|
+
agentsystems_notary-0.1.4.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
agentsystems_notary
|