agentguard-core-schema 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.
- agentguard_core_schema-1.0.0/PKG-INFO +14 -0
- agentguard_core_schema-1.0.0/agentguard_core_schema/__init__.py +33 -0
- agentguard_core_schema-1.0.0/agentguard_core_schema/schemas.py +184 -0
- agentguard_core_schema-1.0.0/agentguard_core_schema.egg-info/PKG-INFO +14 -0
- agentguard_core_schema-1.0.0/agentguard_core_schema.egg-info/SOURCES.txt +8 -0
- agentguard_core_schema-1.0.0/agentguard_core_schema.egg-info/dependency_links.txt +1 -0
- agentguard_core_schema-1.0.0/agentguard_core_schema.egg-info/requires.txt +9 -0
- agentguard_core_schema-1.0.0/agentguard_core_schema.egg-info/top_level.txt +1 -0
- agentguard_core_schema-1.0.0/pyproject.toml +37 -0
- agentguard_core_schema-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentguard-core-schema
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Core schemas for AgentGuard forensic trace format
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pydantic>=2.0.0
|
|
8
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
11
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
12
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
13
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
14
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from .schemas import (
|
|
2
|
+
AgentActionTrace,
|
|
3
|
+
ToolCall,
|
|
4
|
+
InputContext,
|
|
5
|
+
ThoughtChain,
|
|
6
|
+
Observation,
|
|
7
|
+
SafetyValidation,
|
|
8
|
+
TraceBundle,
|
|
9
|
+
CreateTraceRequest,
|
|
10
|
+
TraceQuery,
|
|
11
|
+
RiskLevel,
|
|
12
|
+
ApprovalStatus,
|
|
13
|
+
Environment,
|
|
14
|
+
calculate_trace_hash,
|
|
15
|
+
validate_trace_chain,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"AgentActionTrace",
|
|
20
|
+
"ToolCall",
|
|
21
|
+
"InputContext",
|
|
22
|
+
"ThoughtChain",
|
|
23
|
+
"Observation",
|
|
24
|
+
"SafetyValidation",
|
|
25
|
+
"TraceBundle",
|
|
26
|
+
"CreateTraceRequest",
|
|
27
|
+
"TraceQuery",
|
|
28
|
+
"RiskLevel",
|
|
29
|
+
"ApprovalStatus",
|
|
30
|
+
"Environment",
|
|
31
|
+
"calculate_trace_hash",
|
|
32
|
+
"validate_trace_chain",
|
|
33
|
+
]
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
from uuid import UUID, uuid4
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field, field_validator
|
|
7
|
+
import hashlib
|
|
8
|
+
import json
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RiskLevel(str, Enum):
|
|
12
|
+
LOW = "LOW"
|
|
13
|
+
MEDIUM = "MEDIUM"
|
|
14
|
+
HIGH = "HIGH"
|
|
15
|
+
CRITICAL = "CRITICAL"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ApprovalStatus(str, Enum):
|
|
19
|
+
APPROVED = "APPROVED"
|
|
20
|
+
PENDING_APPROVAL = "PENDING_APPROVAL"
|
|
21
|
+
REJECTED = "REJECTED"
|
|
22
|
+
AUTO_APPROVED = "AUTO_APPROVED"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Environment(str, Enum):
|
|
26
|
+
DEVELOPMENT = "DEVELOPMENT"
|
|
27
|
+
STAGING = "STAGING"
|
|
28
|
+
PRODUCTION = "PRODUCTION"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class RetrievedSnippet(BaseModel):
|
|
32
|
+
source: str
|
|
33
|
+
content: str
|
|
34
|
+
relevance_score: float = Field(ge=0.0, le=1.0)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class InputContext(BaseModel):
|
|
38
|
+
prompt: str
|
|
39
|
+
retrieved_snippets: Optional[List[RetrievedSnippet]] = None
|
|
40
|
+
system_context: Optional[Dict[str, Any]] = None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ThoughtChain(BaseModel):
|
|
44
|
+
raw_tokens: str
|
|
45
|
+
parsed_steps: Optional[List[str]] = None
|
|
46
|
+
confidence_score: Optional[float] = Field(None, ge=0.0, le=1.0)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ToolCall(BaseModel):
|
|
50
|
+
tool_name: str
|
|
51
|
+
function: str
|
|
52
|
+
arguments: Dict[str, Any]
|
|
53
|
+
timestamp: datetime
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class Observation(BaseModel):
|
|
57
|
+
raw_output: Any
|
|
58
|
+
error: Optional[str] = None
|
|
59
|
+
duration_ms: float = Field(gt=0)
|
|
60
|
+
metadata: Optional[Dict[str, Any]] = None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class SafetyValidation(BaseModel):
|
|
64
|
+
policy_name: str
|
|
65
|
+
passed: bool
|
|
66
|
+
violations: Optional[List[str]] = None
|
|
67
|
+
risk_level: RiskLevel
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class AgentActionTrace(BaseModel):
|
|
71
|
+
trace_id: UUID = Field(default_factory=uuid4)
|
|
72
|
+
parent_trace_id: Optional[UUID] = None
|
|
73
|
+
agent_id: UUID
|
|
74
|
+
timestamp: datetime = Field(default_factory=datetime.utcnow)
|
|
75
|
+
sequence_number: int = Field(ge=0)
|
|
76
|
+
|
|
77
|
+
# Core fields
|
|
78
|
+
input_context: InputContext
|
|
79
|
+
thought_chain: ThoughtChain
|
|
80
|
+
tool_call: ToolCall
|
|
81
|
+
observation: Observation
|
|
82
|
+
|
|
83
|
+
# Security & Integrity
|
|
84
|
+
integrity_hash: str = Field(regex=r"^[a-f0-9]{64}$", description="SHA-256 hash")
|
|
85
|
+
previous_hash: Optional[str] = Field(None, regex=r"^[a-f0-9]{64}$")
|
|
86
|
+
signature: Optional[str] = None
|
|
87
|
+
|
|
88
|
+
# Safety & Compliance
|
|
89
|
+
safety_validation: Optional[SafetyValidation] = None
|
|
90
|
+
approval_status: Optional[ApprovalStatus] = None
|
|
91
|
+
approved_by: Optional[str] = None
|
|
92
|
+
|
|
93
|
+
# Metadata
|
|
94
|
+
environment: Environment = Environment.DEVELOPMENT
|
|
95
|
+
version: str = "1.0.0"
|
|
96
|
+
tags: Optional[List[str]] = None
|
|
97
|
+
|
|
98
|
+
@field_validator("integrity_hash", "previous_hash")
|
|
99
|
+
@classmethod
|
|
100
|
+
def validate_hash(cls, v: Optional[str]) -> Optional[str]:
|
|
101
|
+
if v is not None and not all(c in "0123456789abcdefABCDEF" for c in v):
|
|
102
|
+
raise ValueError("Invalid hash format")
|
|
103
|
+
return v.lower() if v else v
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class TraceBundle(BaseModel):
|
|
107
|
+
bundle_id: UUID = Field(default_factory=uuid4)
|
|
108
|
+
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
109
|
+
traces: List[AgentActionTrace]
|
|
110
|
+
metadata: Dict[str, Any] = Field(
|
|
111
|
+
default_factory=lambda: {
|
|
112
|
+
"agent_id": None,
|
|
113
|
+
"session_id": None,
|
|
114
|
+
"export_reason": "",
|
|
115
|
+
"total_traces": 0,
|
|
116
|
+
"hash_chain_valid": False,
|
|
117
|
+
"signature": None,
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class CreateTraceRequest(BaseModel):
|
|
123
|
+
parent_trace_id: Optional[UUID] = None
|
|
124
|
+
agent_id: UUID
|
|
125
|
+
timestamp: datetime = Field(default_factory=datetime.utcnow)
|
|
126
|
+
sequence_number: int = Field(ge=0)
|
|
127
|
+
|
|
128
|
+
input_context: InputContext
|
|
129
|
+
thought_chain: ThoughtChain
|
|
130
|
+
tool_call: ToolCall
|
|
131
|
+
observation: Observation
|
|
132
|
+
|
|
133
|
+
previous_hash: Optional[str] = Field(None, regex=r"^[a-f0-9]{64}$")
|
|
134
|
+
|
|
135
|
+
safety_validation: Optional[SafetyValidation] = None
|
|
136
|
+
approval_status: Optional[ApprovalStatus] = None
|
|
137
|
+
approved_by: Optional[str] = None
|
|
138
|
+
|
|
139
|
+
environment: Environment = Environment.DEVELOPMENT
|
|
140
|
+
version: str = "1.0.0"
|
|
141
|
+
tags: Optional[List[str]] = None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class TraceQuery(BaseModel):
|
|
145
|
+
agent_id: Optional[UUID] = None
|
|
146
|
+
start_time: Optional[datetime] = None
|
|
147
|
+
end_time: Optional[datetime] = None
|
|
148
|
+
risk_level: Optional[RiskLevel] = None
|
|
149
|
+
approval_status: Optional[ApprovalStatus] = None
|
|
150
|
+
limit: int = Field(default=100, gt=0, le=1000)
|
|
151
|
+
offset: int = Field(default=0, ge=0)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def calculate_trace_hash(trace: Dict[str, Any]) -> str:
|
|
155
|
+
"""Calculate SHA-256 hash for a trace object."""
|
|
156
|
+
# Extract relevant fields for hashing
|
|
157
|
+
hash_content = {
|
|
158
|
+
"trace_id": str(trace.get("trace_id", "")),
|
|
159
|
+
"agent_id": str(trace.get("agent_id", "")),
|
|
160
|
+
"timestamp": str(trace.get("timestamp", "")),
|
|
161
|
+
"input_context": trace.get("input_context", {}),
|
|
162
|
+
"thought_chain": trace.get("thought_chain", {}),
|
|
163
|
+
"tool_call": trace.get("tool_call", {}),
|
|
164
|
+
"observation": trace.get("observation", {}),
|
|
165
|
+
"previous_hash": trace.get("previous_hash", ""),
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# Serialize to JSON with sorted keys for consistency
|
|
169
|
+
content = json.dumps(hash_content, sort_keys=True, default=str)
|
|
170
|
+
|
|
171
|
+
# Calculate SHA-256 hash
|
|
172
|
+
return hashlib.sha256(content.encode()).hexdigest()
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def validate_trace_chain(traces: List[AgentActionTrace]) -> bool:
|
|
176
|
+
"""Validate the hash chain integrity of a list of traces."""
|
|
177
|
+
if not traces:
|
|
178
|
+
return True
|
|
179
|
+
|
|
180
|
+
for i in range(1, len(traces)):
|
|
181
|
+
if traces[i].previous_hash != traces[i - 1].integrity_hash:
|
|
182
|
+
return False
|
|
183
|
+
|
|
184
|
+
return True
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentguard-core-schema
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Core schemas for AgentGuard forensic trace format
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pydantic>=2.0.0
|
|
8
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
11
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
12
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
13
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
14
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
agentguard_core_schema/__init__.py
|
|
3
|
+
agentguard_core_schema/schemas.py
|
|
4
|
+
agentguard_core_schema.egg-info/PKG-INFO
|
|
5
|
+
agentguard_core_schema.egg-info/SOURCES.txt
|
|
6
|
+
agentguard_core_schema.egg-info/dependency_links.txt
|
|
7
|
+
agentguard_core_schema.egg-info/requires.txt
|
|
8
|
+
agentguard_core_schema.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
agentguard_core_schema
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "agentguard-core-schema"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Core schemas for AgentGuard forensic trace format"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"pydantic>=2.0.0",
|
|
13
|
+
"pydantic-settings>=2.0.0"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
dev = [
|
|
18
|
+
"pytest>=7.0.0",
|
|
19
|
+
"pytest-cov>=4.0.0",
|
|
20
|
+
"mypy>=1.0.0",
|
|
21
|
+
"black>=23.0.0",
|
|
22
|
+
"ruff>=0.1.0"
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.mypy]
|
|
26
|
+
python_version = "3.10"
|
|
27
|
+
warn_return_any = true
|
|
28
|
+
warn_unused_configs = true
|
|
29
|
+
disallow_untyped_defs = true
|
|
30
|
+
|
|
31
|
+
[tool.ruff]
|
|
32
|
+
line-length = 120
|
|
33
|
+
target-version = "py310"
|
|
34
|
+
|
|
35
|
+
[tool.black]
|
|
36
|
+
line-length = 120
|
|
37
|
+
target-version = ['py310']
|