Trace2

Core Concepts

Understanding the fundamental concepts of Trace2

Core Concepts

Learn the fundamental concepts that power Trace2's optimization framework.

Overview

Trace2 brings AutoDiff-like optimization to AI systems. Instead of backpropagating numerical gradients through neural networks, Trace2 backpropagates feedback through computation graphs of AI agent execution.

Key Concepts

The Big Picture

Think of Trace2 as PyTorch for AI agents:

PyTorchTrace2
Neural networksAI agent workflows
TensorsPython objects (any type)
Forward passAgent execution
Loss functionFeedback function
GradientsNatural language feedback
Backward passFeedback propagation through graph
Weight updatesCode/prompt updates

Quick Example

Here's how the concepts work together:

from opto.trace import node, bundle
from opto.optimizers import OptoPrime

# 1. Define trainable parameters (like nn.Parameter)
@bundle(trainable=True)
def agent_function(input):
    """This can be optimized."""
    return "Process: " + input

# 2. Execute (forward pass)
output = agent_function("user request")

# 3. Get feedback (like computing loss)
feedback = "Make it more concise and professional"

# 4. Optimize (backward pass + optimizer step)
optimizer = OptoPrime(agent_function.parameters())
optimizer.zero_feedback()
optimizer.backward(output, feedback)
optimizer.step()

# 5. New behavior learned!
new_output = agent_function("user request")

Learning Path

We recommend learning these concepts in order:

  1. Start: Computation Graph - Understand how Trace2 tracks execution
  2. Build: Nodes and Bundles - Learn to define optimizable components
  3. Configure: Trainable Parameters - Mark what should be optimized
  4. Guide: Feedback Functions - Direct the optimization process

Advanced Topics

Once you understand the basics:

Why These Concepts Matter

Understanding these core concepts will help you:

  • ✅ Design effective AI systems
  • ✅ Debug optimization issues
  • ✅ Choose the right optimizer
  • ✅ Write better feedback functions
  • ✅ Build complex multi-agent systems

Next Steps