Nodes and Bundles
Learn about Trace2's core primitives for building optimizable systems
Nodes and Bundles
Trace2 has two fundamental primitives: node and bundle.
Nodes
A node wraps any Python value and tracks operations on it.
Creating Nodes
from opto.trace import node
x = node(1, trainable=True)
y = node(3)
z = x / yTrainable Nodes
Node Operations
[Add explanation of automatic tracing]
Bundles
A bundle wraps a Python function, making it optimizable.
Creating Bundles
from opto.trace import bundle
@bundle(trainable=True)
def my_function(x):
"""This function can be optimized by Trace2."""
return x * 2Trainable Functions
The Model Decorator
For complex agents, use @trace.model:
from opto import trace
@trace.model
class Agent:
def __init__(self, system_prompt):
self.system_prompt = system_prompt
self.instruction = trace.node("Be helpful", trainable=True)
def __call__(self, user_input):
return trace.operators.call_llm(self.system_prompt, self.instruction, user_input)