Skip to main content

Installation

StateGraph is included in Upsonic. Make sure you have it installed:

Your First Graph

Let’s build a simple conversational AI that processes user messages.

Step 1: Define Your State

States are typed dictionaries that flow through your graph:

Step 2: Create Node Functions

Nodes are functions that process state and return updates:

Step 3: Build the Graph

Connect your nodes with edges:
START and END are special constants representing the entry and exit points of your graph.

Step 4: Execute the Graph

Now invoke your graph with initial state:

Complete Example

Here’s the full code in one place:

Adding Conditional Logic

Let’s extend our graph to route based on user intent:
Command allows nodes to both update state and specify where to go next.

What’s Next?

Now that you’ve built your first graph, explore more advanced features: