How Trayn Works
From a single recording to an interactive playground to a trained agent.
The Full Picture
Recording
Install the Trayn browser extension for Chrome or Firefox. Navigate to any website and record yourself completing a workflow.
Privacy-First Anonymization
Before anything is stored, Trayn detects and replaces all personal data — entirely offline in your browser. Nothing leaves your machine until anonymization is complete.
- Offline Anonymization — AI models run directly in your browser for identifying and replacing sensitive information.
- Context Preservation — Anonymized identities and context are maintained and mapped to ensure consistent representation across applications.
Playground Generation
From just a few recordings, Trayn creates a hyper-realistic, anonymized, fully interactive clone of the original application. These are standalone RL environments where every button, popup, dropdown, and navigation works as they do on the real app.
Trayn analyzes the recorded interactions to understand the app's behavior — how clicks cause UI changes, how inputs flow through forms, how elements relate to each other and hundreds of micro interactions to generate the most accurate sandboxed playgrounds to train your agent.
Each recording produces a task-specific playground where actions are tracked and graded with guidance on what should have been done instead. This data is packaged as memories the agent can retrieve on subsequent attempts.
Task Generation
Trayn analyzes each recording and extracts a task definition:
- Goal — Natural language description ("Change ticket priority to High and add the 'escalated' tag")
- Verifiers — Success criteria (screenshot of expected final state, DOM checks)
- Expected actions — Semantic descriptions of each step the user took
All of the above are editable and customizable in the application as well as the SDK.
Agent Training Loop
The core of Trayn is a learning loop: attempt → grade → remember → improve.
Repetitions
Each CLI run executes the task multiple times:
- Run 1 — Baseline run, no memory retrieval
- Run 2+ — Retrieves memories from previous reps
Memories tell the agent what worked ("REPEAT: clicked the save button") and what didn't ("AVOID: clicked the wrong dropdown — DO INSTEAD: use the priority dropdown in the sidebar").
Pluggable Adapter Architecture
Every I/O boundary in Trayn is an interface you can replace. This lets you use Trayn's learning loop with any infrastructure:
Each adapter is configured via a dependency injection singleton:
See the individual adapter docs for interface details and custom implementation examples:
- Grading —
GraderAdapter - Retrieval —
RetrieverAdapter - Storage —
StorageAdapter - Embeddings —
EmbeddingAdapter
Multi-Framework Support
Trayn is designed to work with any browser agent. The @trayn/agent-sdk provides the harness, browser automation, and action execution. The @trayn/memory package provides the learning layer. Bring your own agent — or use the built-in reference agent to get started.
Bring Your Own Agent
The SDK defines an Agent interface — implement it to plug any browser agent into Trayn's training loop. The harness handles the browser, accessibility tree, action execution, and grading; your agent just decides what to do next.
External agents like OpenClaw work out of the box:
Built-in Agent (TraynAgent)
For quick starts, the SDK includes TraynAgent — a reference agent that implements the full observation → reasoning → action loop. It supports models from OpenAI and Google (GPT-4o, Gemini, etc.) and defaults to gpt-4.1-mini:
Memory as a Standalone Package
@trayn/memory can be used independently of @trayn/agent-sdk — integrate Trayn's learning layer into any agent framework:
Use it as a Claude Memory Tool or integrate directly into your agent's retrieval pipeline.
Two Packages
| Package | Purpose |
|---|---|
@trayn/agent-sdk | Agent interface, harness, browser environment, accessibility tree, actions, CLI, grading client, built-in TraynAgent |
@trayn/memory | Memory storage, retrieval, embeddings, grading interface, export formats — works standalone or with any agent framework |
Installing @trayn/agent-sdk pulls in @trayn/memory automatically.
Environment Variables
| Variable | Required For | Description |
|---|---|---|
OPENAI_API_KEY | Built-in TraynAgent | Powers the default agent's reasoning |
GOOGLE_GENERATIVE_AI_API_KEY | Memory embeddings | Generates embedding vectors for memory retrieval |
AWS_ACCESS_KEY_ID | Memory storage | Credentials for persisting memories |
AWS_SECRET_ACCESS_KEY | Memory storage | Credentials for persisting memories |
When using a custom agent, you only need the AI keys for your own model. The OpenAI key is only required for the built-in TraynAgent.