agenttune 1.1.0__py3-none-any.whl

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.
Files changed (315) hide show
  1. agenttune/__init__.py +62 -0
  2. agenttune/agentic/README.md +217 -0
  3. agenttune/agentic/__init__.py +66 -0
  4. agenttune/agentic/distill_trainer.py +411 -0
  5. agenttune/agentic/events/judgment_hook.py +57 -0
  6. agenttune/agentic/events.py +268 -0
  7. agenttune/agentic/harness.py +184 -0
  8. agenttune/agentic/harness_openenv.py +127 -0
  9. agenttune/agentic/heal_loop.py +192 -0
  10. agenttune/agentic/inference/__init__.py +6 -0
  11. agenttune/agentic/inference/api_engine.py +53 -0
  12. agenttune/agentic/inference/base_engine.py +20 -0
  13. agenttune/agentic/inference/transformers_engine.py +72 -0
  14. agenttune/agentic/inference/vllm_engine.py +108 -0
  15. agenttune/agentic/langgraph_orchestrator.py +13 -0
  16. agenttune/agentic/memory.py +196 -0
  17. agenttune/agentic/memory_graph.py +213 -0
  18. agenttune/agentic/memory_vector.py +105 -0
  19. agenttune/agentic/project.py +375 -0
  20. agenttune/agentic/rewards/__init__.py +4 -0
  21. agenttune/agentic/rewards/builtin_rewards/__init__.py +56 -0
  22. agenttune/agentic/rewards/builtin_rewards/distilled_judge.py +84 -0
  23. agenttune/agentic/rewards/builtin_rewards/finqa.py +392 -0
  24. agenttune/agentic/rewards/builtin_rewards/hybrid_prm.py +142 -0
  25. agenttune/agentic/rewards/builtin_rewards/sql.py +258 -0
  26. agenttune/agentic/rewards/builtin_rewards/use_case.py +404 -0
  27. agenttune/agentic/rewards/composite.py +107 -0
  28. agenttune/agentic/rewards/judges/rule_guards.py +49 -0
  29. agenttune/agentic/rewards/llm_judge.py +781 -0
  30. agenttune/agentic/rollout_engines/__init__.py +0 -0
  31. agenttune/agentic/rollout_engines/api_engine.py +412 -0
  32. agenttune/agentic/rollout_engines/base.py +30 -0
  33. agenttune/agentic/rollout_engines/demo_engine.py +32 -0
  34. agenttune/agentic/rollout_engines/rollout_factory.py +2618 -0
  35. agenttune/agentic/rollout_engines/tool_call_parse.py +496 -0
  36. agenttune/agentic/rollout_engines/transformers_engine.py +604 -0
  37. agenttune/agentic/rollout_engines/vllm_engine.py +394 -0
  38. agenttune/agentic/service/__init__.py +5 -0
  39. agenttune/agentic/service/app.py +372 -0
  40. agenttune/agentic/service/static/index.html +351 -0
  41. agenttune/agentic/strategy.py +81 -0
  42. agenttune/agentic/strategy_advanced.py +127 -0
  43. agenttune/agentic/strategy_memory.py +91 -0
  44. agenttune/agentic/strategy_tree.py +180 -0
  45. agenttune/agentic/tools/__init__.py +5 -0
  46. agenttune/agentic/tools/base.py +57 -0
  47. agenttune/agentic/tools/builtin/__init__.py +0 -0
  48. agenttune/agentic/tools/builtin/api_tools.py +62 -0
  49. agenttune/agentic/tools/builtin/code_tools.py +80 -0
  50. agenttune/agentic/tools/builtin/file_ingestion.py +478 -0
  51. agenttune/agentic/tools/builtin/file_tools.py +72 -0
  52. agenttune/agentic/tools/builtin/finqa_tool.py +547 -0
  53. agenttune/agentic/tools/builtin/github.py +62 -0
  54. agenttune/agentic/tools/builtin/openenv_tool.py +388 -0
  55. agenttune/agentic/tools/builtin/playright.py +100 -0
  56. agenttune/agentic/tools/builtin/search_tools.py +32 -0
  57. agenttune/agentic/tools/builtin/slack.py +51 -0
  58. agenttune/agentic/tools/builtin/sql.py +916 -0
  59. agenttune/agentic/tools/builtin/web_search_tool.py +48 -0
  60. agenttune/agentic/tools/executor.py +54 -0
  61. agenttune/agentic/tools/registry.py +79 -0
  62. agenttune/agentic/trajectory/__init__.py +0 -0
  63. agenttune/agentic/trajectory/dataset.py +175 -0
  64. agenttune/api.py +128 -0
  65. agenttune/assets/agenttune_banner.png +0 -0
  66. agenttune/assets/lexsi_logo.png +0 -0
  67. agenttune/backends/__init__.py +7 -0
  68. agenttune/backends/_imports.py +69 -0
  69. agenttune/backends/trl/agentic/__init__.py +0 -0
  70. agenttune/backends/trl/agentic/bco/__init__.py +0 -0
  71. agenttune/backends/trl/agentic/bco/agentic_bco.py +1042 -0
  72. agenttune/backends/trl/agentic/dpo/__init__.py +0 -0
  73. agenttune/backends/trl/agentic/dpo/agentic_dpo.py +731 -0
  74. agenttune/backends/trl/agentic/grpo/__init__.py +0 -0
  75. agenttune/backends/trl/agentic/grpo/agentic_grpo.py +774 -0
  76. agenttune/backends/trl/agentic/ppo/__init__.py +0 -0
  77. agenttune/backends/trl/agentic/ppo/agentic_ppo.py +1263 -0
  78. agenttune/backends/trl/agentic/rloo/__init__.py +0 -0
  79. agenttune/backends/trl/agentic/rloo/agentic_rloo.py +523 -0
  80. agenttune/backends/trl/sft/__init__.py +12 -0
  81. agenttune/backends/unsloth/__init__.py +47 -0
  82. agenttune/backends/unsloth/agentic/__init__.py +0 -0
  83. agenttune/backends/unsloth/agentic/bco/__init__.py +0 -0
  84. agenttune/backends/unsloth/agentic/bco/agentic_bco.py +1179 -0
  85. agenttune/backends/unsloth/agentic/dpo/__init__.py +0 -0
  86. agenttune/backends/unsloth/agentic/dpo/agentic_dpo.py +860 -0
  87. agenttune/backends/unsloth/agentic/grpo/__init__.py +0 -0
  88. agenttune/backends/unsloth/agentic/grpo/agentic_grpo.py +811 -0
  89. agenttune/backends/unsloth/agentic/ppo/__init__.py +0 -0
  90. agenttune/backends/unsloth/agentic/ppo/agentic_ppo.py +1323 -0
  91. agenttune/backends/unsloth/agentic/rloo/__init__.py +0 -0
  92. agenttune/backends/unsloth/agentic/rloo/agentic_rloo.py +637 -0
  93. agenttune/backends/unsloth/sft/__init__.py +9 -0
  94. agenttune/backends/unsloth/sft/sft.py +1333 -0
  95. agenttune/cli/__init__.py +57 -0
  96. agenttune/cli/unified.py +119 -0
  97. agenttune/core/backend_factory.py +256 -0
  98. agenttune/core/callbacks/__init__.py +7 -0
  99. agenttune/core/callbacks/base.py +168 -0
  100. agenttune/core/sft/__init__.py +41 -0
  101. agenttune/core/sft/config.py +763 -0
  102. agenttune/core/sft/config_loader.py +186 -0
  103. agenttune/core/sft/evaluator.py +1037 -0
  104. agenttune/core/sft/logging.py +114 -0
  105. agenttune/core/sft/trainer_base.py +604 -0
  106. agenttune/data/README.md +123 -0
  107. agenttune/data/__init__.py +0 -0
  108. agenttune/data/loaders/__init__.py +0 -0
  109. agenttune/data/loaders/base.py +9 -0
  110. agenttune/data/loaders/csv_loader.py +22 -0
  111. agenttune/data/loaders/directory_loader.py +30 -0
  112. agenttune/data/loaders/hf_loader.py +40 -0
  113. agenttune/data/loaders/json_loader.py +14 -0
  114. agenttune/data/loaders/parquet_loader.py +11 -0
  115. agenttune/data/loaders/resolver.py +35 -0
  116. agenttune/data/manager.py +217 -0
  117. agenttune/data/processors.py +700 -0
  118. agenttune/data/schemas.py +132 -0
  119. agenttune/decide/__init__.py +48 -0
  120. agenttune/decide/audit.py +330 -0
  121. agenttune/decide/cli.py +331 -0
  122. agenttune/decide/closed_loop/__init__.py +93 -0
  123. agenttune/decide/closed_loop/behavioral_diversity_monitor.py +60 -0
  124. agenttune/decide/closed_loop/closed_loop_runner.py +306 -0
  125. agenttune/decide/closed_loop/contracts.py +143 -0
  126. agenttune/decide/closed_loop/deployment_gate.py +447 -0
  127. agenttune/decide/closed_loop/failure_classifier.py +86 -0
  128. agenttune/decide/closed_loop/failure_detector.py +130 -0
  129. agenttune/decide/closed_loop/full_loop.py +439 -0
  130. agenttune/decide/closed_loop/pipeline.py +76 -0
  131. agenttune/decide/closed_loop/replay_validator.py +91 -0
  132. agenttune/decide/closed_loop/retrain_config.py +272 -0
  133. agenttune/decide/closed_loop/retrain_runner.py +166 -0
  134. agenttune/decide/closed_loop/retraining_trigger.py +491 -0
  135. agenttune/decide/closed_loop/tool_isolation.py +196 -0
  136. agenttune/decide/closed_loop/training_example_generator.py +224 -0
  137. agenttune/decide/collect_runner.py +150 -0
  138. agenttune/decide/config.example.yaml +217 -0
  139. agenttune/decide/config.py +293 -0
  140. agenttune/decide/destinations/__init__.py +15 -0
  141. agenttune/decide/destinations/base.py +25 -0
  142. agenttune/decide/destinations/file_writer.py +74 -0
  143. agenttune/decide/destinations/postgres_writer.py +103 -0
  144. agenttune/decide/destinations/router.py +47 -0
  145. agenttune/decide/destinations/webhook_sender.py +79 -0
  146. agenttune/decide/eval_runner.py +196 -0
  147. agenttune/decide/graph_runner.py +554 -0
  148. agenttune/decide/model_deployment.py +204 -0
  149. agenttune/decide/registry.py +94 -0
  150. agenttune/decide/rewards.py +187 -0
  151. agenttune/decide/stage_executor.py +45 -0
  152. agenttune/decide/stage_wise_runner.py +70 -0
  153. agenttune/decide/stages/__init__.py +35 -0
  154. agenttune/decide/stages/base.py +419 -0
  155. agenttune/decide/stages/human_review.py +125 -0
  156. agenttune/decide/stages/llm_call.py +220 -0
  157. agenttune/decide/stages/llm_judge.py +162 -0
  158. agenttune/decide/stages/output.py +155 -0
  159. agenttune/decide/stages/parallel.py +118 -0
  160. agenttune/decide/stages/router.py +104 -0
  161. agenttune/decide/stages/rules.py +218 -0
  162. agenttune/decide/stages/tool_call.py +134 -0
  163. agenttune/decide/state.py +127 -0
  164. agenttune/decide/templates/bfsi/account_opening.yaml +29 -0
  165. agenttune/decide/templates/bfsi/card_decline.yaml +29 -0
  166. agenttune/decide/templates/bfsi/claims_triage.yaml +29 -0
  167. agenttune/decide/templates/bfsi/customer_risk_rating.yaml +29 -0
  168. agenttune/decide/templates/bfsi/fraud_detection.yaml +262 -0
  169. agenttune/decide/templates/bfsi/kyc_triage.yaml +343 -0
  170. agenttune/decide/templates/bfsi/loan_approval.yaml +259 -0
  171. agenttune/decide/templates/bfsi/loan_prequal.yaml +29 -0
  172. agenttune/decide/templates/bfsi/regulatory_filing.yaml +29 -0
  173. agenttune/decide/templates/bfsi/sanctions_check.yaml +29 -0
  174. agenttune/decide/templates/bfsi/trade_finance_review.yaml +29 -0
  175. agenttune/decide/templates/bfsi/transaction_monitoring.yaml +29 -0
  176. agenttune/decide/templates/custom/my_classifier.yaml +48 -0
  177. agenttune/decide/templates/custom/simple_classifier.yaml +34 -0
  178. agenttune/decide/templates/example/conditional_routing.yaml +48 -0
  179. agenttune/decide/templates/generic/anomaly_flag.yaml +36 -0
  180. agenttune/decide/templates/generic/document_classification.yaml +157 -0
  181. agenttune/decide/templates/generic/entity_extract.yaml +34 -0
  182. agenttune/decide/templates/generic/iterative_refinement.yaml +209 -0
  183. agenttune/decide/templates/generic/multi_judge_score.yaml +244 -0
  184. agenttune/decide/templates/generic/multi_judge_score_parallel.yaml +240 -0
  185. agenttune/decide/templates/generic/qa_system.yaml +36 -0
  186. agenttune/decide/templates/generic/sentiment_analysis.yaml +35 -0
  187. agenttune/decide/templates/generic/summarize.yaml +36 -0
  188. agenttune/decide/templates/generic/synthetic_data_gen.yaml +35 -0
  189. agenttune/decide/templates/generic/text_classify.yaml +35 -0
  190. agenttune/decide/trainer_config_bridge.py +625 -0
  191. agenttune/decide/trainer_config_example.yaml +223 -0
  192. agenttune/decide/training_bridge.py +323 -0
  193. agenttune/eval/README.md +150 -0
  194. agenttune/eval/README_AGENT_EVAL.md +302 -0
  195. agenttune/eval/__init__.py +78 -0
  196. agenttune/eval/agent_eval.py +1298 -0
  197. agenttune/eval/agentic/trajectory_eval.py +573 -0
  198. agenttune/eval/caching.py +44 -0
  199. agenttune/eval/cli.py +263 -0
  200. agenttune/eval/core.py +431 -0
  201. agenttune/eval/evaluator.py +517 -0
  202. agenttune/eval/lm_eval_integration.py +503 -0
  203. agenttune/eval/metrics/__init__.py +23 -0
  204. agenttune/eval/metrics/base.py +46 -0
  205. agenttune/eval/metrics/code.py +266 -0
  206. agenttune/eval/metrics/dpo.py +335 -0
  207. agenttune/eval/metrics/generic.py +56 -0
  208. agenttune/eval/metrics/math.py +140 -0
  209. agenttune/eval/metrics/rl.py +66 -0
  210. agenttune/eval/metrics/text.py +137 -0
  211. agenttune/eval/registry.py +64 -0
  212. agenttune/eval/rl_evaluator.py +652 -0
  213. agenttune/eval/runner.py +776 -0
  214. agenttune/eval/safe_executor.py +525 -0
  215. agenttune/langgraph/__init__.py +1 -0
  216. agenttune/langgraph/langgraph.py +628 -0
  217. agenttune/py.typed +0 -0
  218. agenttune/rag/README.md +550 -0
  219. agenttune/rag/__init__.py +15 -0
  220. agenttune/rag/data/__init__.py +15 -0
  221. agenttune/rag/data/cuad.py +343 -0
  222. agenttune/rag/data/finder.py +362 -0
  223. agenttune/rag/data/hotpotqa.py +248 -0
  224. agenttune/rag/datagen.py +196 -0
  225. agenttune/rag/memory/__init__.py +42 -0
  226. agenttune/rag/memory/m1_rewrite.py +307 -0
  227. agenttune/rag/memory/m2_decisions.py +221 -0
  228. agenttune/rag/retrieval/__init__.py +19 -0
  229. agenttune/rag/retrieval/base.py +44 -0
  230. agenttune/rag/retrieval/chroma_backend.py +77 -0
  231. agenttune/rag/retrieval/chunker.py +49 -0
  232. agenttune/rag/retrieval/corpus_loader.py +77 -0
  233. agenttune/rag/retrieval/document_loaders.py +333 -0
  234. agenttune/rag/retrieval/hybrid_backend.py +96 -0
  235. agenttune/rag/retrieval/sqlite_fts.py +137 -0
  236. agenttune/rag/rewards/__init__.py +47 -0
  237. agenttune/rag/rewards/finder_rewards.py +408 -0
  238. agenttune/rag/rewards/judge_eval.py +44 -0
  239. agenttune/rag/rewards/phase1_rewards.py +186 -0
  240. agenttune/rag/rewards/qa_metrics.py +116 -0
  241. agenttune/rag/rewards/t3_rewards.py +550 -0
  242. agenttune/rag/scripts/__init__.py +1 -0
  243. agenttune/rag/scripts/analyze_run.py +197 -0
  244. agenttune/rag/scripts/build_cuad_dataset.py +369 -0
  245. agenttune/rag/scripts/build_index.py +72 -0
  246. agenttune/rag/scripts/build_index_finder.py +177 -0
  247. agenttune/rag/scripts/build_index_from_docs.py +115 -0
  248. agenttune/rag/scripts/build_index_mixed.py +294 -0
  249. agenttune/rag/scripts/eval_generated_dataset.py +184 -0
  250. agenttune/rag/scripts/eval_m1_zeroshot.py +378 -0
  251. agenttune/rag/scripts/evaluate.py +189 -0
  252. agenttune/rag/scripts/fetch_cuad_official.py +145 -0
  253. agenttune/rag/scripts/make_e1_graphs.py +274 -0
  254. agenttune/rag/scripts/run_controlled_eval.py +173 -0
  255. agenttune/rag/scripts/run_t1_t4_probe.py +93 -0
  256. agenttune/rag/scripts/train_grpo.py +1603 -0
  257. agenttune/rag/scripts/verify_masking.py +156 -0
  258. agenttune/rag/storage/__init__.py +19 -0
  259. agenttune/rag/storage/trajectory_store.py +448 -0
  260. agenttune/rag/synthesis/.gitignore +6 -0
  261. agenttune/rag/synthesis/README.md +297 -0
  262. agenttune/rag/synthesis/__init__.py +73 -0
  263. agenttune/rag/synthesis/append_dataset.py +291 -0
  264. agenttune/rag/synthesis/build_dataset.py +583 -0
  265. agenttune/rag/synthesis/checkpoint.py +178 -0
  266. agenttune/rag/synthesis/curriculum.py +240 -0
  267. agenttune/rag/synthesis/difficulty.py +114 -0
  268. agenttune/rag/synthesis/embeddings.py +260 -0
  269. agenttune/rag/synthesis/evaluate.py +306 -0
  270. agenttune/rag/synthesis/generate.py +302 -0
  271. agenttune/rag/synthesis/graph.py +483 -0
  272. agenttune/rag/synthesis/io_utils.py +95 -0
  273. agenttune/rag/synthesis/llm_client.py +372 -0
  274. agenttune/rag/synthesis/paths.py +255 -0
  275. agenttune/rag/synthesis/requires_search_filter.py +96 -0
  276. agenttune/rag/synthesis/schema.py +173 -0
  277. agenttune/rag/synthesis/solve_difficulty.py +209 -0
  278. agenttune/rag/synthesis/split.py +292 -0
  279. agenttune/rag/synthesis/verify.py +568 -0
  280. agenttune/rag/tools/__init__.py +12 -0
  281. agenttune/rag/tools/read_document.py +60 -0
  282. agenttune/rag/tools/search_corpus.py +55 -0
  283. agenttune/rag/tools/xml_tool_parser.py +36 -0
  284. agenttune/rag/trainer.py +210 -0
  285. agenttune/rag/trajectory_utils.py +60 -0
  286. agenttune/scenarios/__init__.py +54 -0
  287. agenttune/scenarios/collection.py +139 -0
  288. agenttune/scenarios/generator.py +585 -0
  289. agenttune/scenarios/normalizer.py +273 -0
  290. agenttune/scripts/__init__.py +3 -0
  291. agenttune/utils/__init__.py +138 -0
  292. agenttune/utils/auth.py +243 -0
  293. agenttune/utils/checkpointing.py +424 -0
  294. agenttune/utils/colored_logging.py +268 -0
  295. agenttune/utils/config_extractor.py +336 -0
  296. agenttune/utils/config_utils.py +514 -0
  297. agenttune/utils/device.py +423 -0
  298. agenttune/utils/diagnostics.py +462 -0
  299. agenttune/utils/environment.py +357 -0
  300. agenttune/utils/errors.py +482 -0
  301. agenttune/utils/hf_publish.py +789 -0
  302. agenttune/utils/inference_utils.py +39 -0
  303. agenttune/utils/logging.py +299 -0
  304. agenttune/utils/model_class_resolver.py +42 -0
  305. agenttune/utils/model_loader.py +561 -0
  306. agenttune/utils/optional.py +48 -0
  307. agenttune/utils/provenance.py +64 -0
  308. agenttune/utils/score_logger.py +104 -0
  309. agenttune/utils/validation.py +551 -0
  310. agenttune-1.1.0.dist-info/METADATA +636 -0
  311. agenttune-1.1.0.dist-info/RECORD +315 -0
  312. agenttune-1.1.0.dist-info/WHEEL +5 -0
  313. agenttune-1.1.0.dist-info/entry_points.txt +2 -0
  314. agenttune-1.1.0.dist-info/licenses/LICENSE +83 -0
  315. agenttune-1.1.0.dist-info/top_level.txt +1 -0
agenttune/__init__.py ADDED
@@ -0,0 +1,62 @@
1
+ """AgentTune: a framework for training tool-using LLM agents with RL.
2
+
3
+ The stable, documented entry points live in :mod:`agenttune.api`:
4
+
5
+ from agenttune import run_pipeline, train_agentic
6
+
7
+ The one-call training factories are also importable directly from the top
8
+ level (lazily — importing ``agenttune`` itself stays cheap; the underlying
9
+ TRL/torch training stack only loads once you actually access one of these):
10
+
11
+ from agenttune import create_agentic_trainer, create_rag_trainer, create_distill_trainer
12
+ """
13
+
14
+ import importlib
15
+ from importlib.metadata import PackageNotFoundError, version
16
+
17
+ try:
18
+ __version__ = version("agenttune")
19
+ except PackageNotFoundError: # running from a source tree that was never installed
20
+ __version__ = "0+unknown"
21
+
22
+ from agenttune.api import ( # noqa: E402
23
+ PipelineResult,
24
+ arun_pipeline,
25
+ run_pipeline,
26
+ train_agentic,
27
+ )
28
+
29
+ __all__ = [
30
+ "__version__",
31
+ "PipelineResult",
32
+ "run_pipeline",
33
+ "arun_pipeline",
34
+ "train_agentic",
35
+ "create_agentic_trainer",
36
+ "create_rag_trainer",
37
+ "create_distill_trainer",
38
+ ]
39
+
40
+ # name -> (module to import, attribute on that module)
41
+ _LAZY_ATTRS = {
42
+ "create_agentic_trainer": ("agenttune.core.backend_factory", "create_agentic_trainer"),
43
+ "create_rag_trainer": ("agenttune.rag", "create_rag_trainer"),
44
+ "create_distill_trainer": ("agenttune.agentic", "create_distill_trainer"),
45
+ }
46
+
47
+
48
+ def __getattr__(name: str):
49
+ """PEP 562 lazy attribute access — defers the heavy TRL/torch import chain
50
+ until one of these factories is actually used, not just on `import agenttune`."""
51
+ target = _LAZY_ATTRS.get(name)
52
+ if target is None:
53
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
54
+ module_name, attr_name = target
55
+ module = importlib.import_module(module_name)
56
+ value = getattr(module, attr_name)
57
+ globals()[name] = value # cache on the module so repeated access skips __getattr__
58
+ return value
59
+
60
+
61
+ def __dir__():
62
+ return sorted(set(globals()) | set(_LAZY_ATTRS))
@@ -0,0 +1,217 @@
1
+ # AgentTune — the agentic spine
2
+
3
+ `agenttune.agentic` is the **integration spine**: the connective tissue that moves one
4
+ artifact — a set of tasks on a *strategy* + *harness* — through the entire agentic
5
+ lifecycle and extracts value end to end.
6
+
7
+ ## Thesis
8
+
9
+ > Everywhere else you can **run** an agent design, a memory system, or a harness. Here you
10
+ > **train, eval, distill, and heal** them — through **one trajectory schema**.
11
+
12
+ That one schema is the **two-tier `EventLog`**. Every stage of the lifecycle — a strategy
13
+ episode, a harness rollout, an RL rollout, an eval, a self-heal scan — reads and writes the
14
+ same normalized event stream, so a trajectory produced anywhere is consumable everywhere.
15
+ The `EventLog` is an *additive projection layer*: it wraps the existing `agentic.Trajectory`,
16
+ DECIDE `PipelineState`, and eval dicts without modifying them.
17
+
18
+ **The two tiers** (`events.py`):
19
+
20
+ | tier | source | carries | used for |
21
+ |------|--------|---------|----------|
22
+ | `full` | harness / rollout path | `token_span` + `logprobs` | trainable — SFT rows, GRPO masking, distillation |
23
+ | `light` | observational (`DictToolHarness`, DECIDE `PipelineState`, eval dicts) | events only | UI / eval / heal (read-only) |
24
+
25
+ A `light`-tier log can be evaluated and healed but **cannot be trained on** — the trainable
26
+ projections (`as_dataset_rows`, `masked_tokens`) raise if the tier is not `full`.
27
+
28
+ **Projection naming convention** (stable across 1.0): `as_*` returns a direct *cast* of the
29
+ log's own events (`as_dataset_rows`, `masked_tokens` — same data, different shape); `to_*`
30
+ builds a *new representation for a specific consumer* (`to_eval_dict` for the evaluator,
31
+ `to_audit_records` for the failure detector). The prefix tells you whether you are re-viewing
32
+ the log or translating it for something else.
33
+
34
+ ## The lifecycle
35
+
36
+ ```
37
+ build (AgentStrategy) → run (Harness) → collect_rollout → evaluate / evaluate_agentic
38
+ → train (SFT | GRPO) → distill → heal
39
+ ```
40
+
41
+ `Project` (`project.py`) is the public lifecycle object that threads one artifact through
42
+ these stages, accumulating `EventLog` trajectories and emitting a typed `LifecycleEvent`
43
+ stream (`Project.events()`).
44
+
45
+ ### Quickstart (GPU-free, verified)
46
+
47
+ Uses `DictToolHarness` + `ReActStrategy` + `Project` plus the deterministic
48
+ `DemoRolloutEngine` — no model, no network, no GPU.
49
+
50
+ ```python
51
+ from agenttune.agentic import Project, DictToolHarness, ReActStrategy
52
+ from agenttune.agentic.rollout_engines.demo_engine import DemoRolloutEngine
53
+
54
+ # 1) Harness = the agent's environment (the tools it can call).
55
+ def add(a, b):
56
+ return a + b
57
+
58
+ harness = DictToolHarness({"add": add}, max_steps=4)
59
+
60
+ # 2) Strategy = the agent's policy. ReAct's policy is state -> action dict.
61
+ def policy(state):
62
+ if state.step == 0:
63
+ return {"name": "add", "arguments": {"a": 2, "b": 3}, "thought": "add them"}
64
+ return {"name": "finish", "arguments": {"answer": "5"}}
65
+
66
+ strategy = ReActStrategy(policy, max_steps=4)
67
+
68
+ # 3) Project threads strategy + harness through the lifecycle.
69
+ proj = Project(strategy=strategy, harness=harness)
70
+
71
+ log = proj.infer("what is 2+3?") # one episode -> light-tier EventLog
72
+ report = proj.evaluate([{"task": "what is 2+3?", "expected": "5"}]) # answer_match
73
+ ametrics = proj.evaluate_agentic(["what is 2+3?"]) # real programmatic trajectory metrics
74
+
75
+ # GPU-free FULL-tier rollouts via the deterministic DemoRolloutEngine.
76
+ proj2 = Project()
77
+ logs = proj2.collect_rollout(DemoRolloutEngine(), ["what is 2+3?"], tools=[], max_steps=2)
78
+ rows = proj2.sft_dataset() # the SFT/distill rows the spine would train on
79
+ fails = proj2.heal() # closed-loop failure detection over collected trajectories
80
+ ```
81
+
82
+ Running this prints (abridged):
83
+
84
+ ```
85
+ infer -> events: 8 tier: light
86
+ evaluate -> mean_score: 1.0
87
+ evaluate_agentic -> metrics: {'tac': 0.0, 'ter': 0.5, 'arr': 0.0, 'scsr': 1.0, 'rad': 0.0, 'lcf': 0.0}
88
+ collect_rollout -> tiers: ['full']
89
+ sft_dataset -> rows: 1
90
+ heal -> failures: 0
91
+ ```
92
+
93
+ ### What each stage reuses (wrap, don't reimplement)
94
+
95
+ - `infer` / `collect` — run `AgentStrategy` on `Harness` via `run_episode`, projecting to `EventLog`.
96
+ - `collect_rollout` — drives a real `RolloutEngine` through the existing `create_rollout_fn`
97
+ (the *same* producer GRPO uses), yielding native `Trajectory` objects (the RL substrate,
98
+ in `Project.native_trajectories`) plus `full`-tier `EventLog`s.
99
+ - `evaluate` — scores with `answer_match` (or any `scorer(log, expected) -> float`).
100
+ - `evaluate_agentic` — scores each trajectory with the existing `TrajectoryEvaluator`'s
101
+ programmatic metrics (`tac, ter, arr, scsr, rad, lcf`) via `EventLog.to_eval_dict()` — no
102
+ model, no network. Reference-dependent and judge/semantic metrics activate when their
103
+ inputs (plans, golden trajectories, litellm) are supplied.
104
+ - `train(fmt='sft')` — builds SFT rows from the project's own `full`-tier trajectories
105
+ (`as_dataset_rows`, whose `messages` schema matches the real SFT trainer) and delegates to
106
+ a `trainer_factory` returning an object with `.train() -> dict`.
107
+ - `train(fmt='grpo')` — on-policy RL: wires `create_rollout_fn(rollout_engine=…)` as the real
108
+ trainer's `rollout_func`; rollout runs inside the trainer with a real model. Requires a `rollout_engine`.
109
+ - `distill` — agentic distillation (behavior cloning, not weight-KD): SFT a small `student`
110
+ on a teacher's `full`-tier trajectories; rides the same rails as `train(fmt='sft')`.
111
+ - `heal` — projects trajectories to audit records (`to_audit_records`) and scans them with the
112
+ real closed-loop `FailureDetector` (`loop_collapse` / `tool_crash`).
113
+
114
+ `Project.train`/`distill` take a `trainer_factory` (not a live trainer), so the `Project`
115
+ object itself stays GPU- and dependency-free while delegating to the real runner.
116
+
117
+ ## The three pillars
118
+
119
+ New capability layers, each additive, each speaking `EventLog`.
120
+
121
+ ### 1. Agent design — `strategy.py`, `strategy_advanced.py`, `strategy_memory.py`, `strategy_tree.py`
122
+
123
+ The policy layer. Every design reduces to `init → propose → observe → is_done`, with model
124
+ access behind an injected `policy` callable (testable without a model).
125
+
126
+ - `AgentStrategy` (base), `AgentState`
127
+ - `ReActStrategy` — the reference (ReAct, arXiv:2210.03629); driven by `run_episode`
128
+ - `PlanExecuteStrategy` — Plan-and-Solve (arXiv:2305.04091)
129
+ - `ReflexionStrategy` + `run_reflexion` — Reflexion (arXiv:2303.11366): retry loop seeded with verbal self-reflections
130
+ - `MemoryReActStrategy` — ReAct that recalls from an injected `BaseMemory` on `init` and writes observations back on `observe` (wires the memory pillar into the loop)
131
+ - `TreeOfThoughtsStrategy` — Tree-of-Thoughts / LATS (arXiv:2305.10601, arXiv:2310.04406): injected `propose_candidates` + `score`; greedy beam per step, plus `search()` for best-first frontier expansion with real backtracking
132
+
133
+ ### 2. Memory — `memory.py`, `memory_vector.py`, `memory_graph.py`
134
+
135
+ Pluggable memory subsystem. CRUD plus injectable, **trainable** `consolidate`/`forget`
136
+ policies and `snapshot`/`restore` for rollout reset/replay.
137
+
138
+ - `MemoryKind` (working / episodic / semantic / procedural / entity — CoALA, arXiv:2309.02427), `Scope`, `MemoryItem`
139
+ - `BaseMemory` (base)
140
+ - `InContextMemory` — list-backed ReAct scratchpad (recent-k recall)
141
+ - `VectorMemory` — semantic recall: `read(query, k)` ranks by cosine similarity to the query embedding (embedder injected — stdlib-only, no model required to test)
142
+ - `GraphMemory` — relational recall (Graphiti / A-MEM, arXiv:2501.13956, arXiv:2502.12110): typed directed edges, `link` / `neighbors` BFS traversal, and logical-clock temporal decay (`read(recency_weighted=True)`, `forget_older_than`)
143
+ - `TrajectoryStore` — episodic replay store of `full`-tier `EventLog`s; emits distillation datasets (`as_dataset`)
144
+
145
+ Trainable memory policies follow the Memory-R1 (arXiv:2508.19828) pattern. The three drivers
146
+ span the retrieval paradigms: recent-k (`InContextMemory`), semantic (`VectorMemory`), and
147
+ relational (`GraphMemory`).
148
+
149
+ ### 3. Harness — `harness.py`, `harness_openenv.py`
150
+
151
+ The agent's environment / RL env. Gym-like `reset` / `step` / `action_space`, capability
152
+ flags with a DRIFT conformance bench, and `replay()`.
153
+
154
+ - `Harness` (base), `Observation`, `HarnessCapabilities`
155
+ - `DictToolHarness` — pure-Python tool dict; produces `light`-tier logs (observational)
156
+ - `OpenEnvHarness` — wraps the OpenEnv sandbox adapter
157
+ - `run_conformance` → `ConformanceReport` — checks a harness's declared capabilities against behavior
158
+ - `replay(harness, log)` — re-execute a log's `TOOL_CALL`s through a harness
159
+
160
+ ### Self-healing — `heal_loop.py`
161
+
162
+ The closed-loop recovery layer built on top of `heal` detection: detect → classify →
163
+ generate → retrain, with the litellm-bound classify/generate stages injected so the loop is
164
+ testable model-free.
165
+
166
+ - `SelfHealLoop(classifier, generator, *, trainer_factory=None)` — `.run(failures)` / `.run_on(project)` drive the full loop and return a stage-by-stage summary
167
+ - `build_dataset(examples)` — maps `TrainingExample`s to `{prompt, chosen, rejected}` preference rows using the real closed-loop `derive_preference_from_completions`
168
+ - `as_sync_classifier` / `as_sync_generator` — adapt the async litellm-bound closed-loop stages into the loop's sync injection points
169
+
170
+ ## Honest scope: GPU-free vs GPU
171
+
172
+ **GPU-free (runs anywhere, for real):** everything in the quickstart — `infer`, `collect`,
173
+ `evaluate`, `evaluate_agentic` (real programmatic metrics), `collect_rollout` +
174
+ `sft_dataset` + `heal` via the deterministic `DemoRolloutEngine` (`rollout_engines/demo_engine.py`).
175
+ The demo engine emits a canned reasoning + answer with fixed logprobs so a genuine `full`-tier
176
+ `Trajectory` flows through the real rollout machinery — no model.
177
+
178
+ **Needs GPU / litellm:**
179
+
180
+ - `train(fmt='grpo')` — on-policy RL with a real model behind the rollout engine.
181
+ - SFT/distill *execution* — the dataset assembly is GPU-free; the actual `.train()` runs on GPU via the wired trainer.
182
+ - Full self-heal (`classify → regenerate → retrain`) — `heal` **detection** is GPU-free; the regenerate/retrain steps need litellm and ride on top of that detection.
183
+
184
+ ### Running the service
185
+
186
+ A FastAPI backend exposes the GPU-free live spine path (create project → collect_rollout →
187
+ evaluate → distill/SFT preview → heal, plus a live lifecycle event stream over REST +
188
+ WebSocket). GRPO training and full self-heal are reported as `wired-runs-on-gpu` rather than
189
+ executed in-process — the same honesty scope the library holds.
190
+
191
+ ```bash
192
+ uvicorn agenttune.agentic.service.app:create_app --factory
193
+ ```
194
+
195
+ ## Public surface
196
+
197
+ Exported from `agenttune.agentic` (`__init__.py`):
198
+
199
+ - **Events:** `Event`, `EventKind`, `EventLog`
200
+ - **Harness:** `Harness`, `DictToolHarness`, `OpenEnvHarness`, `Observation`, `HarnessCapabilities`, `ConformanceReport`, `run_conformance`, `replay`
201
+ - **Strategy:** `AgentStrategy`, `AgentState`, `ReActStrategy`, `PlanExecuteStrategy`, `ReflexionStrategy`, `MemoryReActStrategy`, `TreeOfThoughtsStrategy`, `run_episode`, `run_reflexion`
202
+ - **Memory:** `BaseMemory`, `InContextMemory`, `VectorMemory`, `GraphMemory`, `TrajectoryStore`, `MemoryKind`, `Scope`, `MemoryItem`
203
+ - **Project:** `Project`, `LifecycleEvent`, `answer_match`, `agentic_metrics`
204
+ - **Self-heal:** `SelfHealLoop`, `build_dataset`, `as_sync_classifier`, `as_sync_generator`
205
+ - **Substrate:** `Trajectory`, `Step`, `TrajectoryDataset`, `ToolRegistry`, `BaseTool`, `ToolResult`, `create_rollout_engine`, `create_rollout_fn`
206
+
207
+ ## References
208
+
209
+ - ReAct — arXiv:2210.03629
210
+ - Reflexion — arXiv:2303.11366
211
+ - Plan-and-Solve — arXiv:2305.04091
212
+ - Tree-of-Thoughts — arXiv:2305.10601
213
+ - LATS — arXiv:2310.04406
214
+ - CoALA (memory taxonomy) — arXiv:2309.02427
215
+ - Graphiti / Zep (temporal graph memory) — arXiv:2501.13956
216
+ - A-MEM (agentic memory) — arXiv:2502.12110
217
+ - Memory-R1 (trainable memory policies) — arXiv:2508.19828
@@ -0,0 +1,66 @@
1
+ from .rewards import REWARD_REGISTRY, combine_rewards
2
+ from .rollout_engines.rollout_factory import create_rollout_engine, create_rollout_fn
3
+ from .tools.base import BaseTool, ToolResult
4
+ from .tools.registry import ToolRegistry
5
+ from .trajectory.dataset import Step, Trajectory, TrajectoryDataset
6
+
7
+ __all__ = [
8
+ "BaseTool",
9
+ "ToolResult",
10
+ "ToolRegistry",
11
+ "create_rollout_engine",
12
+ "create_rollout_fn",
13
+ "Trajectory",
14
+ "Step",
15
+ "TrajectoryDataset",
16
+ ]
17
+ from agenttune.agentic.distill_trainer import DistillTrainer, create_distill_trainer # noqa: F401
18
+ from agenttune.agentic.events import Event, EventKind, EventLog # noqa: F401
19
+ from agenttune.agentic.harness import ( # noqa: F401
20
+ ConformanceReport,
21
+ DictToolHarness,
22
+ Harness,
23
+ HarnessCapabilities,
24
+ Observation,
25
+ replay,
26
+ run_conformance,
27
+ )
28
+ from agenttune.agentic.harness_openenv import OpenEnvHarness # noqa: F401
29
+ from agenttune.agentic.heal_loop import ( # noqa: F401
30
+ SelfHealLoop,
31
+ as_sync_classifier,
32
+ as_sync_generator,
33
+ build_dataset,
34
+ )
35
+ from agenttune.agentic.memory import ( # noqa: F401
36
+ BaseMemory,
37
+ InContextMemory,
38
+ MemoryItem,
39
+ MemoryKind,
40
+ Scope,
41
+ TrajectoryStore,
42
+ )
43
+ from agenttune.agentic.memory_graph import GraphMemory # noqa: F401
44
+ from agenttune.agentic.memory_vector import VectorMemory # noqa: F401
45
+ from agenttune.agentic.project import ( # noqa: F401
46
+ AgenticEvalReport,
47
+ AgenticMetrics,
48
+ EvalReport,
49
+ LifecycleEvent,
50
+ Project,
51
+ agentic_metrics,
52
+ answer_match,
53
+ )
54
+ from agenttune.agentic.strategy import ( # noqa: F401
55
+ AgentState,
56
+ AgentStrategy,
57
+ ReActStrategy,
58
+ run_episode,
59
+ )
60
+ from agenttune.agentic.strategy_advanced import ( # noqa: F401
61
+ PlanExecuteStrategy,
62
+ ReflexionStrategy,
63
+ run_reflexion,
64
+ )
65
+ from agenttune.agentic.strategy_memory import MemoryReActStrategy # noqa: F401
66
+ from agenttune.agentic.strategy_tree import TreeOfThoughtsStrategy # noqa: F401