Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions examples/agent_demo/make_showcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
uv run --extra mcp python examples/agent_demo/make_showcase.py claude codex pi

DEMO_SCENARIO picks the scenario (runs/<scenario>/ -> showcase/<scenario>/).
A recording of one of the scenario's suggested questions goes under
showcase/<scenario>/questions/<id>/, from a run folder given with --from:

make_showcase.py --question calls --from <run dir> claude
"""

from __future__ import annotations

import argparse
import getpass
import json
import re
Expand Down Expand Up @@ -46,18 +51,31 @@ def sanitize(agent: str, line: str, run_dir: Path) -> str | None:
text = text.replace(path + "/", "").replace(path, ".")
text = text.replace(str(HERE.parent.parent), "<repo>")
text = re.sub(r"/(Users|home)/[^/\"\\\\]+", "~", text)
# The agent's sandbox temp folder names the local user id.
# Claude Code's temp folders, which name the user id and, by project,
# the home folder ("claude-501/-Users-jdoe-src-x").
text = re.sub(r"claude-\d+/-(Users|home)-[A-Za-z0-9._-]+", "claude", text)
text = re.sub(r"(/private)?/tmp/claude-\d+", "/tmp", text)
# The login as the owner, and on Linux often the group, in `ls -l`
# output ("1 jdoe staff", "1 jdoe jdoe").
login = re.escape(getpass.getuser())
text = re.sub(rf"(\s\d+ ){login}(\s+){login}(\s)", r"\1user\2user\3", text)
return re.sub(rf"(\s\d+ ){login}(\s+\w+\s)", r"\1user\2", text)


def main(agents: list[str]) -> None:
def main(
agents: list[str], question: str | None = None, source: Path | None = None
) -> None:
scenario = scenarios.load()
if question:
ids = [s[0] for s in scenario.task.LABELS.get("suggestions", [])]
if question not in ids:
sys.exit(f"no suggested question {question!r}: one of {ids}")
for agent in agents:
run_dir = scenario.runs / agent
run_dir = source or scenario.runs / agent
out = scenario.showcase / agent
if question:
out = scenario.showcase / "questions" / question / agent
shutil.rmtree(out, ignore_errors=True)
out.mkdir(parents=True)
lines = (run_dir / "transcript.jsonl").read_text().splitlines()
Expand All @@ -68,6 +86,12 @@ def main(agents: list[str]) -> None:
]
(out / "transcript.jsonl").write_text("\n".join(kept) + "\n")
shutil.copy(run_dir / "report.md", out / "report.md")
# The run's question and plan: inside a run folder given with
# --from (only there: its parent may hold another run's), else
# beside it, where the page keeps it.
ask = run_dir / "ask.json" if source else run_dir.parent / f".{agent}.ask.json"
if ask.is_file(): # an open question: what was asked, the plan
shutil.copy(ask, out / "ask.json")
(out / "score.json").write_text(
json.dumps(score(run_dir, scenario), indent=2) + "\n"
)
Expand All @@ -78,4 +102,11 @@ def main(agents: list[str]) -> None:


if __name__ == "__main__":
main(sys.argv[1:] or ["claude", "codex", "pi"])
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("agents", nargs="*", default=["claude", "codex", "pi"])
parser.add_argument("--question", help="a suggested question's id")
parser.add_argument("--from", dest="source", type=Path, help="the run folder")
args = parser.parse_args()
if args.source and len(args.agents) != 1:
parser.error("--from takes one agent")
main(args.agents, args.question, args.source)
11 changes: 10 additions & 1 deletion examples/agent_demo/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
- task.py the files, the id and outcome columns, the page's labels
(its steps); optionally the raw files' own names for the
id and outcome, and how to read the outcome's rate there
- PROMPT.md the agent's task
- PROMPT.md the agent's task (the fixed brief)
- CONTEXT.md optional: the setting for open questions (see .context)
- prepare_data.py builds the data: main(scenario) writes the workspace and
the withheld answers

Expand Down Expand Up @@ -54,6 +55,14 @@ def folder(self) -> Path:
def prompt(self) -> Path:
return self.folder / "PROMPT.md"

@property
def context(self) -> Path | None:
"""CONTEXT.md, when the scenario takes open questions: what the
organisation sets up once (who the analyst is, the files, the team's
conventions), to which the asker adds a question and a plan."""
path = self.folder / "CONTEXT.md"
return path if path.is_file() else None

@property
def workspace(self) -> Path:
# DEMO_WORKSPACE replaces the data folder, whatever the scenario
Expand Down
28 changes: 28 additions & 0 deletions examples/agent_demo/scenarios/insurance/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
You are an analyst on the group retention team at Maple Mutual Group
Benefits, a Canadian insurer that sells group health, dental, life and
disability plans to employers. In this directory are two raw exports
from the plan administration system:

- `renewals_2025_export.csv`: last year's plan renewals, with
`Renewal Status`: did the employer renew its plan with us or leave?
- `renewals_due_export.csv`: plans whose renewal is due in the next
three months. Nobody knows yet who will leave.

You have tabular foundation models (the tabctx tools) for predictions
from tables. Use them, not a model you write yourself.

The team's conventions, so others can reuse your work:

- If you clean the exports, do it with one Python script, `clean.py`
(pandas is installed), and write `renewals_2025.csv` and
`renewals_due.csv`: snake_case column names (`Plan ID` becomes
`plan_id`), one row per plan, and in the history `terminated` is Yes
(the employer left) or No.
- Keep the predictions CSV the tools write for the due plans.
- Write your answer to `report.md`, in plain language, for the person
who asked.

Say plainly which findings are patterns the model learned rather than
proven effects. When you claim a threshold, or that something makes no
difference, give the uncertainty and the smallest effect the data could
have detected.
31 changes: 31 additions & 0 deletions examples/agent_demo/scenarios/insurance/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,40 @@ def positive_rate(history) -> float:
"at renewal and why, and test what could keep them. Write it up for "
"the head of group retention."
),
# Questions to start from (id, the card's words, the question). The
# open questions that held up against the real outcomes in testing.
"suggestions": [
[
"retention",
"Who will leave, and what could keep them?",
"Clean up these two exports, find which employers are likely to leave "
"at renewal and why, and test what could keep them. Write it up for "
"the head of group retention.",
],
[
"calls",
"Which 50 employers should we call first?",
"Which 50 employers renewing in the next three months should our "
"account managers call first, and what should they talk about with "
"each one?",
],
[
"premium",
"How much premium is at risk?",
"How much annual premium is at risk of walking out the door in the "
"next three months, and where is it concentrated?",
],
[
"reviews",
"Are account reviews worth it?",
"We're thinking of giving every at-risk plan an account review "
"meeting next quarter. Is it worth it, and which plans should get one?",
],
],
"audience": "the head of group retention",
"entity": "employers",
"outcome": "left",
"likely": "likely to leave",
"window": "at renewal",
"history": "last year's plan renewals",
"current": "renewals due",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"question": "Which 50 employers renewing in the next three months should our account managers call first, and what should they talk about with each one?", "plan": [{"kind": "clean", "text": "Fix messy formats in both files so every plan is one consistent row."}, {"kind": "evaluate", "text": "Check how well last year's renewals show which employers were likely to leave."}, {"kind": "predict", "text": "Score each upcoming renewal for its chance of leaving."}, {"kind": "analyze", "text": "Rank plans by leaving risk and premium at stake, then pick the top 50."}, {"kind": "explain", "text": "Find what most separates leavers from stayers, for each account's talking points."}, {"kind": "report", "text": "Write the call list with talking points and say how certain each finding is."}]}
Loading