Spaces:
Running
Running
feat: enhance protocol schema and add audit log traceability
Browse files
app/services/k2_think_engine.py
CHANGED
|
@@ -107,6 +107,12 @@ class K2ThinkEngine:
|
|
| 107 |
"proposed_protocol": {{
|
| 108 |
"title": "...",
|
| 109 |
"objective": "...",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
"steps": [
|
| 111 |
{{ "description": "...", "duration_hours": 1, "materials": [], "critical_parameters": [] }}
|
| 112 |
]
|
|
@@ -325,6 +331,19 @@ DO NOT USE <think> TAGS. DO NOT CONVERSE.
|
|
| 325 |
hypotheses = self._convert_k2_to_counter_hypotheses(k2_analysis)
|
| 326 |
protocol = await self._convert_k2_to_protocol(k2_analysis)
|
| 327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
result = AnalysisResult(
|
| 329 |
request_id=request_id,
|
| 330 |
documents_analyzed=len(request.documents),
|
|
|
|
| 107 |
"proposed_protocol": {{
|
| 108 |
"title": "...",
|
| 109 |
"objective": "...",
|
| 110 |
+
"hypothesis": "...",
|
| 111 |
+
"expected_outcomes": "...",
|
| 112 |
+
"variables": [
|
| 113 |
+
{{ "name": "...", "type": "independent", "measurement_method": "..." }}
|
| 114 |
+
],
|
| 115 |
+
"risk_assessment": {{ "overall_risk": "low" }},
|
| 116 |
"steps": [
|
| 117 |
{{ "description": "...", "duration_hours": 1, "materials": [], "critical_parameters": [] }}
|
| 118 |
]
|
|
|
|
| 331 |
hypotheses = self._convert_k2_to_counter_hypotheses(k2_analysis)
|
| 332 |
protocol = await self._convert_k2_to_protocol(k2_analysis)
|
| 333 |
|
| 334 |
+
# Ensure reasoning trace is populated for Audit Log
|
| 335 |
+
trace_val = k2_analysis.get("reasoning_trace")
|
| 336 |
+
if isinstance(trace_val, str):
|
| 337 |
+
self._log_reasoning("ANALYSIS", "K2 Synthesis", trace_val)
|
| 338 |
+
elif isinstance(trace_val, list):
|
| 339 |
+
for t in trace_val:
|
| 340 |
+
if isinstance(t, dict) and "reasoning" in t:
|
| 341 |
+
self.reasoning_trace.append(t)
|
| 342 |
+
else:
|
| 343 |
+
self._log_reasoning("ANALYSIS", "K2 Synthesis", str(t))
|
| 344 |
+
elif not self.reasoning_trace:
|
| 345 |
+
self._log_reasoning("ANALYSIS", "K2 Synthesis", "Analysis generated successfully.")
|
| 346 |
+
|
| 347 |
result = AnalysisResult(
|
| 348 |
request_id=request_id,
|
| 349 |
documents_analyzed=len(request.documents),
|