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.
- agenttune/__init__.py +62 -0
- agenttune/agentic/README.md +217 -0
- agenttune/agentic/__init__.py +66 -0
- agenttune/agentic/distill_trainer.py +411 -0
- agenttune/agentic/events/judgment_hook.py +57 -0
- agenttune/agentic/events.py +268 -0
- agenttune/agentic/harness.py +184 -0
- agenttune/agentic/harness_openenv.py +127 -0
- agenttune/agentic/heal_loop.py +192 -0
- agenttune/agentic/inference/__init__.py +6 -0
- agenttune/agentic/inference/api_engine.py +53 -0
- agenttune/agentic/inference/base_engine.py +20 -0
- agenttune/agentic/inference/transformers_engine.py +72 -0
- agenttune/agentic/inference/vllm_engine.py +108 -0
- agenttune/agentic/langgraph_orchestrator.py +13 -0
- agenttune/agentic/memory.py +196 -0
- agenttune/agentic/memory_graph.py +213 -0
- agenttune/agentic/memory_vector.py +105 -0
- agenttune/agentic/project.py +375 -0
- agenttune/agentic/rewards/__init__.py +4 -0
- agenttune/agentic/rewards/builtin_rewards/__init__.py +56 -0
- agenttune/agentic/rewards/builtin_rewards/distilled_judge.py +84 -0
- agenttune/agentic/rewards/builtin_rewards/finqa.py +392 -0
- agenttune/agentic/rewards/builtin_rewards/hybrid_prm.py +142 -0
- agenttune/agentic/rewards/builtin_rewards/sql.py +258 -0
- agenttune/agentic/rewards/builtin_rewards/use_case.py +404 -0
- agenttune/agentic/rewards/composite.py +107 -0
- agenttune/agentic/rewards/judges/rule_guards.py +49 -0
- agenttune/agentic/rewards/llm_judge.py +781 -0
- agenttune/agentic/rollout_engines/__init__.py +0 -0
- agenttune/agentic/rollout_engines/api_engine.py +412 -0
- agenttune/agentic/rollout_engines/base.py +30 -0
- agenttune/agentic/rollout_engines/demo_engine.py +32 -0
- agenttune/agentic/rollout_engines/rollout_factory.py +2618 -0
- agenttune/agentic/rollout_engines/tool_call_parse.py +496 -0
- agenttune/agentic/rollout_engines/transformers_engine.py +604 -0
- agenttune/agentic/rollout_engines/vllm_engine.py +394 -0
- agenttune/agentic/service/__init__.py +5 -0
- agenttune/agentic/service/app.py +372 -0
- agenttune/agentic/service/static/index.html +351 -0
- agenttune/agentic/strategy.py +81 -0
- agenttune/agentic/strategy_advanced.py +127 -0
- agenttune/agentic/strategy_memory.py +91 -0
- agenttune/agentic/strategy_tree.py +180 -0
- agenttune/agentic/tools/__init__.py +5 -0
- agenttune/agentic/tools/base.py +57 -0
- agenttune/agentic/tools/builtin/__init__.py +0 -0
- agenttune/agentic/tools/builtin/api_tools.py +62 -0
- agenttune/agentic/tools/builtin/code_tools.py +80 -0
- agenttune/agentic/tools/builtin/file_ingestion.py +478 -0
- agenttune/agentic/tools/builtin/file_tools.py +72 -0
- agenttune/agentic/tools/builtin/finqa_tool.py +547 -0
- agenttune/agentic/tools/builtin/github.py +62 -0
- agenttune/agentic/tools/builtin/openenv_tool.py +388 -0
- agenttune/agentic/tools/builtin/playright.py +100 -0
- agenttune/agentic/tools/builtin/search_tools.py +32 -0
- agenttune/agentic/tools/builtin/slack.py +51 -0
- agenttune/agentic/tools/builtin/sql.py +916 -0
- agenttune/agentic/tools/builtin/web_search_tool.py +48 -0
- agenttune/agentic/tools/executor.py +54 -0
- agenttune/agentic/tools/registry.py +79 -0
- agenttune/agentic/trajectory/__init__.py +0 -0
- agenttune/agentic/trajectory/dataset.py +175 -0
- agenttune/api.py +128 -0
- agenttune/assets/agenttune_banner.png +0 -0
- agenttune/assets/lexsi_logo.png +0 -0
- agenttune/backends/__init__.py +7 -0
- agenttune/backends/_imports.py +69 -0
- agenttune/backends/trl/agentic/__init__.py +0 -0
- agenttune/backends/trl/agentic/bco/__init__.py +0 -0
- agenttune/backends/trl/agentic/bco/agentic_bco.py +1042 -0
- agenttune/backends/trl/agentic/dpo/__init__.py +0 -0
- agenttune/backends/trl/agentic/dpo/agentic_dpo.py +731 -0
- agenttune/backends/trl/agentic/grpo/__init__.py +0 -0
- agenttune/backends/trl/agentic/grpo/agentic_grpo.py +774 -0
- agenttune/backends/trl/agentic/ppo/__init__.py +0 -0
- agenttune/backends/trl/agentic/ppo/agentic_ppo.py +1263 -0
- agenttune/backends/trl/agentic/rloo/__init__.py +0 -0
- agenttune/backends/trl/agentic/rloo/agentic_rloo.py +523 -0
- agenttune/backends/trl/sft/__init__.py +12 -0
- agenttune/backends/unsloth/__init__.py +47 -0
- agenttune/backends/unsloth/agentic/__init__.py +0 -0
- agenttune/backends/unsloth/agentic/bco/__init__.py +0 -0
- agenttune/backends/unsloth/agentic/bco/agentic_bco.py +1179 -0
- agenttune/backends/unsloth/agentic/dpo/__init__.py +0 -0
- agenttune/backends/unsloth/agentic/dpo/agentic_dpo.py +860 -0
- agenttune/backends/unsloth/agentic/grpo/__init__.py +0 -0
- agenttune/backends/unsloth/agentic/grpo/agentic_grpo.py +811 -0
- agenttune/backends/unsloth/agentic/ppo/__init__.py +0 -0
- agenttune/backends/unsloth/agentic/ppo/agentic_ppo.py +1323 -0
- agenttune/backends/unsloth/agentic/rloo/__init__.py +0 -0
- agenttune/backends/unsloth/agentic/rloo/agentic_rloo.py +637 -0
- agenttune/backends/unsloth/sft/__init__.py +9 -0
- agenttune/backends/unsloth/sft/sft.py +1333 -0
- agenttune/cli/__init__.py +57 -0
- agenttune/cli/unified.py +119 -0
- agenttune/core/backend_factory.py +256 -0
- agenttune/core/callbacks/__init__.py +7 -0
- agenttune/core/callbacks/base.py +168 -0
- agenttune/core/sft/__init__.py +41 -0
- agenttune/core/sft/config.py +763 -0
- agenttune/core/sft/config_loader.py +186 -0
- agenttune/core/sft/evaluator.py +1037 -0
- agenttune/core/sft/logging.py +114 -0
- agenttune/core/sft/trainer_base.py +604 -0
- agenttune/data/README.md +123 -0
- agenttune/data/__init__.py +0 -0
- agenttune/data/loaders/__init__.py +0 -0
- agenttune/data/loaders/base.py +9 -0
- agenttune/data/loaders/csv_loader.py +22 -0
- agenttune/data/loaders/directory_loader.py +30 -0
- agenttune/data/loaders/hf_loader.py +40 -0
- agenttune/data/loaders/json_loader.py +14 -0
- agenttune/data/loaders/parquet_loader.py +11 -0
- agenttune/data/loaders/resolver.py +35 -0
- agenttune/data/manager.py +217 -0
- agenttune/data/processors.py +700 -0
- agenttune/data/schemas.py +132 -0
- agenttune/decide/__init__.py +48 -0
- agenttune/decide/audit.py +330 -0
- agenttune/decide/cli.py +331 -0
- agenttune/decide/closed_loop/__init__.py +93 -0
- agenttune/decide/closed_loop/behavioral_diversity_monitor.py +60 -0
- agenttune/decide/closed_loop/closed_loop_runner.py +306 -0
- agenttune/decide/closed_loop/contracts.py +143 -0
- agenttune/decide/closed_loop/deployment_gate.py +447 -0
- agenttune/decide/closed_loop/failure_classifier.py +86 -0
- agenttune/decide/closed_loop/failure_detector.py +130 -0
- agenttune/decide/closed_loop/full_loop.py +439 -0
- agenttune/decide/closed_loop/pipeline.py +76 -0
- agenttune/decide/closed_loop/replay_validator.py +91 -0
- agenttune/decide/closed_loop/retrain_config.py +272 -0
- agenttune/decide/closed_loop/retrain_runner.py +166 -0
- agenttune/decide/closed_loop/retraining_trigger.py +491 -0
- agenttune/decide/closed_loop/tool_isolation.py +196 -0
- agenttune/decide/closed_loop/training_example_generator.py +224 -0
- agenttune/decide/collect_runner.py +150 -0
- agenttune/decide/config.example.yaml +217 -0
- agenttune/decide/config.py +293 -0
- agenttune/decide/destinations/__init__.py +15 -0
- agenttune/decide/destinations/base.py +25 -0
- agenttune/decide/destinations/file_writer.py +74 -0
- agenttune/decide/destinations/postgres_writer.py +103 -0
- agenttune/decide/destinations/router.py +47 -0
- agenttune/decide/destinations/webhook_sender.py +79 -0
- agenttune/decide/eval_runner.py +196 -0
- agenttune/decide/graph_runner.py +554 -0
- agenttune/decide/model_deployment.py +204 -0
- agenttune/decide/registry.py +94 -0
- agenttune/decide/rewards.py +187 -0
- agenttune/decide/stage_executor.py +45 -0
- agenttune/decide/stage_wise_runner.py +70 -0
- agenttune/decide/stages/__init__.py +35 -0
- agenttune/decide/stages/base.py +419 -0
- agenttune/decide/stages/human_review.py +125 -0
- agenttune/decide/stages/llm_call.py +220 -0
- agenttune/decide/stages/llm_judge.py +162 -0
- agenttune/decide/stages/output.py +155 -0
- agenttune/decide/stages/parallel.py +118 -0
- agenttune/decide/stages/router.py +104 -0
- agenttune/decide/stages/rules.py +218 -0
- agenttune/decide/stages/tool_call.py +134 -0
- agenttune/decide/state.py +127 -0
- agenttune/decide/templates/bfsi/account_opening.yaml +29 -0
- agenttune/decide/templates/bfsi/card_decline.yaml +29 -0
- agenttune/decide/templates/bfsi/claims_triage.yaml +29 -0
- agenttune/decide/templates/bfsi/customer_risk_rating.yaml +29 -0
- agenttune/decide/templates/bfsi/fraud_detection.yaml +262 -0
- agenttune/decide/templates/bfsi/kyc_triage.yaml +343 -0
- agenttune/decide/templates/bfsi/loan_approval.yaml +259 -0
- agenttune/decide/templates/bfsi/loan_prequal.yaml +29 -0
- agenttune/decide/templates/bfsi/regulatory_filing.yaml +29 -0
- agenttune/decide/templates/bfsi/sanctions_check.yaml +29 -0
- agenttune/decide/templates/bfsi/trade_finance_review.yaml +29 -0
- agenttune/decide/templates/bfsi/transaction_monitoring.yaml +29 -0
- agenttune/decide/templates/custom/my_classifier.yaml +48 -0
- agenttune/decide/templates/custom/simple_classifier.yaml +34 -0
- agenttune/decide/templates/example/conditional_routing.yaml +48 -0
- agenttune/decide/templates/generic/anomaly_flag.yaml +36 -0
- agenttune/decide/templates/generic/document_classification.yaml +157 -0
- agenttune/decide/templates/generic/entity_extract.yaml +34 -0
- agenttune/decide/templates/generic/iterative_refinement.yaml +209 -0
- agenttune/decide/templates/generic/multi_judge_score.yaml +244 -0
- agenttune/decide/templates/generic/multi_judge_score_parallel.yaml +240 -0
- agenttune/decide/templates/generic/qa_system.yaml +36 -0
- agenttune/decide/templates/generic/sentiment_analysis.yaml +35 -0
- agenttune/decide/templates/generic/summarize.yaml +36 -0
- agenttune/decide/templates/generic/synthetic_data_gen.yaml +35 -0
- agenttune/decide/templates/generic/text_classify.yaml +35 -0
- agenttune/decide/trainer_config_bridge.py +625 -0
- agenttune/decide/trainer_config_example.yaml +223 -0
- agenttune/decide/training_bridge.py +323 -0
- agenttune/eval/README.md +150 -0
- agenttune/eval/README_AGENT_EVAL.md +302 -0
- agenttune/eval/__init__.py +78 -0
- agenttune/eval/agent_eval.py +1298 -0
- agenttune/eval/agentic/trajectory_eval.py +573 -0
- agenttune/eval/caching.py +44 -0
- agenttune/eval/cli.py +263 -0
- agenttune/eval/core.py +431 -0
- agenttune/eval/evaluator.py +517 -0
- agenttune/eval/lm_eval_integration.py +503 -0
- agenttune/eval/metrics/__init__.py +23 -0
- agenttune/eval/metrics/base.py +46 -0
- agenttune/eval/metrics/code.py +266 -0
- agenttune/eval/metrics/dpo.py +335 -0
- agenttune/eval/metrics/generic.py +56 -0
- agenttune/eval/metrics/math.py +140 -0
- agenttune/eval/metrics/rl.py +66 -0
- agenttune/eval/metrics/text.py +137 -0
- agenttune/eval/registry.py +64 -0
- agenttune/eval/rl_evaluator.py +652 -0
- agenttune/eval/runner.py +776 -0
- agenttune/eval/safe_executor.py +525 -0
- agenttune/langgraph/__init__.py +1 -0
- agenttune/langgraph/langgraph.py +628 -0
- agenttune/py.typed +0 -0
- agenttune/rag/README.md +550 -0
- agenttune/rag/__init__.py +15 -0
- agenttune/rag/data/__init__.py +15 -0
- agenttune/rag/data/cuad.py +343 -0
- agenttune/rag/data/finder.py +362 -0
- agenttune/rag/data/hotpotqa.py +248 -0
- agenttune/rag/datagen.py +196 -0
- agenttune/rag/memory/__init__.py +42 -0
- agenttune/rag/memory/m1_rewrite.py +307 -0
- agenttune/rag/memory/m2_decisions.py +221 -0
- agenttune/rag/retrieval/__init__.py +19 -0
- agenttune/rag/retrieval/base.py +44 -0
- agenttune/rag/retrieval/chroma_backend.py +77 -0
- agenttune/rag/retrieval/chunker.py +49 -0
- agenttune/rag/retrieval/corpus_loader.py +77 -0
- agenttune/rag/retrieval/document_loaders.py +333 -0
- agenttune/rag/retrieval/hybrid_backend.py +96 -0
- agenttune/rag/retrieval/sqlite_fts.py +137 -0
- agenttune/rag/rewards/__init__.py +47 -0
- agenttune/rag/rewards/finder_rewards.py +408 -0
- agenttune/rag/rewards/judge_eval.py +44 -0
- agenttune/rag/rewards/phase1_rewards.py +186 -0
- agenttune/rag/rewards/qa_metrics.py +116 -0
- agenttune/rag/rewards/t3_rewards.py +550 -0
- agenttune/rag/scripts/__init__.py +1 -0
- agenttune/rag/scripts/analyze_run.py +197 -0
- agenttune/rag/scripts/build_cuad_dataset.py +369 -0
- agenttune/rag/scripts/build_index.py +72 -0
- agenttune/rag/scripts/build_index_finder.py +177 -0
- agenttune/rag/scripts/build_index_from_docs.py +115 -0
- agenttune/rag/scripts/build_index_mixed.py +294 -0
- agenttune/rag/scripts/eval_generated_dataset.py +184 -0
- agenttune/rag/scripts/eval_m1_zeroshot.py +378 -0
- agenttune/rag/scripts/evaluate.py +189 -0
- agenttune/rag/scripts/fetch_cuad_official.py +145 -0
- agenttune/rag/scripts/make_e1_graphs.py +274 -0
- agenttune/rag/scripts/run_controlled_eval.py +173 -0
- agenttune/rag/scripts/run_t1_t4_probe.py +93 -0
- agenttune/rag/scripts/train_grpo.py +1603 -0
- agenttune/rag/scripts/verify_masking.py +156 -0
- agenttune/rag/storage/__init__.py +19 -0
- agenttune/rag/storage/trajectory_store.py +448 -0
- agenttune/rag/synthesis/.gitignore +6 -0
- agenttune/rag/synthesis/README.md +297 -0
- agenttune/rag/synthesis/__init__.py +73 -0
- agenttune/rag/synthesis/append_dataset.py +291 -0
- agenttune/rag/synthesis/build_dataset.py +583 -0
- agenttune/rag/synthesis/checkpoint.py +178 -0
- agenttune/rag/synthesis/curriculum.py +240 -0
- agenttune/rag/synthesis/difficulty.py +114 -0
- agenttune/rag/synthesis/embeddings.py +260 -0
- agenttune/rag/synthesis/evaluate.py +306 -0
- agenttune/rag/synthesis/generate.py +302 -0
- agenttune/rag/synthesis/graph.py +483 -0
- agenttune/rag/synthesis/io_utils.py +95 -0
- agenttune/rag/synthesis/llm_client.py +372 -0
- agenttune/rag/synthesis/paths.py +255 -0
- agenttune/rag/synthesis/requires_search_filter.py +96 -0
- agenttune/rag/synthesis/schema.py +173 -0
- agenttune/rag/synthesis/solve_difficulty.py +209 -0
- agenttune/rag/synthesis/split.py +292 -0
- agenttune/rag/synthesis/verify.py +568 -0
- agenttune/rag/tools/__init__.py +12 -0
- agenttune/rag/tools/read_document.py +60 -0
- agenttune/rag/tools/search_corpus.py +55 -0
- agenttune/rag/tools/xml_tool_parser.py +36 -0
- agenttune/rag/trainer.py +210 -0
- agenttune/rag/trajectory_utils.py +60 -0
- agenttune/scenarios/__init__.py +54 -0
- agenttune/scenarios/collection.py +139 -0
- agenttune/scenarios/generator.py +585 -0
- agenttune/scenarios/normalizer.py +273 -0
- agenttune/scripts/__init__.py +3 -0
- agenttune/utils/__init__.py +138 -0
- agenttune/utils/auth.py +243 -0
- agenttune/utils/checkpointing.py +424 -0
- agenttune/utils/colored_logging.py +268 -0
- agenttune/utils/config_extractor.py +336 -0
- agenttune/utils/config_utils.py +514 -0
- agenttune/utils/device.py +423 -0
- agenttune/utils/diagnostics.py +462 -0
- agenttune/utils/environment.py +357 -0
- agenttune/utils/errors.py +482 -0
- agenttune/utils/hf_publish.py +789 -0
- agenttune/utils/inference_utils.py +39 -0
- agenttune/utils/logging.py +299 -0
- agenttune/utils/model_class_resolver.py +42 -0
- agenttune/utils/model_loader.py +561 -0
- agenttune/utils/optional.py +48 -0
- agenttune/utils/provenance.py +64 -0
- agenttune/utils/score_logger.py +104 -0
- agenttune/utils/validation.py +551 -0
- agenttune-1.1.0.dist-info/METADATA +636 -0
- agenttune-1.1.0.dist-info/RECORD +315 -0
- agenttune-1.1.0.dist-info/WHEEL +5 -0
- agenttune-1.1.0.dist-info/entry_points.txt +2 -0
- agenttune-1.1.0.dist-info/licenses/LICENSE +83 -0
- 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
|