Skip to contents

A harness is a function you call exactly like peter(). gptr_tailor() makes one from peter or from another harness, without calling any model: it fixes peter() arguments such as mode, model, tools or extensions, it can carry your own hard rules, and it can carry coaching, plain data that gptr itself turns into a note added to peter's instructions, skills peter can open, a review that asks peter to check its work once or twice before it stops, and hard rules. Each call of the harness is the same call as peter() with those arguments added, so objects, envir, {name} interpolation, gptr_last(), pipes, lapply() and do.call() behave as with peter().

Usage

gptr_tailor(x = peter, ..., rules = NULL, coaching = NULL, dir = NULL)

Arguments

x

peter or a harness to start from.

...

Named peter() arguments to fix, resolved now as peter() resolves them (so mode = auto is "auto"); prompt is each call's task and cannot be fixed. plugins cannot hold "+name" or "-name" filters, which would change the whole R session.

rules

NULL to keep your rules of x, else your own hard rules, which no coaching changes: list(never, require). never holds up to 8 list(rule, why): a call that matches rule is refused in every mode, also in sub-agents, with "denied by your rule". require holds up to 4 list(id, any, contains, text) or list(id, made, text): when peter is about to finish without a matching call in that run, text is sent to it, at most twice, and the run ends with a notice naming id. A rule or an any pattern is a permission rule (see gptr_permissions()) of the kind r(fn:name), r(category:name), r(sh:glob), r(sql:keyword) or a path glob such as write(data/raw/**); it matches when any call in the code does, and fn: names every function the code calls. A require pattern names only functions or categories rated below level 3. contains is text the call's code must hold; made is "plot" or "file:<glob>" (a file inside the project changed during the run). list() drops your rules.

coaching

NULL to keep the coaching of x, else list(note, skills, review, rules): note one string of at most 8,000 characters; skills a list of list(name, description, text) with names such as "survey-weights", descriptions of at most 1,024 characters and 64 KiB in all; review list(text, rounds) with at most 2,000 characters and 0 to 2 rounds (default 1); rules as rules above, refused with "denied by the coaching rule". The texts may not hold control characters, zero-width or other format characters (so text in a script or an emoji sequence that needs a zero-width joiner cannot appear), tags of gptr's own prompt blocks, or gptr's wording for a message from you or an extension.

dir

A folder to write the harness to for people to read or keep in git (HARNESS.md, NOTE.md, REVIEW.md, RULES.md and skills/<name>/SKILL.md). gptr never reads it back.

Value

A harness, a function of class gptr_harness with a new id and an empty record (invisibly when dir is given). h$coaching and h$record show its coaching and record, and h$report the last full coaching report of this R session.

Details

Arguments you give in a call win over the fixed ones, except that tools, extensions, plugins and skills add to the fixed values and .opts entries replace them by name. The same rule applies when you tailor a harness again; NULL drops a fixed single value.

To share a harness, save it with saveRDS(). Treat a harness from someone else like an R script from them: functions among its fixed arguments, and the extension files it names, run when you call it. Load it with gptr_tailor(readRDS(file)), which rebuilds it, checks its coaching and shows the code, extensions and plugins it fixes and any system prompt it replaces.

See also

gptr_coach() to improve the coaching by running your task, and peter().

Examples

fake = gptr_fake_provider(list("The data has 32 rows.", "Checked: 32 rows."))
count_peter = gptr_tailor(peter, model = fake, coaching = list(
  note = "Count rows with nrow(), never by eye.",
  review = list(text = "Run the count once more before you answer.", rounds = 1)))
#> This harness loads code or loosens checks:
#> model = <provider fake>
count_peter
#> <gptr_harness 8974b3dbe6cf> built on peter (gptr 1.0.0)
#> fixed: model = <provider fake>
#> your rules: none
#> coaching: note 37 characters, 0 skill(s), review 1 round(s), rules none
#> record: none
session = count_peter("How many rows does the data have?", mtcars)
#> gptr: thinking
#> gptr: thinking
#> gptr: done · fake-1 · 2 requests · 3.2k tokens · 99% context left
session$text
#> [1] "Checked: 32 rows."