BRK: BRX Knowledge Representations

BRKs (BRX Knowledge Representations) are the fundamental building blocks of the BRX platform. They represent reusable AI components that can be composed together to build complex applications.

What is a BRK?

A BRK is a prompt with the ability to include variables and other BRKs as dependencies with recursion. Think of it as a function in programming - it takes inputs, processes them, and produces outputs. However, instead of executing code, a BRK processes natural language and interacts with LLMs.

Key characteristics of BRKs:

  • Reusable: Create once, use anywhere
  • Composable: BRKs can include other BRKs as dependencies
  • Parameterized: Accept input variables that can be customized at runtime
  • Versioned: Track changes and maintain compatibility
  • Shareable: Can be shared with other users and teams

BRK Structure

A BRK consists of:

  • BRX ID: A unique identifier for the BRK
  • Name: A human-readable name
  • Description: A description of what the BRK does
  • Input Fields: Variables that can be provided at runtime
  • Prompt: The template that will be sent to the LLM
  • Dependencies: Other BRKs that this BRK depends on
  • Process Parameters: Configuration for how the BRK should be executed

Creating a BRK

BRKs can be created through the BRX platform UI or programmatically using the BRX API. Here’s an example of creating a BRK using the Node.js SDK:

import BRX, { BRK } from 'brx-node';

// Initialize the BRX client
const brx = new BRX('your-api-key');

// Create a new BRK
const modifyRequest = {
  modifyBrxMode: 'CREATE',
  brx: {
    brxId: 'unique-brx-id',
    brxName: 'My First BRK',
    description: 'A simple BRK that does something useful',
    prompt: {
      prompt: new Map([
        ['main', 'This is the main prompt template with {{variable}}']
      ])
    },
    processParams: {
      processType: 0 // Standard processing
    },
    dependantBrxIds: new Map([
      ['main_brx_entry_schema', 'unique-brx-id']
    ])
  },
  schema: {
    schemaFields: new Map([
      ['variable', {
        fieldValueDataType: 'string',
        fieldValue: ''
      }]
    ]),
    brxName: 'My First BRK',
    brxId: 'unique-brx-id'
  }
};

// Send the create request
const result = await brx.create(modifyRequest);

Using a BRK

Once a BRK is created, you can use it by fetching its schema and providing input values:

import BRX, { BRK } from 'brx-node';

const brx = new BRX('your-api-key');

// Fetch the BRK Schema with a BRK ID
const myBrkSchema = await brx.get('unique-brx-id');

// Initialize the BRK using the schema
const myBrk = new BRK(myBrkSchema);

// Add inputs
myBrk.input['variable'] = 'Some input value';

// Run the BRK
const result = await brx.run(myBrk);
console.log(result);

BRK Dependencies

One of the most powerful features of BRKs is the ability to include other BRKs as dependencies. This allows you to build complex AI applications by composing simpler components.

For example, you might have:

  1. A BRK that extracts key information from a text
  2. A BRK that summarizes information
  3. A BRK that formats the summary in a specific way

You can compose these together by making the summarization BRK depend on the extraction BRK, and the formatting BRK depend on the summarization BRK.

When you run the formatting BRK, it will automatically run the summarization BRK, which will in turn run the extraction BRK. The output of each BRK is passed to the next one in the chain.

Best Practices

  • Keep BRKs focused: Each BRK should do one thing well
  • Use descriptive names: Make it clear what each BRK does
  • Document inputs and outputs: Clearly describe what each input field expects and what the output will be
  • Test thoroughly: Ensure your BRKs work as expected with various inputs
  • Version control: Keep track of changes to your BRKs