harness-evolver 0.1.0

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
+ """TraceLogger — optional helper for harnesses to write structured trace records.
2
+
3
+ Usage in a harness:
4
+ from trace_logger import TraceLogger
5
+
6
+ trace = TraceLogger(traces_dir)
7
+ trace.step("llm_call", {"prompt": p, "response": r, "model": "gpt-4"})
8
+ trace.step("tool_use", {"tool": "search", "query": q, "results": results})
9
+ trace.save()
10
+
11
+ Stdlib-only. No external dependencies.
12
+ """
13
+
14
+ import json
15
+ import os
16
+ import time
17
+
18
+
19
+ class TraceLogger:
20
+ def __init__(self, traces_dir):
21
+ self.traces_dir = traces_dir
22
+ self._steps = []
23
+ if traces_dir:
24
+ os.makedirs(traces_dir, exist_ok=True)
25
+
26
+ def step(self, name, data=None):
27
+ self._steps.append({
28
+ "name": name,
29
+ "timestamp": time.time(),
30
+ "data": data if data is not None else {},
31
+ })
32
+
33
+ def save(self):
34
+ if not self.traces_dir:
35
+ return
36
+ path = os.path.join(self.traces_dir, "trace.json")
37
+ with open(path, "w") as f:
38
+ json.dump(self._steps, f, indent=2)
39
+
40
+ @property
41
+ def steps(self):
42
+ return list(self._steps)