Please note:this document is a work in progress.

Core Kit

This is the kit that provides the most fundamental building blocks for Breadboard and contains the following nodes:

append

Use this node to accumulate local state, like context in a prompt.

The node looks for property called accumulator in its input. All other properties are appended to this property, and returned as accumulator output property.

The way the properties are appended depends on the type of the accumulator input property.

If the accumulator property is "string-ey" (that is, it's a string, number, boolean, bigint, null or undefined), the properties will be appended as strings, formatted as : and joined with "\n".

If the accumulator property is an array, the properties will be appended as array items, formatted as : ,

Otherwise, the accumulator property will be treated as an object and the properties will be added as properties on this object.

Example

If we send the append node an input of Question with the value of How old is planet Earth? and the accumulator value of \n:

{
  "accumulator": "\n",
  "Question": "How old is planet Earth?"
}

We will see the following output:

{
  "accumulator": "\n\nQuestion: How old is planet Earth?"
}

If we send the node an input of Question with the value of How old is planet Earth? and the accumulator value of []:

{
  "accumulator": [],
  "Question": "How old is planet Earth?"
}

We will get the output:

{
  "accumulator": ["Question: How old is planet Earth?"]
}

If we send the node an input of Question with the value of How old is planet Earth? and the accumulator value of {}:

{
  "accumulator": {},
  "Question": "How old is planet Earth?"
}

We'll get the output of:

{
  "accumulator": {
    "Question": "How old is planet Earth?"
  }
}

Implementation

fetch

Use this node to fetch data from the Internet. Practically, this is a wrapper around fetch

Example

If we would like to fetch data from https://example.com, we would send the following inputs to fetch:

{
  "url": "https://example.com"
}

And receive this output:

{
  "response": "<response from https://example.com>"
}

Inputs

Outputs

Implementation

runJavascript

Use this node to execute JavaScript code. The node recognizes a required code input property, which is a string that contains the code to be executed. It also recognizes a name input property, which is a string that specifies the name of the function that will be invoked to execute the code. If not supplied, the run function name will be used.

All other input properties will be passed as arguments to the function.

The code is executed in a new V8 context in Node or a Web Worker in the browser, which means that it cannot access any variables or functions from the outside.

The node will pass the result of the execution as the result output property.

Example:

If we send the following inputs to runJavascript:

{
  "code": "function run() { return 1 + 1; }"
}

We will get this output:

{
  "result": 2
}

If we send:

{
  "code": "function run({ what }) { return `hello ${what}`; }",
  "what": "world"
}

We will get:

{
  "result": "hello world"
}

Inputs

Outputs

Implementation

secrets

Use this node to access secrets, such as API keys or other valuable bits of information that you might not want to store in the graph itself. The node takes in an array of strings named keys, matches the process environment values, and returns them as outputs. This enables connecting edges from environment variables.

Example

Use this node to pass the PALM_KEY environment variable to the text-completion node. The input:

{
  "keys": ["PALM_KEY"]
}

Will produce this output:

{
  "PALM_KEY": "<value of the API key from the environment>"
}

Inputs

Outputs

Implementation

passthrough

This is a no-op node. It takes the input property bag and passes it along as output, unmodified. This node can be useful when the board needs an entry point, but the rest of the board forms a cycle.

Example

board.input().wire("say->", board.passthrough().wire("say->", board.output()));

board.runOnce({
  say: "Hello, world!",
});

console.log("result", result);

Will produce this output:

result { say: 'Hello, world!' }

See Chapter 9: Let's build a chatbot of Breadboard tutorial to see another example of usage.

Inputs

Outputs

Implementation

invoke

Use this node to invoke another board from this board.

It recognizes path, graph, and board properties that specify, respectively, a file path or URL to the serialized board, directly the serialized-as-JSON board, and a BoardCapability (returned by lambda or import).

The rest of the inputs in the property bag are passed along to the invoked board as its inputs. If other inputs were bound to the board via wires into the lambda or import node, then those have precedence over inputs passed here.

The outputs of the invoked board will be passed along as outputs of the invoke node.

Inputs

Outputs

Implementation

import

Creates a lambda board from a pre-existing board, either loaded from path or passed as JSON via graph. All other inputs are bound to the board, which is returned as board.

Inputs

Outputs

Implementation

reflect

This node is used to reflect the board itself. It has no required inputs and provides a JSON representation of the board as a graph output property. This node can be used for getting information that might be stored in the structure of the board.

Example

import { Board } from "@google-labs/breadboard";

const board = new Board();

board.input().wire("", board.reflect().wire("graph->", board.output()));

const result = await board.runOnce({});
console.log("result", result);

will print:

result {
  graph: {
    edges: [ [Object], [Object] ],
    nodes: [ [Object], [Object], [Object] ],
    kits: []
  }
}

Inputs

Outputs

Implementation