Skip to content

Commit f48ea25

Browse files
refactor(galileo): normalize records with galileo-core
1 parent 364ff45 commit f48ea25

5 files changed

Lines changed: 871 additions & 207 deletions

File tree

‎evaluators/contrib/galileo/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ authors = [{ name = "Agent Control Team" }]
99
dependencies = [
1010
"agent-control-evaluators>=8.6.0",
1111
"agent-control-models>=8.6.0",
12+
"galileo-core>=4.4.0,<5.0.0",
1213
"httpx>=0.24.0",
13-
"splunk-ao==0.4.0",
1414
"pydantic>=2.12.4",
1515
]
1616

‎evaluators/contrib/galileo/src/agent_control_evaluator_galileo/records/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
record_from_scorer_invoke_record,
1010
record_from_step,
1111
)
12+
from .normalization import GalileoRecordNormalizer
1213

1314
__all__ = [
1415
"GalileoRecord",
16+
"GalileoRecordNormalizer",
1517
"RecordFactoryError",
1618
"UnsupportedStepTypeError",
1719
"build_galileo_record",

‎evaluators/contrib/galileo/src/agent_control_evaluator_galileo/records/factory.py‎

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,12 @@
66
from typing import Any, cast
77

88
from agent_control_models import Step
9+
from galileo_core.schemas.logging.session import Session
10+
from galileo_core.schemas.logging.span import LlmSpan, RetrieverSpan, ToolSpan
11+
from galileo_core.schemas.logging.trace import Trace
912
from pydantic import BaseModel
10-
from splunk_ao import ( # type: ignore[import-untyped]
11-
LlmSpan,
12-
RetrieverSpan,
13-
Session,
14-
ToolSpan,
15-
Trace,
16-
)
17-
18-
from .normalization import (
19-
documents,
20-
message_value,
21-
session_value,
22-
string_metadata,
23-
text_value,
24-
tool_value,
25-
trace_input_value,
26-
trace_output_value,
27-
)
13+
14+
from .normalization import GalileoRecordNormalizer
2815

2916
type GalileoRecord = LlmSpan | ToolSpan | RetrieverSpan | Trace | Session
3017
type GalileoSpan = LlmSpan | ToolSpan | RetrieverSpan
@@ -111,7 +98,9 @@ def _record_from_mapping(raw: Mapping[str, Any], record_type: str) -> GalileoRec
11198
context = _mapping(raw.get("context")) or {}
11299
common = {
113100
"name": "" if raw.get("name") is None else str(raw["name"]),
114-
"user_metadata": string_metadata(raw.get("user_metadata", raw.get("metadata"))),
101+
"user_metadata": GalileoRecordNormalizer.metadata(
102+
raw.get("user_metadata", raw.get("metadata"))
103+
),
115104
}
116105
for field in (
117106
"tags",
@@ -126,9 +115,9 @@ def _record_from_mapping(raw: Mapping[str, Any], record_type: str) -> GalileoRec
126115
):
127116
if raw.get(field) is not None:
128117
common[field] = (
129-
text_value(raw[field])
118+
GalileoRecordNormalizer.json_text(raw[field])
130119
if field in {"dataset_input", "dataset_output"}
131-
else string_metadata(raw[field])
120+
else GalileoRecordNormalizer.metadata(raw[field])
132121
if field == "dataset_metadata"
133122
else raw[field]
134123
)
@@ -138,39 +127,55 @@ def _record_from_mapping(raw: Mapping[str, Any], record_type: str) -> GalileoRec
138127
if record_type == "llm":
139128
kwargs = {
140129
**common,
141-
"input": message_value(input_value),
142-
"output": message_value(output_value, output=True),
130+
"input": GalileoRecordNormalizer.llm_input(input_value),
131+
"output": GalileoRecordNormalizer.llm_output(output_value),
143132
}
144133
if raw.get("tools") is not None:
145-
kwargs["tools"] = raw["tools"]
134+
kwargs["tools"] = GalileoRecordNormalizer.llm_tools(raw["tools"])
146135
for field in ("events", "model", "temperature", "finish_reason"):
147136
if raw.get(field) is not None:
148137
kwargs[field] = raw[field]
149138
if raw.get("redacted_input") is not None:
150-
kwargs["redacted_input"] = message_value(raw["redacted_input"])
139+
kwargs["redacted_input"] = GalileoRecordNormalizer.llm_redacted_input(
140+
raw["redacted_input"]
141+
)
151142
if raw.get("redacted_output") is not None:
152-
kwargs["redacted_output"] = message_value(raw["redacted_output"], output=True)
143+
kwargs["redacted_output"] = GalileoRecordNormalizer.llm_redacted_output(
144+
raw["redacted_output"]
145+
)
153146
return LlmSpan(**kwargs)
154147
if record_type == "tool":
155148
kwargs = {
156149
**common,
157-
"input": tool_value(input_value) or "",
158-
"output": tool_value(output_value),
150+
"input": GalileoRecordNormalizer.tool_input(input_value),
151+
"output": GalileoRecordNormalizer.tool_output(output_value),
159152
}
160153
if raw.get("tool_call_id") is not None:
161154
kwargs["tool_call_id"] = str(raw["tool_call_id"])
162155
if raw.get("redacted_input") is not None:
163-
kwargs["redacted_input"] = tool_value(raw["redacted_input"])
156+
kwargs["redacted_input"] = GalileoRecordNormalizer.tool_redacted_input(
157+
raw["redacted_input"]
158+
)
164159
if raw.get("redacted_output") is not None:
165-
kwargs["redacted_output"] = tool_value(raw["redacted_output"])
160+
kwargs["redacted_output"] = GalileoRecordNormalizer.tool_redacted_output(
161+
raw["redacted_output"]
162+
)
166163
kwargs["spans"] = [_nested_span(item) for item in _span_payloads(raw, context)]
167164
return ToolSpan(**kwargs)
168165
if record_type == "retriever":
169-
kwargs = {**common, "input": text_value(input_value), "output": documents(output_value)}
166+
kwargs = {
167+
**common,
168+
"input": GalileoRecordNormalizer.retriever_input(input_value),
169+
"output": GalileoRecordNormalizer.retriever_output(output_value),
170+
}
170171
if raw.get("redacted_input") is not None:
171-
kwargs["redacted_input"] = text_value(raw["redacted_input"])
172+
kwargs["redacted_input"] = GalileoRecordNormalizer.retriever_redacted_input(
173+
raw["redacted_input"]
174+
)
172175
if raw.get("redacted_output") is not None:
173-
kwargs["redacted_output"] = documents(raw["redacted_output"])
176+
kwargs["redacted_output"] = GalileoRecordNormalizer.retriever_redacted_output(
177+
raw["redacted_output"]
178+
)
174179
kwargs["spans"] = [_nested_span(item) for item in _span_payloads(raw, context)]
175180
return RetrieverSpan(**kwargs)
176181
if record_type == "trace":
@@ -179,34 +184,45 @@ def _record_from_mapping(raw: Mapping[str, Any], record_type: str) -> GalileoRec
179184
raise RecordFactoryError("Galileo trace context must include a 'spans' list.")
180185
trace_kwargs: dict[str, Any] = {
181186
**common,
182-
"input": trace_input_value(input_value),
183-
"output": trace_output_value(output_value),
187+
"input": GalileoRecordNormalizer.trace_input(input_value),
188+
"output": GalileoRecordNormalizer.trace_output(output_value),
184189
"spans": [_nested_span(item) for item in spans],
185190
}
186191
if raw.get("redacted_input") is not None:
187-
trace_kwargs["redacted_input"] = trace_input_value(raw["redacted_input"])
192+
trace_kwargs["redacted_input"] = GalileoRecordNormalizer.trace_redacted_input(
193+
raw["redacted_input"]
194+
)
188195
if raw.get("redacted_output") is not None:
189-
trace_kwargs["redacted_output"] = trace_output_value(raw["redacted_output"])
196+
trace_kwargs["redacted_output"] = GalileoRecordNormalizer.trace_redacted_output(
197+
raw["redacted_output"]
198+
)
190199
return Trace(
191200
**trace_kwargs,
192201
)
193202
traces = raw.get("traces", context.get("traces"))
194203
if not isinstance(traces, Sequence) or isinstance(traces, str | bytes | bytearray):
195204
raise RecordFactoryError("Galileo session context must include a 'traces' list.")
196-
nested_records = [_nested_record(item) for item in traces]
205+
nested_records = GalileoRecordNormalizer.session_traces(
206+
traces,
207+
normalize_record=_nested_record,
208+
)
197209
nested_traces = [item for item in nested_records if isinstance(item, Trace)]
198210
if len(nested_traces) != len(nested_records):
199211
raise RecordFactoryError("Galileo session 'traces' must contain trace records.")
200212
session_kwargs: dict[str, Any] = {
201213
**common,
202-
"input": session_value(input_value),
203-
"output": session_value(output_value),
214+
"input": GalileoRecordNormalizer.session_input(input_value),
215+
"output": GalileoRecordNormalizer.session_output(output_value),
204216
"traces": cast(list[Trace], nested_traces),
205217
}
206218
if raw.get("redacted_input") is not None:
207-
session_kwargs["redacted_input"] = session_value(raw["redacted_input"])
219+
session_kwargs["redacted_input"] = GalileoRecordNormalizer.session_redacted_input(
220+
raw["redacted_input"]
221+
)
208222
if raw.get("redacted_output") is not None:
209-
session_kwargs["redacted_output"] = session_value(raw["redacted_output"])
223+
session_kwargs["redacted_output"] = GalileoRecordNormalizer.session_redacted_output(
224+
raw["redacted_output"]
225+
)
210226
return Session(
211227
**session_kwargs,
212228
)

0 commit comments

Comments
 (0)