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
2 changes: 1 addition & 1 deletion plugins/fxtr/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fxtr",
"version": "0.1.4",
"version": "0.1.5",
"description": "Write, run, and view fxtr experiments, and call models from them with behaviors.",
"author": {
"name": "Transluce",
Expand Down
57 changes: 44 additions & 13 deletions plugins/fxtr/skills/behaviors/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ The pages below are its documentation. Read the ones a task needs before writing

## Where to read

| Task | Read |
| ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------- |
| Add behaviors to a project; hold a conversation, judge outputs, and summarize verdicts in fxtr steps; test without credentials | [Calling language models](references/guides/language-models.mdx) |
| Pick a provider, an adapter, and an exact model ID | [Choosing models](references/guides/choosing-models.mdx) |
| Script users or simulate them with models (a base model, steered by a pilot), offer tools, or write a custom conversation flow | [Policies and tools](references/guides/policies-and-tools.mdx) |
| Rollout statuses and `max_turns`, failures, retries, streaming | [Rollout outcomes and retries](references/guides/rollout-outcomes.mdx) |
| Messages and content, stored records, transcripts, conversations in the viewer, checkpoints | [Conversation records and checkpoints](references/guides/conversation-records.mdx) |
| Run Docent readings, or convert records for Docent | [Docent readings](references/guides/docent-readings.mdx) |
| Choose a layer; imports, adapters and their options, model providers, sampling and reasoning settings, requests and responses | [API overview](references/reference/api.mdx) |
| Steps, workflows, arrays, launching jobs, and the step cache | the adjacent [fxtr skill](../fxtr/SKILL.md) |
| Task | Read |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| Add behaviors to a project; hold a conversation, judge outputs, and summarize verdicts in fxtr steps; test without credentials | [Calling language models](references/guides/language-models.mdx) |
| Pick a provider, an adapter, and an exact model ID | [Choosing models](references/guides/choosing-models.mdx) |
| Script users or simulate them with models (a base model, steered by a pilot), offer tools, or write a custom conversation flow | [Policies and tools](references/guides/policies-and-tools.mdx) |
| What each provider's dialect carries, adaptation losses and refusing them, structured output (`response_format`, strict tools, tool output schemas), refusals and other stops, codecs | [Dialects and adaptation](references/guides/dialects-and-adaptation.mdx) |
| Rollout statuses and `max_turns`, failures, retries, streaming | [Rollout outcomes and retries](references/guides/rollout-outcomes.mdx) |
| Messages and content, stored records, transcripts, conversations in the viewer, checkpoints | [Conversation records and checkpoints](references/guides/conversation-records.mdx) |
| Run Docent readings, or convert records for Docent | [Docent readings](references/guides/docent-readings.mdx) |
| Choose a layer; imports, adapters (including Gemini and OpenRouter) and their options, model providers, sampling, reasoning and speed settings, requests and responses | [API overview](references/reference/api.mdx) |
| Steps, workflows, arrays, launching jobs, and the step cache | the adjacent [fxtr skill](../fxtr/SKILL.md) |

## Best practices

Expand All @@ -33,6 +34,36 @@ The pages below are its documentation. Read the ones a task needs before writing
models shows, rather than substituting another. Without credentials to check, take candidate
IDs from the provider's published catalog, and tell the user that account access has not been
verified.
* **Shape model experiments as the guide does**: one step per conversation, with every setting
that affects the request in a configuration entity; fxtr replicas for repeated samples; and
separate steps for judging and for aggregating verdicts.
* **Make each argument of a model call its own step input.** Then every result points at the
exact settings that produced it, and the cache sees every setting. Hard-code nothing that
affects a request in a step.
* The model is a `model_name` string, such as `openai/gpt-6-luna`. The project's own
`make_api(model_name)` builds the `ModelAPI` from it, and the step closes the API in
`finally`. The string is the record of which model was called: a `Judgment` holds none.
* Sampling is a `SamplingParamsEntity` the project defines, a frozen `DataclassEntity` with one
field, `params: SamplingParams`. An fxtr array can't hold a `SamplingParams` as a value, but
it can hold a reference to an entity. behaviors provides no such type.
* A prompt, a rubric, the judge's instructions, and an output schema (as JSON text) are
`TextEntity` inputs.
* **Shape model experiments as the guide does**: one step per conversation; fxtr replicas for
repeated samples; and separate steps for transcripts, judging, and aggregating judgments.
* **Judge with behaviors' `judge`**, from `behaviors.judging.judge`, which returns a `Judgment`.
Write its output schema with a `behaviors.judging.schemas` function (`binary_schema`,
`continuous_schema`, `categorical_schema`, `structured_schema`). Each starts with a
`discussion`, so the judge explains before it decides. For the instructions, start from
`DEFAULT_SYSTEM_INSTRUCTIONS_ENTITY`, from `behaviors.judging.defaults`. `judge` needs
`jsonschema`, which a project adds itself: `uv add "behaviors[models]" jsonschema`.
* **Point at evidence with a citation, not a number.** When a judge's answer has to name a place
in an entity (the message where a behavior first appears, the line a score rests on), make that
field a citation field, written by a `CustomFormat`'s `schema` method, and ask for exactly one
citation, or an empty string when there is none. The viewer draws such a field as a link that opens the entity at that place. An integer
index is drawn as a bare number.
* **Link a judge's call output first.** When you link the user to one call of a judge step, add
`section_order=output_first` to its `invocation` view, so the judgment shows above the
transcript and rubric it was given:
`p=invocation(/judge,item=0127,judge=sonnet,section_order=output_first)`.
* **Use as many citation fields as the answer needs.** One schema can have several, and they need
not be checked the same way: each way is a `CustomFormat` with a name of its own, which writes
its field with `schema(description=...)` and is passed to `judge` in `custom_formats` (lines in
a discussion, a whole message in a field that points at one). See
[Citations](references/reference/api.mdx#citations).
8 changes: 4 additions & 4 deletions plugins/fxtr/skills/behaviors/provenance.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"skill": "behaviors",
"documentation": "https://docs.transluce.ai/behaviors",
"packages": {
"fxtr": "0.1.0a0",
"behaviors": "0.0.1a4"
"fxtr": "0.2.0a0",
"behaviors": "0.0.1a5"
},
"revision": "052f907cc35979930fda832a71aec0c2194e7e48",
"revision": "6432f6ad1682ca0a8ff344a6ef66cb09bbccb8f7",
"modified": false,
"content_sha256": "a9a5b26e4b86c7b765f0d3c7ce1ce7bea062364e7112c5bec2ad86aed6ca2f1d"
"content_sha256": "f67fdb291628ed957c6fa39d933926312c3c3864bea083e28264c69666da8d96"
}
1 change: 1 addition & 0 deletions plugins/fxtr/skills/behaviors/references/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ in the order of the site's navigation.

- [Choosing models](guides/choosing-models.mdx): Find the exact model IDs a provider offers your account, pick the adapter for its endpoint, and check a model before a sweep.
- [Conversation records and checkpoints](guides/conversation-records.mdx): What a rollout records, how conversations are stored as fxtr entities and flattened into transcripts, and how to checkpoint a session.
- [Dialects and adaptation](guides/dialects-and-adaptation.mdx): How a request reaches each provider: the dialects the adapters speak, what an adapter changes to send a request and how to refuse it, structured output, responses that are not answers, and the codecs behind the adapters.
- [Docent readings](guides/docent-readings.mdx): Convert conversations to Docent's data models, and run a Docent reading against a transcript or agent run with a model you choose.
- [Calling language models](guides/language-models.mdx): Use the behaviors library to hold conversations and judge outputs in fxtr steps.
- [Policies and tools](guides/policies-and-tools.mdx): Decide what the model sees each turn: scripted users, users simulated by a base model and steered by a pilot, tool policies, their combinations, and custom conversation flows.
Expand Down
49 changes: 34 additions & 15 deletions plugins/fxtr/skills/behaviors/references/guides/choosing-models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ This is one page, even with `limit=1000`. While `has_more` is true, request the
`after_id` set to the returned `last_id`, and collect its models before advancing again.
Pass a returned `id` to `AnthropicMessagesAPI(model_id)`; `display_name` is only for presentation.

## Gemini

[List models](https://ai.google.dev/api/models#method:-models.list)
with `GET https://generativelanguage.googleapis.com/v1beta/models`:

```bash
curl --fail-with-body --silent --show-error \
'https://generativelanguage.googleapis.com/v1beta/models?pageSize=1000' \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-o /tmp/gemini-models.json &&
jq -r '.models[]
| select(.supportedGenerationMethods | index("generateContent"))
| [(.name | sub("^models/"; "")), .displayName] | @tsv' /tmp/gemini-models.json &&
jq '{nextPageToken}' /tmp/gemini-models.json
```

While `nextPageToken` is set, request the next page with `pageToken` set to it. The filter keeps
models that serve `generateContent`, the method the adapter calls. Pass the returned `name`
without its `models/` prefix to `GeminiGenerateContentAPI(model_id)`, from
`behaviors.implementations.models.gemini`.

## OpenRouter

OpenRouter serves models from multiple vendors through an OpenAI-compatible endpoint. Its
Expand All @@ -71,31 +92,29 @@ For the general catalog, change `/models/user` to `/models`. The
Use the full returned `id`, including its vendor prefix and any suffix, with:

```python
import os

from behaviors.implementations.models.openai_compatible import OpenAICompatibleAPI
from behaviors.implementations.models.openrouter import OpenRouterAPI

api = OpenAICompatibleAPI(
model_id, # Exact id selected from the OpenRouter listing.
base_url="https://openrouter.ai/api/v1",
api_key=os.environ["OPENROUTER_API_KEY"],
)
api = OpenRouterAPI(model_id) # Exact id selected from the OpenRouter listing.
```

The OpenAI SDK does not read `OPENROUTER_API_KEY` by itself, so pass it explicitly as above.
`OpenRouterAPI` reads `OPENROUTER_API_KEY` unless you pass `api_key`, and sends back the
reasoning state OpenRouter returns, which `OpenAICompatibleAPI` pointed at OpenRouter would not.
Close the adapter with `await api.aclose()` when finished, as in the
[conversation step](language-models.mdx#a-conversation-as-a-step).

## Search and validate a candidate

Search a saved response by ID or display name, changing the file and search text as needed:
Search a saved response by ID or display name, changing the file and search text as needed. The
filter reads any of the listings above: Gemini's lists `models` rather than `data`, and its `name`
is the ID with a `models/` prefix, which the filter removes.

```bash
jq -r --arg query 'claude' '
.data[]
| select(([.id, (.name // .display_name // "")] | join(" ") | ascii_downcase)
(.data // .models)[]
| (.id // (.name | sub("^models/"; ""))) as $id
| select(([$id, (.display_name // .displayName // .name // "")] | join(" ") | ascii_downcase)
| contains($query | ascii_downcase))
| .id
| $id
' /tmp/openrouter-models.json
```

Expand All @@ -105,6 +124,6 @@ streaming, tools, and reasoning, then try the chosen adapter and sampling settin
request before launching a sweep. Without credentials, the providers' published catalogs and
documentation give candidate IDs, but not whether your account can use them.

Keep the chosen provider, model ID, and request settings in the experiment's configuration
inputs, so that each run records what was selected (see
Pass the chosen provider and model ID, and each request setting, to the step as inputs, so that
each run records what was selected (see
[A conversation as a step](language-models.mdx#a-conversation-as-a-step)).
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ are stored and shown, and how they differ from a session's checkpoint.
Messages are `SystemMessage`, `UserMessage`, `AssistantMessage`, and `ToolMessage`, each holding a
tuple of typed content blocks. An assistant's content may include text, tool calls, reasoning,
redacted reasoning, or summarized reasoning, so don't assume every block has `.text`. For the
answer's text alone, keep the `ContentText` blocks of the turn's `AssistantMessage`s, as the
[judge step's](language-models.mdx#a-judge-step) `answer_text` does, and keep the
structured rollout for later inspection.
answer's text alone, keep the `ContentText` blocks of the turn's `AssistantMessage`s, and keep the
structured rollout for later inspection. To give a whole conversation to a judge, flatten it into
a `Transcript`, as the [judge step](language-models.mdx#a-judge-step) does.

## Metadata

Expand Down Expand Up @@ -72,7 +72,7 @@ initializations, such as `SetSystemMessage`, are fxtr entities, with type IDs of
`org.transluce.behaviors.<Class>.v<N>`, such as `org.transluce.behaviors.ChatRollout.v2`. A
version is bumped when a type's stored shape changes, and a record stored under an earlier version
doesn't load as the current type. Versions are per type: `ChatRollout` and its turns use `.v2`,
while messages and `ModelResponse` use `.v1`. Only the current version of each type is supported.
messages use `.v1`, and `ModelResponse` uses `.v2`. Only the current version of each type is supported.

A step that returns a `ChatRollout` has it stored like any other entity
(see [Entities and custom types](../../../fxtr/references/concepts/entities-and-custom-types.mdx)), and
Expand Down
Loading
Loading