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
Computation Graph
How Trace2 captures and represents AI system execution
Nodes and Bundles
The fundamental primitives for building optimizable systems
Trainable Parameters
Defining what can be optimized in your AI system
Feedback Functions
Using feedback to guide optimization
The Big Picture
Think of Trace2 as PyTorch for AI agents:
| PyTorch | Trace2 |
|---|---|
| Neural networks | AI agent workflows |
| Tensors | Python objects (any type) |
| Forward pass | Agent execution |
| Loss function | Feedback function |
| Gradients | Natural language feedback |
| Backward pass | Feedback propagation through graph |
| Weight updates | Code/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:
- Start: Computation Graph - Understand how Trace2 tracks execution
- Build: Nodes and Bundles - Learn to define optimizable components
- Configure: Trainable Parameters - Mark what should be optimized
- Guide: Feedback Functions - Direct the optimization process
Advanced Topics
Once you understand the basics:
- Explore different Optimizers
- Read Best Practices
- Study Examples
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