Skip to main content

Overview

The Graph feature in Upsonic allows you to create complex workflows by connecting multiple AI Tasks together. Tasks can be executed sequentially or in parallel, with outputs from one task flowing into subsequent tasks. This enables building sophisticated AI pipelines where each task builds upon the results of previous ones.

Creating a Graph

A Graph is the main structure that manages task execution and workflow. It handles task scheduling, execution order, and state management between tasks.
You can configure a graph with several options:
  • default_agent: The default agent to use for tasks that don’t specify their own
  • parallel_execution: Whether to execute independent tasks in parallel
  • max_parallel_tasks: Maximum number of tasks to execute in parallel (default: 4)
  • show_progress: Whether to display a progress bar during execution (default: True)

Creating Task Nodes

Task nodes are the building blocks of a graph. Each node contains a Task object and connects to other nodes to form a workflow.
Note: Tasks in a graph work exactly the same as regular Tasks in Upsonic. You can provide prompts, tools, and context just as you would with standalone tasks.

Using Direct in Graph

The Direct interface provides a simpler way to interact with AI models without creating a full Agent configuration.
filename

Creating Decision Nodes

Decision nodes allow you to create conditional branches in your graph, enabling dynamic workflows that can take different paths based on the output of previous tasks. Upsonic provides two types of decision nodes:

Decision via Code (DecisionFunc)

The DecisionFunc allows you to use a custom Python function to determine which path to take in your graph based on the output of previous tasks.
In this example, after getting information about a country’s geography, the decision function checks if the word “mountain” appears in the output. If it does, the graph will execute the mountain task; otherwise, it will execute the culture task.

Decision via LLM (DecisionLLM)

The DecisionLLM uses an AI model to make decisions based on the output of previous tasks, allowing for more complex decision-making without writing custom code.
In this example, the LLM will analyze the output from the geography task and determine whether the country has “the biggest trains” based on the content. The decision will then direct the flow to either the mountain task or the culture task. Decision nodes provide powerful flexibility in creating dynamic workflows that can adapt based on the content and context of previous task outputs.

Running a Graph - Detailed

Once you’ve created a graph and added tasks, you can run the graph to execute all tasks in the proper order.
When tasks are executed, outputs from each task are stored in the graph’s state and can be accessed by subsequent tasks. This allows for complex workflows where later tasks build upon the results of earlier ones.