Getting Started
Get Started with R-Think
This guide walks you through installing R-Think, creating a project, and executing your first structured reasoning flow.
Prerequisites
- Node.js 18.0 or higher
- npm 9.0 or higher
- TypeScript 5.0 or higher (recommended)
Installation
Install R-Think using npm. The runtime package includes the core engine, protocol definitions, and validation rules.
Terminal bash
npm install @r-think/core Version Note
R-Think follows semantic versioning. Check the Download page for the latest stable version.
Create Project
Create a new project directory and initialize your reasoning flow.
Terminal bash
mkdir my-rthink-project
cd my-rthink-project
npm init -y Hello World
Create your first reasoning flow. This example demonstrates a simple sequential protocol with validation rules.
hello-world.ts typescript
import { Runtime, Protocol, Rule } from '@r-think/core';
const runtime = Runtime.create({
id: 'hello-world',
protocol: Protocol.sequential,
rules: [
Rule.required('message'),
Rule.type('message', 'string')
]
});
const result = await runtime.execute({
message: 'Hello, R-Think'
});
console.log(result.output); // { message: 'Hello, R-Think' }
console.log(result.trace); // Full reasoning trace
console.log(result.validated); // true Validation
Rules validate inputs, outputs, and state transitions. Invalid data is rejected before reasoning proceeds.
validation.ts typescript
const runtime = Runtime.create({
id: 'validated-flow',
protocol: Protocol.sequential,
rules: [
Rule.required('input'),
Rule.bounded('score', 0, 100),
Rule.matches('email', /^[^\s@]+@[^\s@]+\.[^\s@]+$/),
Rule.enum('status', ['pending', 'approved', 'rejected'])
]
});
// Invalid: score out of bounds
try {
await runtime.execute({ score: 150 });
} catch (error) {
console.log(error.message); // Rule violated: score must be between 0 and 100
} Tip
Define rules close to the protocol definition. This makes validation requirements explicit and maintainable.
Next Step
You have successfully installed R-Think and executed your first reasoning flow. Continue learning with the documentation.