Trayntrayn.ai

Getting Started

RL Environments for Real-World AI Agents

Record any workflow on any app with our browser extension (Chrome or Firefox). Trayn creates a fully interactive, anonymized RL playground where agents can safely practice sending emails, escalating tickets, placing orders, and every other operation you'd never risk on a live system.

Each action is graded in real-time and packaged into training memories the agent retrieves to improve on the next attempt.

How It Works

Record a workflow on any app

Install the Trayn browser extension (Chrome or Firefox), navigate to any app, and complete a task. Trayn captures every screen state and interaction. All personal data is detected and replaced offline in your browser before anything is stored.

Get an interactive playground with auto-generated tasks

Trayn turns your recording into an RL playground — every button, dropdown, and navigation works exactly as the real app. It also extracts a task definition: a goal, verifiers, and expected actions.

Train your agent against it

Point the SDK at a playground URL. Your agent attempts the task, gets graded on each step, and stores memories of what worked and what didn't. On the next repetition, it retrieves those memories and improves.

Architecture

The training loop runs through both packages:

  1. @trayn/agent-sdk fetches the task from your playground, drives a real browser, and sends each step to the grader for multimodal evaluation
  2. @trayn/memory stores graded memories with environment embeddings, then retrieves relevant REPEAT/AVOID memories on subsequent reps so the agent learns from mistakes

Installation

npm install @trayn/agent-sdk
bun add @trayn/agent-sdk
pnpm add @trayn/agent-sdk
yarn add @trayn/agent-sdk

The SDK requires Playwright. Install browsers after:

npx playwright install chromium
PackagePurpose
@trayn/agent-sdkAgent interface, harness, browser environment, accessibility tree, actions, CLI, grading
@trayn/memoryMemory storage, retrieval, embeddings — works standalone with any agent

Installing @trayn/agent-sdk pulls in @trayn/memory automatically.

Quick Start

Install the browser extension

Install the Trayn browser extension (Chrome or Firefox). This captures your workflow — every screen state and interaction.

Record a workflow

Open any app in your browser and click Record in the extension. Complete the workflow you want your agent to learn. When done, hit Stop.

View in the Trayn app

Open app.trayn.ai. Your recordings appear in the timeline. Trayn anonymizes, creates a playground, and generates a task definition.

Train your agent

Your new playground appears in app.trayn.ai alongside all your other playgrounds. Copy its URL and run the CLI:

trayn --url https://app.trayn.ai/playground/{host}/{sessionId} --max-steps 15 --reps 3

Results — per-step grades, accuracy scores, and memory diffs — appear in the Experiments panel in the web app.

For custom agents, use the SDK directly:

import { harness } from "@trayn/agent-sdk";

await harness({
  agentargs: {
    agent_name: "my-agent",
    make_agent: () => ({
      get_action: async (obs) => {
        return ["click('42')", { think: "clicking submit" }];
      },
      store_grades: async (result) => {
        console.log("Completed:", result.taskCompleted);
      },
    }),
  },
  url_override: "https://app.trayn.ai/playground/{host}/{sessionId}",
}).run();

Training Outputs

Every training run produces structured data you can consume directly or feed into other platforms:

OutputFormatDescription
Step gradesGradingResult JSONPer-step isCorrect, explanation, and correction for wrong steps
MemoriesMemoryEntry[] JSONAction, outcome (success/failure), reason, and correction per step
Embeddings3072-dim vectorsEnvironment + internal-state embeddings for similarity retrieval

Memories use a REPEAT/AVOID format — successful steps become REPEAT memories, failed steps become AVOID memories with a correction field describing what the agent should have done instead. On subsequent repetitions, relevant memories are retrieved and injected into the agent's prompt:

action -> FAILED: clicked wrong button | DO INSTEAD: click the "Save" button in the toolbar

This data is portable. Export memories and grades from the Experiments panel or read them via the @trayn/memory package to plug into your own fine-tuning, RLHF, or evaluation pipelines.

Authentication

To access your playgrounds from the CLI or SDK, you need to authenticate with your Trayn account. This is the same account you use to sign in at app.trayn.ai.

On first run, the CLI prompts for your email and saves it locally:

trayn --url https://app.trayn.ai/playground/...
#  Email: you@company.com (saved to ~/.config/trayn/config.json)
#  ✓ Saved

This credential links all your training runs to your account — grading results, memories, and experiments all appear under your profile in the web app. It also authorizes access to your playgrounds so only you (and your team) can run agents against them.

CLI Reference

trayn [options]
FlagTypeDefaultDescription
--urlstringPlayground URL
--agentstringtraynAgent to use (trayn or openclaw)
--max-stepsnumber5Maximum actions per task
--repsnumber3Repetitions (rep 1 = baseline, rep 2+ = with memory)
--headlessbooleanfalseRun browser without UI
--verbosebooleanfalseShow accessibility tree previews
--debugbooleanfalseEnable debug logging
--grader-endpointstringTrayn APICustom grading endpoint (or none to skip)
--session-idstringautoOverride session ID
--confirmbooleanfalseReview and edit the task before running

Programmatic Usage

import { harness } from "@trayn/agent-sdk";

await harness({
  agentargs: {
    agent_name: "my-agent",
    make_agent: () => ({
      get_action: async (obs) => {
        // obs.goal — task objective fetched from the backend
        // obs.url — current playground page URL
        // obs.axtree_txt — accessibility tree with element BIDs
        // obs.last_action_error — feedback from previous action
        return ["click('42')", { think: "clicking the submit button" }];
      },
      store_grades: async (result) => {
        console.log("Completed:", result.taskCompleted);
      },
    }),
  },
  url_override: "https://app.trayn.ai/playground/{host}/{sessionId}",
}).run();

Environment Variables

The CLI and SDK need an API key for whichever AI provider your agent uses. Trayn supports OpenAI, Anthropic, Google, and any provider compatible with the Vercel AI SDK.

VariableRequired ForDescription
OPENAI_API_KEYOpenAI modelsRequired if your agent uses OpenAI (default for built-in TraynAgent)
ANTHROPIC_API_KEYAnthropic modelsRequired if your agent uses Claude
GOOGLE_GENERATIVE_AI_API_KEYGoogle modelsRequired if your agent uses Gemini

Memory storage and grading are handled by Trayn's backend using your account credentials — no additional infrastructure keys required.

On this page