# Lexsi Labs Hackathon — Track 3 (Agentic Fine-tuning): AgentMart Tool-Calling Pipeline Chains **two Lexsi Labs toolkits** for reliable tool calling, targeting a Cohere Labs open-weights student model: - **AgentTune** — trajectory / post-training data formats (reference clone in `AgentTune_ref/`, from https://github.com/lexsi-labs/AgentTune). - **AuditKIT** (`auditkit==1.1.11` from PyPI) — agent evaluation metrics, used through its real API (`Sample`, `ToolCallF1`, `ToolCallValidity`, `RedundantToolCalls`, `TrajectoryMatch`, `load_agenttune`, `episodes_from_agenttune`). - **Student target (GPU step):** `CohereLabs/aya-expanse-8b` / `CohereLabs/tiny-aya-global` — see `train_aya_sft.ipynb`. **What is measured locally vs. the GPU step:** the executed local run evaluates two *agent policies* (naive baseline vs. a policy distilled by code from the AgentTune trajectories) with AuditKIT scoring. The Cohere fine-tune itself is the notebook step and has **not** been run yet — no LLM metrics are claimed. See `ARTICLE.md` for the full write-up and the real before/after table. ## Layout | Path | What | |---|---| | `src/tasks.py` | 5 tool schemas + deterministic tool implementations + 170-task suite (130 train / 40 held-out test, entity/value-disjoint) | | `src/generate_data.py` | Builds `data/tasks.json`, `data/sft_agenttune.jsonl`, `data/trajectories.jsonl` | | `src/policies.py` | `BaselinePolicy` (naive keyword agent) + `LearnedPolicy` (naive-Bayes router + learned cue/shape extractor, fitted on the SFT file) | | `src/evaluate.py` | Harness: scores both policies on the test split (own metrics + AuditKIT), verifies AgentTune→AuditKIT parsing, writes `results/metrics.json` | | `data/sft_agenttune.jsonl` | 130 SFT rows in AgentTune `EventLog.as_dataset_rows('sft')` format (`messages`, `segment_weights`, `loss_mask`) | | `data/trajectories.jsonl` | 130 TrajectoryDataset records (AgentTune trainer format; AuditKIT-readable) | | `results/metrics.json` | Real before/after numbers from the executed run | | `RUN_OUTPUT.txt` | Full console output of the executed pipeline | | `train_aya_sft.ipynb` | GPU notebook: TRL SFT (LoRA) on Aya Expanse 8B + AgentTune-native alternative + AuditKIT hand-off (not executed locally) | | `ARTICLE.md` | HF-Article-style write-up with the real metrics | | `AgentTune_ref/` | Shallow clone of Lexsi-Labs/AgentTune used as the format source (README "Hand the run to AuditKIT"; `src/agenttune/agentic/events.py` for the SFT row schema) | ## Reproduce (Python 3.12, CPU only) ```bash cd lexsi-agentmart python3 -m venv .venv .venv/bin/pip install auditkit==1.1.11 # or: .venv/bin/pip install -r requirements.txt .venv/bin/python src/generate_data.py .venv/bin/python src/evaluate.py # prints the report, writes results/metrics.json ``` Expected headline result (held-out test, n=40): task success **0.15 → 1.00**, tool-selection accuracy **0.75 → 1.00**, AuditKIT redundant calls **0.1375 → 0.00** — with the in-distribution caveat documented in `ARTICLE.md`. ## Formats — where each came from - **SFT rows:** AgentTune `EventLog.as_dataset_rows(fmt='sft')` (`AgentTune_ref/src/agenttune/agentic/events.py`): one `{"messages", "segment_weights", "loss_mask"}` row per trajectory; tool calls rendered as `{"name": ..., "arguments": {...}}` assistant messages (weight 2.0), tool results as `tool` messages (weight 0.0). - **Trajectories:** AgentTune README, "Hand the run to AuditKIT": one JSONL record per rollout — `{"task", "steps": [{"action": {"tool_calls": [{"id", "name", "arguments"}]}, "observation"}], "final_response", "metadata": {"conversation": [...]}}`. Verified: `auditkit.load_agenttune()` returns 130 samples and `episodes_from_agenttune()` 130 episodes for our file. - **AuditKIT scoring:** `Sample(input, tools=, expected_tool_calls=[[gold]])` scored with `metric.score(sample, output, {"trace": {"tool_calls": turns}})`. ## Notes - Train/test split: prompts fully disjoint; entities and values (topics, expressions, people, symbols, cities, dates) disjoint across splits; template wording families shared — disclosed in `ARTICLE.md` Limitations. - Nothing in this repo has been pushed to GitHub or Hugging Face, and no submission form has been filled — that step belongs to the team lead.