Overview
There are two primary steps in setting up your experience using Inworld Graphs:- Graph Creation: Creating a graph, adding nodes, connecting them with edges, defining start/end points, and building the graph
- Graph Execution: Process your data by providing input to the graph and capturing the results from your target nodes
Graph Creation
Basic Graph
The simplest form of a graph is a single node graph that consists of:- creating a node
- creating a graph builder
- adding the node to the graph
- defining that node as the start and end points for execution
- building the graph
Multi-Node Graph
Most graphs will consist of multiple nodes that can power more advanced functionality. The below example shows how to create a graph that outputs the LLM response as audio, using TTS.Graph with Multiple Start Nodes
Graphs require at least one start node and end node, but they can also have multiple start or end nodes. You can define this withsetStartNodes() and setEndNodes().
Graph Datastore
The datastore is a key-value storage mechanism that allows you to pass additional data across nodes in a graph execution. You can access the datastore throughProcessContext in any custom node’s process() method, and use add() to store data and get() to retrieve it.
See this guide on using context for an example of how to use the datastore.
Graph Execution
After a graph has been created, it needs to be executed by providing input data and handling the results. The execution returns a stream that allows you to process the output from the graph.v0.8 Breaking Change:
graph.start() is now async and must be awaited. Additionally, you should call stopInworldRuntime() for proper cleanup when your application terminates.Execution Result
Thestart() method returns an ExecutionResult object with the following properties:
variantName- The variant of the graph that was executed (default:"__default__")outputStream- The output stream for processing resultsexecutionId- Unique identifier for this execution