agent-apprenticeship 0.2.0 → 0.3.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.
- package/README.md +269 -3
- package/bin/agent-apprenticeship.js +1 -2
- package/package.json +4 -4
- package/pyproject.toml +10 -4
- package/schemas/environment_replay.schema.json +41 -0
- package/schemas/eval_package.schema.json +37 -0
- package/schemas/experience_compilation.schema.json +53 -0
- package/schemas/runtime_training.schema.json +33 -0
- package/schemas/source_evidence_map.schema.json +25 -0
- package/schemas/trace.schema.json +904 -0
- package/schemas/trace_step.schema.json +622 -0
- package/schemas/training_rows.schema.json +29 -0
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/__init__.py +1 -1
- package/src/agent_apprenticeship/agent_env_exporter.py +53 -0
- package/src/agent_apprenticeship/agent_env_verify.py +32 -0
- package/src/agent_apprenticeship/atif.py +152 -0
- package/src/agent_apprenticeship/atif_models/LICENSE +201 -0
- package/src/agent_apprenticeship/atif_models/__init__.py +38 -0
- package/src/agent_apprenticeship/atif_models/agent.py +35 -0
- package/src/agent_apprenticeship/atif_models/content.py +159 -0
- package/src/agent_apprenticeship/atif_models/final_metrics.py +43 -0
- package/src/agent_apprenticeship/atif_models/metrics.py +47 -0
- package/src/agent_apprenticeship/atif_models/observation.py +19 -0
- package/src/agent_apprenticeship/atif_models/observation_result.py +45 -0
- package/src/agent_apprenticeship/atif_models/step.py +142 -0
- package/src/agent_apprenticeship/atif_models/subagent_trajectory_ref.py +88 -0
- package/src/agent_apprenticeship/atif_models/tool_call.py +34 -0
- package/src/agent_apprenticeship/atif_models/trajectory.py +196 -0
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/batch_runner.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/bundle_exporter.py +8 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/certification.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/cli.py +26 -7
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/codex_runner.py +17 -17
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/config.py +2 -2
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/ecosystem_r2.py +3 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/evaluator.py +8 -27
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/grader.py +6 -5
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/integration_status.py +1 -1
- package/src/agent_apprenticeship/io.py +104 -0
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/learning.py +7 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/loop.py +5 -5
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/loop_review.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/mentor_checkpoints.py +2 -2
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/package_exporter.py +5 -3
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/progress.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/public_run.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/public_sanitizer.py +2 -2
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/release_exporter.py +7 -4
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/rubric_generation.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/schemas.py +17 -4
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/session_events.py +4 -4
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/task_intake.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/tdo.py +5 -1
- package/src/agent_apprenticeship/trace_normalizer.py +103 -0
- package/src/agent_apprenticeship/trace_prompt.py +48 -0
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/training_signals.py +1 -1
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/validation.py +3 -3
- package/src/{agent_apprenticeship_trace → agent_apprenticeship}/verifier.py +6 -5
- package/docs/bioactive_evidence_mapping_schema.md +0 -113
- package/docs/dataset_schema.md +0 -160
- package/docs/local_usage.md +0 -191
- package/docs/scaling_to_1000_tasks.md +0 -3
- package/docs/trace_schema.md +0 -192
- package/docs/v0.2_release_notes.md +0 -61
- package/src/agent_apprenticeship_trace/io.py +0 -20
- package/src/agent_apprenticeship_trace/trace_normalizer.py +0 -1026
- package/src/agent_apprenticeship_trace/trace_prompt.py +0 -78
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/actual_outputs_normalizer.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/apprentice_adapters.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/artifact_capture.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/artifact_previews.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/artifact_resolver.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/command_discovery.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/contract_diagnostics.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/contract_verifier.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/env.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/lesson_extractor.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/llm_output_normalizer.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/openai_structured.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/recipes.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/revision.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/role_runners.py +0 -0
- /package/src/{agent_apprenticeship_trace → agent_apprenticeship}/version.py +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import shutil
|
|
7
|
+
import tempfile
|
|
8
|
+
|
|
9
|
+
from .io import validate_trace_tree, write_json
|
|
10
|
+
|
|
11
|
+
_EXCLUDED = {'agent_env', '__pycache__', 'node_modules', 'build', 'dist', 'roles'}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def export_agent_env(source: Path) -> Path:
|
|
15
|
+
source = source.resolve()
|
|
16
|
+
destination = source / 'agent_env'
|
|
17
|
+
validate_trace_tree(source)
|
|
18
|
+
with tempfile.TemporaryDirectory(prefix='.agentenv-', dir=source) as temp:
|
|
19
|
+
staging = Path(temp)
|
|
20
|
+
artifact = staging / 'artifacts' / 'experience'
|
|
21
|
+
snapshot = artifact / 'snapshot'
|
|
22
|
+
snapshot.mkdir(parents=True)
|
|
23
|
+
files = []
|
|
24
|
+
for directory, dirs, names in os.walk(source, followlinks=False):
|
|
25
|
+
dirs[:] = sorted(d for d in dirs if not d.startswith('.') and d not in _EXCLUDED
|
|
26
|
+
and not (Path(directory) / d).is_symlink())
|
|
27
|
+
for name in sorted(names):
|
|
28
|
+
path = Path(directory) / name
|
|
29
|
+
if name.startswith('.') or path.is_symlink() or not path.is_file():
|
|
30
|
+
continue
|
|
31
|
+
if name.endswith(('.pyc', '.log')) or name in {'stdout.txt', 'stderr.txt', 'rejected_agent_response.txt'}:
|
|
32
|
+
continue
|
|
33
|
+
relative = path.relative_to(source)
|
|
34
|
+
target = snapshot / relative
|
|
35
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
shutil.copyfile(path, target)
|
|
37
|
+
files.append({'path': relative.as_posix(), 'sha256': hashlib.sha256(target.read_bytes()).hexdigest()})
|
|
38
|
+
write_json(artifact / 'snapshot.json', {'files': files})
|
|
39
|
+
shutil.copyfile(Path(__file__).with_name('agent_env_verify.py'), artifact / 'verify.py')
|
|
40
|
+
write_json(staging / 'tasks' / 'experience.json', [
|
|
41
|
+
{'id': 'sandbox', 'type': 'deploy_sandbox', 'sandbox_name': 'experience',
|
|
42
|
+
'sandbox_mode': 'vm', 'sandbox_type': 'local'},
|
|
43
|
+
{'id': 'restore', 'type': 'load_artifact', 'sandbox_name': 'experience',
|
|
44
|
+
'artifact_id': 'experience', 'destination_path': '/app/experience', 'depends_on': ['sandbox']},
|
|
45
|
+
{'id': 'verify', 'type': 'verify_sandbox', 'sandbox_name': 'experience',
|
|
46
|
+
'base_dir': '/app/experience', 'verifier_id': 'experience_integrity', 'depends_on': ['restore'],
|
|
47
|
+
'criteria': [{'type': 'bash_cmd_succeeds', 'criterion': 'snapshot_integrity',
|
|
48
|
+
'bash_cmd': 'python3 verify.py'}]},
|
|
49
|
+
])
|
|
50
|
+
if destination.exists():
|
|
51
|
+
shutil.rmtree(destination)
|
|
52
|
+
staging.rename(destination)
|
|
53
|
+
return destination
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def verify(root):
|
|
7
|
+
root = Path(root)
|
|
8
|
+
snapshot = (root / 'snapshot').resolve()
|
|
9
|
+
manifest = json.loads((root / 'snapshot.json').read_text(encoding='utf-8'))
|
|
10
|
+
files = manifest['files']
|
|
11
|
+
if not isinstance(files, list) or not files:
|
|
12
|
+
return False
|
|
13
|
+
seen = set()
|
|
14
|
+
for entry in files:
|
|
15
|
+
relative = Path(entry['path'])
|
|
16
|
+
path = snapshot / relative
|
|
17
|
+
if relative.is_absolute() or '..' in relative.parts or path.is_symlink():
|
|
18
|
+
return False
|
|
19
|
+
if not path.resolve().is_relative_to(snapshot) or not path.is_file() or relative.as_posix() in seen:
|
|
20
|
+
return False
|
|
21
|
+
seen.add(relative.as_posix())
|
|
22
|
+
if hashlib.sha256(path.read_bytes()).hexdigest() != entry['sha256']:
|
|
23
|
+
return False
|
|
24
|
+
return True
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == '__main__':
|
|
28
|
+
try:
|
|
29
|
+
passed = verify(Path(__file__).resolve().parent)
|
|
30
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
31
|
+
passed = False
|
|
32
|
+
raise SystemExit(0 if passed else 1)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""ATIF v1.8 interchange and lossless projections for workflow evaluation.
|
|
2
|
+
|
|
3
|
+
Only ATIF documents cross persistence boundaries. Project-specific evidence lives
|
|
4
|
+
in ``extra.agent_apprenticeship``; Harbor fields are preserved independently of
|
|
5
|
+
our task/evaluation projection, including parallel calls and multimodal content.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from copy import deepcopy
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
from .atif_models import Trajectory
|
|
14
|
+
|
|
15
|
+
VERSION = "ATIF-v1.8"
|
|
16
|
+
NAMESPACE = "agent_apprenticeship"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def validate_trace(data: Any) -> dict:
|
|
20
|
+
if not isinstance(data, dict) or data.get("schema_version") != VERSION:
|
|
21
|
+
raise ValueError("Trace must declare schema_version ATIF-v1.8")
|
|
22
|
+
return Trajectory.model_validate(data).to_json_dict()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def load_trace(path: Path) -> dict:
|
|
26
|
+
return validate_trace(json.loads(path.read_text(encoding="utf-8")))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def dump_trace(path: Path, trace: Any) -> None:
|
|
30
|
+
if isinstance(trace, Trajectory):
|
|
31
|
+
trace = trace.to_json_dict()
|
|
32
|
+
data = validate_trace(trace)
|
|
33
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
34
|
+
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _text(value: Any) -> str:
|
|
38
|
+
if value is None:
|
|
39
|
+
return ""
|
|
40
|
+
return value if isinstance(value, str) else json.dumps(value, ensure_ascii=False)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def to_workflow(data: dict) -> dict:
|
|
44
|
+
"""Project validated ATIF into the internal evaluator's task/step view."""
|
|
45
|
+
data = validate_trace(data)
|
|
46
|
+
meta = deepcopy((data.get("extra") or {}).get(NAMESPACE) or {})
|
|
47
|
+
# Filter extension fields for the strongly typed task projection.
|
|
48
|
+
from .schemas import WorkflowTrace, WorkflowTraceStep
|
|
49
|
+
meta = {k: v for k, v in meta.items() if k in WorkflowTrace.model_fields}
|
|
50
|
+
identity = data.get("trajectory_id") or data.get("session_id") or "external"
|
|
51
|
+
meta.setdefault("trace_id", identity)
|
|
52
|
+
meta.setdefault("run_id", data.get("session_id"))
|
|
53
|
+
meta.setdefault("task_id", identity)
|
|
54
|
+
meta.setdefault("attempt_id", identity)
|
|
55
|
+
meta.setdefault("attempt_kind", "other")
|
|
56
|
+
meta.setdefault("trace_mode", "live")
|
|
57
|
+
meta.setdefault("task", next((_text(s["message"]) for s in data["steps"] if s["source"] == "user"), ""))
|
|
58
|
+
meta.setdefault("agent_tools", sorted({c["function_name"] for s in data["steps"] for c in s.get("tool_calls") or []}))
|
|
59
|
+
meta.setdefault("termination_reason", "other")
|
|
60
|
+
meta["schema_version"] = VERSION
|
|
61
|
+
meta.setdefault("metadata_json", {})["_atif_original"] = deepcopy(data)
|
|
62
|
+
steps = []
|
|
63
|
+
for s in data["steps"]:
|
|
64
|
+
ext = deepcopy((s.get("extra") or {}).get(NAMESPACE) or {})
|
|
65
|
+
ext = {k: v for k, v in ext.items() if k in WorkflowTraceStep.model_fields}
|
|
66
|
+
ext.update(step=s["step_id"])
|
|
67
|
+
ext.setdefault("turn", s["step_id"])
|
|
68
|
+
ext.setdefault("actor", "user" if s["source"] == "user" else "agent:worker")
|
|
69
|
+
ext.setdefault("action", "user_message" if s["source"] == "user" else "agent_step")
|
|
70
|
+
ext.setdefault("input", _text(s["message"]))
|
|
71
|
+
if s["source"] != "user":
|
|
72
|
+
ext.setdefault("operation", "other")
|
|
73
|
+
calls = s.get("tool_calls") or []
|
|
74
|
+
ext.setdefault("tool", calls[0]["function_name"] if len(calls) == 1 else None)
|
|
75
|
+
results = (s.get("observation") or {}).get("results") or []
|
|
76
|
+
ext.setdefault("output", "\n".join(_text(r.get("content")) for r in results) or _text(s["message"]))
|
|
77
|
+
ext.setdefault("reasoning", s.get("reasoning_content"))
|
|
78
|
+
steps.append(ext)
|
|
79
|
+
meta["steps"] = steps
|
|
80
|
+
return meta
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def from_workflow(trace: dict) -> dict:
|
|
84
|
+
"""Serialize a task projection as ATIF, retaining original Harbor content."""
|
|
85
|
+
trace = deepcopy(trace)
|
|
86
|
+
original = (trace.get("metadata_json") or {}).pop("_atif_original", None)
|
|
87
|
+
out = deepcopy(original) if original else {
|
|
88
|
+
"schema_version": VERSION,
|
|
89
|
+
"agent": {"name": "agent-apprenticeship", "version": "0.3.0"},
|
|
90
|
+
}
|
|
91
|
+
out["session_id"] = trace.get("run_id") or out.get("session_id") or trace.get("attempt_id") or trace["trace_id"]
|
|
92
|
+
out["trajectory_id"] = trace["trace_id"]
|
|
93
|
+
steps = []
|
|
94
|
+
for i, s in enumerate(trace.pop("steps"), 1):
|
|
95
|
+
prior = original["steps"][i-1] if original and i <= len(original["steps"]) else None
|
|
96
|
+
step = deepcopy(prior) if prior else {
|
|
97
|
+
"step_id": i,
|
|
98
|
+
"source": "user" if s.get("actor") == "user" else "system" if s.get("actor") == "system" else "agent",
|
|
99
|
+
"message": _text(s.get("input") if s.get("actor") == "user" else s.get("output") or s.get("input") or s.get("action")),
|
|
100
|
+
}
|
|
101
|
+
step["step_id"] = i
|
|
102
|
+
if not prior:
|
|
103
|
+
if s.get("started_at"):
|
|
104
|
+
step["timestamp"] = s["started_at"]
|
|
105
|
+
if step["source"] == "agent":
|
|
106
|
+
if s.get("reasoning"):
|
|
107
|
+
step["reasoning_content"] = s["reasoning"]
|
|
108
|
+
if s.get("tool"):
|
|
109
|
+
call_id = f"call_{i}"
|
|
110
|
+
step["tool_calls"] = [{"tool_call_id": call_id, "function_name": s["tool"], "arguments": {"input": s.get("input") or ""}}]
|
|
111
|
+
if s.get("output") is not None:
|
|
112
|
+
step["observation"] = {"results": [{"source_call_id": call_id, "content": s["output"]}]}
|
|
113
|
+
step.setdefault("extra", {}).setdefault(NAMESPACE, {}).update({k: v for k, v in s.items() if v is not None and v != [] and v != {}})
|
|
114
|
+
steps.append(step)
|
|
115
|
+
out["steps"] = steps
|
|
116
|
+
trace.pop("schema_version", None)
|
|
117
|
+
out.setdefault("extra", {}).setdefault(NAMESPACE, {}).update({k: v for k, v in trace.items() if v is not None and v != [] and v != {}})
|
|
118
|
+
return validate_trace(out)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def encode_traces(data: Any) -> Any:
|
|
122
|
+
"""Encode trace objects even when nested in training/evaluation envelopes."""
|
|
123
|
+
if isinstance(data, list):
|
|
124
|
+
return [encode_traces(v) for v in data]
|
|
125
|
+
if not isinstance(data, dict):
|
|
126
|
+
return data
|
|
127
|
+
if isinstance(data.get("steps"), list) and "agent" in data:
|
|
128
|
+
return validate_trace(data)
|
|
129
|
+
if isinstance(data.get("steps"), list) and "trace_id" in data:
|
|
130
|
+
return from_workflow(data)
|
|
131
|
+
return {k: encode_traces(v) for k, v in data.items()}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def decode_traces(data: Any) -> Any:
|
|
135
|
+
if isinstance(data, list):
|
|
136
|
+
return [decode_traces(v) for v in data]
|
|
137
|
+
if not isinstance(data, dict):
|
|
138
|
+
return data
|
|
139
|
+
if isinstance(data.get("steps"), list) and "agent" in data:
|
|
140
|
+
return to_workflow(data)
|
|
141
|
+
return {k: decode_traces(v) for k, v in data.items()}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def event_trace(event: dict, name: str) -> dict:
|
|
145
|
+
"""Represent a compiler/session event as a complete one-step trajectory."""
|
|
146
|
+
return validate_trace({
|
|
147
|
+
"schema_version": VERSION,
|
|
148
|
+
"session_id": event.get("session_id") or event.get("run_id"),
|
|
149
|
+
"agent": {"name": name, "version": "0.3.0"},
|
|
150
|
+
"steps": [{"step_id": 1, "source": "system", "message": _text(event.get("message") or event.get("instruction") or event.get("event_type")), "extra": {NAMESPACE: event}}],
|
|
151
|
+
"extra": {NAMESPACE: {"event": event}},
|
|
152
|
+
})
|
|
@@ -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,38 @@
|
|
|
1
|
+
# Harbor ATIF models (Apache-2.0; see LICENSE).
|
|
2
|
+
# Source: harbor-framework/harbor@357c5e74020fc0890d69fb3a7db610896b9ce57d
|
|
3
|
+
# Modified: local imports; trajectory schema version pinned to v1.8.
|
|
4
|
+
"""Pydantic models for Agent Trajectory Interchange Format (ATIF).
|
|
5
|
+
|
|
6
|
+
This module provides Pydantic models for validating and constructing
|
|
7
|
+
trajectory data following the ATIF specification (RFC 0001).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from agent_apprenticeship.atif_models.agent import Agent
|
|
11
|
+
from agent_apprenticeship.atif_models.content import (
|
|
12
|
+
AudioSource,
|
|
13
|
+
ContentPart,
|
|
14
|
+
ImageSource,
|
|
15
|
+
)
|
|
16
|
+
from agent_apprenticeship.atif_models.final_metrics import FinalMetrics
|
|
17
|
+
from agent_apprenticeship.atif_models.metrics import Metrics
|
|
18
|
+
from agent_apprenticeship.atif_models.observation import Observation
|
|
19
|
+
from agent_apprenticeship.atif_models.observation_result import ObservationResult
|
|
20
|
+
from agent_apprenticeship.atif_models.step import Step
|
|
21
|
+
from agent_apprenticeship.atif_models.subagent_trajectory_ref import SubagentTrajectoryRef
|
|
22
|
+
from agent_apprenticeship.atif_models.tool_call import ToolCall
|
|
23
|
+
from agent_apprenticeship.atif_models.trajectory import Trajectory
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"Agent",
|
|
27
|
+
"AudioSource",
|
|
28
|
+
"ContentPart",
|
|
29
|
+
"FinalMetrics",
|
|
30
|
+
"ImageSource",
|
|
31
|
+
"Metrics",
|
|
32
|
+
"Observation",
|
|
33
|
+
"ObservationResult",
|
|
34
|
+
"Step",
|
|
35
|
+
"SubagentTrajectoryRef",
|
|
36
|
+
"ToolCall",
|
|
37
|
+
"Trajectory",
|
|
38
|
+
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Harbor ATIF models (Apache-2.0; see LICENSE).
|
|
2
|
+
# Source: harbor-framework/harbor@357c5e74020fc0890d69fb3a7db610896b9ce57d
|
|
3
|
+
# Modified: local imports; trajectory schema version pinned to v1.8.
|
|
4
|
+
"""Agent configuration model for ATIF trajectories."""
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Agent(BaseModel):
|
|
12
|
+
"""Agent configuration."""
|
|
13
|
+
|
|
14
|
+
name: str = Field(
|
|
15
|
+
default=...,
|
|
16
|
+
description="The name of the agent system",
|
|
17
|
+
)
|
|
18
|
+
version: str = Field(
|
|
19
|
+
default=...,
|
|
20
|
+
description="The version identifier of the agent system",
|
|
21
|
+
)
|
|
22
|
+
model_name: str | None = Field(
|
|
23
|
+
default=None,
|
|
24
|
+
description="Default LLM model used for this trajectory",
|
|
25
|
+
)
|
|
26
|
+
tool_definitions: list[dict[str, Any]] | None = Field(
|
|
27
|
+
default=None,
|
|
28
|
+
description="Array of tool/function definitions available to the agent. Each element follows OpenAI's function calling schema.",
|
|
29
|
+
)
|
|
30
|
+
extra: dict[str, Any] | None = Field(
|
|
31
|
+
default=None,
|
|
32
|
+
description="Custom agent configuration details",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
model_config = {"extra": "forbid"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Harbor ATIF models (Apache-2.0; see LICENSE).
|
|
2
|
+
# Source: harbor-framework/harbor@357c5e74020fc0890d69fb3a7db610896b9ce57d
|
|
3
|
+
# Modified: local imports; trajectory schema version pinned to v1.8.
|
|
4
|
+
"""Content models for multimodal ATIF trajectories.
|
|
5
|
+
|
|
6
|
+
Added in ATIF-v1.6 to support multimodal content (images) in trajectories.
|
|
7
|
+
Extended in ATIF-v1.8 with audio.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from typing import Any, Literal
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, Field, field_validator, model_validator
|
|
13
|
+
|
|
14
|
+
# Canonical audio MIME types, chosen to cover what multimodal and transcription
|
|
15
|
+
# APIs actually accept: Gemini audio understanding (wav, mp3, aiff, aac, ogg,
|
|
16
|
+
# flac), OpenAI transcription (flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm),
|
|
17
|
+
# and `audio/webm`, which is what a browser's MediaRecorder produces and so what
|
|
18
|
+
# human-recorded task data usually arrives as.
|
|
19
|
+
AudioMediaType = Literal[
|
|
20
|
+
"audio/wav",
|
|
21
|
+
"audio/mpeg",
|
|
22
|
+
"audio/mp4",
|
|
23
|
+
"audio/aac",
|
|
24
|
+
"audio/ogg",
|
|
25
|
+
"audio/flac",
|
|
26
|
+
"audio/webm",
|
|
27
|
+
"audio/aiff",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
# Aliases producers emit in place of the registered MIME type, normalized on the
|
|
31
|
+
# way in so consumers only ever see one spelling per format. `audio/mp3` is the
|
|
32
|
+
# important one: it is not a registered type, but the Gemini API documents and
|
|
33
|
+
# emits it, so a producer copying a provider response verbatim would otherwise
|
|
34
|
+
# fail validation.
|
|
35
|
+
_AUDIO_MEDIA_TYPE_ALIASES = {
|
|
36
|
+
"audio/mp3": "audio/mpeg",
|
|
37
|
+
"audio/mpga": "audio/mpeg",
|
|
38
|
+
"audio/x-mpeg": "audio/mpeg",
|
|
39
|
+
"audio/x-wav": "audio/wav",
|
|
40
|
+
"audio/wave": "audio/wav",
|
|
41
|
+
"audio/vnd.wave": "audio/wav",
|
|
42
|
+
"audio/x-m4a": "audio/mp4",
|
|
43
|
+
"audio/m4a": "audio/mp4",
|
|
44
|
+
"audio/x-aac": "audio/aac",
|
|
45
|
+
"audio/x-flac": "audio/flac",
|
|
46
|
+
"audio/x-aiff": "audio/aiff",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ImageSource(BaseModel):
|
|
51
|
+
"""Image source specification for images stored as files or at remote URLs."""
|
|
52
|
+
|
|
53
|
+
media_type: Literal["image/jpeg", "image/png", "image/gif", "image/webp"] = Field(
|
|
54
|
+
default=...,
|
|
55
|
+
description="MIME type of the image",
|
|
56
|
+
)
|
|
57
|
+
path: str = Field(
|
|
58
|
+
default=...,
|
|
59
|
+
description=(
|
|
60
|
+
"Location of the image. Can be a relative or absolute file path, or a URL."
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
model_config = {"extra": "forbid"}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class AudioSource(BaseModel):
|
|
68
|
+
"""Audio source specification for audio stored as files or at remote URLs.
|
|
69
|
+
|
|
70
|
+
Added in ATIF-v1.8. Mirrors ``ImageSource`` so that consumers can treat any
|
|
71
|
+
referenced media the same way, with one addition: ``duration_sec``. Duration
|
|
72
|
+
is worth recording because several providers bill audio per second and
|
|
73
|
+
dataset statistics need it, and unlike an image's dimensions it cannot be
|
|
74
|
+
recovered without decoding the file.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
media_type: AudioMediaType = Field(
|
|
78
|
+
default=...,
|
|
79
|
+
description="MIME type of the audio",
|
|
80
|
+
)
|
|
81
|
+
path: str = Field(
|
|
82
|
+
default=...,
|
|
83
|
+
description=(
|
|
84
|
+
"Location of the audio. Can be a relative or absolute file path, or a URL."
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
duration_sec: float | None = Field(
|
|
88
|
+
default=None,
|
|
89
|
+
ge=0,
|
|
90
|
+
description=(
|
|
91
|
+
"Optional duration of the audio in seconds. Useful for cost "
|
|
92
|
+
"accounting and dataset statistics; omit when unknown."
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
model_config = {"extra": "forbid"}
|
|
97
|
+
|
|
98
|
+
@field_validator("media_type", mode="before")
|
|
99
|
+
@classmethod
|
|
100
|
+
def normalize_media_type(cls, value: Any) -> Any:
|
|
101
|
+
"""Accept common non-registered spellings, storing the canonical one."""
|
|
102
|
+
if isinstance(value, str):
|
|
103
|
+
normalized = value.strip().lower()
|
|
104
|
+
return _AUDIO_MEDIA_TYPE_ALIASES.get(normalized, normalized)
|
|
105
|
+
return value
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class ContentPart(BaseModel):
|
|
109
|
+
"""A single content part within a multimodal message.
|
|
110
|
+
|
|
111
|
+
Used when a message or observation contains mixed content types (text,
|
|
112
|
+
images, or audio). For text-only content, a plain string can still be used
|
|
113
|
+
instead of a ContentPart array.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
type: Literal["text", "image", "audio"] = Field(
|
|
117
|
+
default=...,
|
|
118
|
+
description="The type of content",
|
|
119
|
+
)
|
|
120
|
+
text: str | None = Field(
|
|
121
|
+
default=None,
|
|
122
|
+
description="Text content. Required when type='text'.",
|
|
123
|
+
)
|
|
124
|
+
source: ImageSource | AudioSource | None = Field(
|
|
125
|
+
default=None,
|
|
126
|
+
description=(
|
|
127
|
+
"Media source (file reference). Required when type='image' or "
|
|
128
|
+
"type='audio', and must match that type."
|
|
129
|
+
),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
model_config = {"extra": "forbid"}
|
|
133
|
+
|
|
134
|
+
@model_validator(mode="after")
|
|
135
|
+
def validate_content_type(self) -> "ContentPart":
|
|
136
|
+
"""Validate that the correct fields are present for each content type."""
|
|
137
|
+
if self.type == "text":
|
|
138
|
+
if self.text is None:
|
|
139
|
+
raise ValueError("'text' field is required when type='text'")
|
|
140
|
+
if self.source is not None:
|
|
141
|
+
raise ValueError("'source' field is not allowed when type='text'")
|
|
142
|
+
return self
|
|
143
|
+
|
|
144
|
+
# Media parts: a source is required, text is not allowed, and the source
|
|
145
|
+
# must be of the kind the `type` declares. Without the last check a
|
|
146
|
+
# `source` union would happily accept an ImageSource under
|
|
147
|
+
# type='audio' (and vice versa), silently mislabelling the content.
|
|
148
|
+
if self.source is None:
|
|
149
|
+
raise ValueError(f"'source' field is required when type='{self.type}'")
|
|
150
|
+
if self.text is not None:
|
|
151
|
+
raise ValueError(f"'text' field is not allowed when type='{self.type}'")
|
|
152
|
+
|
|
153
|
+
expected = ImageSource if self.type == "image" else AudioSource
|
|
154
|
+
if not isinstance(self.source, expected):
|
|
155
|
+
raise ValueError(
|
|
156
|
+
f"type='{self.type}' requires a {expected.__name__}, but the "
|
|
157
|
+
f"source's media_type is {self.source.media_type!r}"
|
|
158
|
+
)
|
|
159
|
+
return self
|