Building Smart Workflows: How to Connect Cross-Project Intelligence to Dynamic Pipelines
Learn how we integrated a consolidation system with a dynamic workflow builder to transform generic templates into intelligent, data-driven pipelines that learn from past projects.
Building Smart Workflows: How to Connect Cross-Project Intelligence to Dynamic Pipelines
Ever built a workflow system that felt... dumb? You know the feeling—you've got these beautiful, dynamic pipelines that can execute complex multi-step processes, but they're essentially starting from scratch every time. What if your workflows could actually learn from previous projects and apply that wisdom automatically?
That's exactly the challenge we tackled in our latest development session. We had a powerful workflow builder with a "Project Wisdom" step that was essentially synthesizing insights from thin air. Time to make it smarter.
The Challenge: From Generic to Intelligent
Our workflow system had a template called the "Deep Build Pipeline"—a 9-step process that takes projects from idea to implementation. The problem was in step 7, "Project Wisdom." Instead of drawing from real cross-project patterns and lessons learned, it was generating generic advice.
We needed to bridge two systems:
- A consolidation system that analyzes completed projects and extracts patterns
- A workflow builder that executes dynamic, multi-step processes
The goal? Make workflows that actually get smarter over time.
The Architecture: Linking Intelligence to Execution
Database Schema Evolution
First, we needed to create the relationship between workflows and consolidations. A simple but powerful addition to our Prisma schema:
model Workflow {
// ... existing fields
consolidationIds String[] @db.Uuid
}
This array of UUIDs lets each workflow reference multiple consolidation reports, giving it access to cross-project intelligence.
The Template Variable System
The magic happens through a template variable system. Instead of hardcoded prompts, our workflow engine now resolves variables at runtime:
// In workflow-engine.ts
const resolvePrompt = (template: string, context: ChainContext): string => {
return template
.replace(/\{\{projectName\}\}/g, context.projectName || 'Untitled Project')
.replace(/\{\{consolidations\}\}/g, context.consolidationContent || '[No consolidations linked]')
// ... other variables
}
When a workflow step includes {{consolidations}} in its prompt, the engine automatically injects relevant patterns and insights from linked consolidation reports.
Smart Content Loading
The real intelligence comes from how we load and format consolidation data:
const loadConsolidationContent = async (consolidationIds: string[]): Promise<string> => {
if (!consolidationIds.length) return '[No consolidations linked to this workflow]'
const consolidations = await prisma.consolidation.findMany({
where: {
id: { in: consolidationIds },
status: 'completed'
}
})
// Transform raw data into actionable prompt hints
return consolidations
.map(c => generatePromptHints(c))
.join('\n\n---\n\n')
}
This function fetches completed consolidations and runs them through a generatePromptHints() function that transforms raw project data into actionable insights for the AI.
The User Experience: Seamless Intelligence Selection
Consolidation Picker
When creating a new workflow, users now see a consolidation picker that shows only completed analyses:
// Query completed consolidations
const { data: consolidations } = trpc.consolidation.list.useQuery({
status: "completed"
})
// Render as selectable options
{consolidations?.map(consolidation => (
<div key={consolidation.id} className="flex items-center space-x-2">
<input
type="checkbox"
checked={consolidationIds.includes(consolidation.id)}
onChange={/* toggle selection */}
/>
<span>{consolidation.name} ({consolidation.projectCount} projects)</span>
</div>
))}
Visual Integration
On the workflow execution page, linked consolidations appear as clickable badges in the settings panel, making it easy to reference the source intelligence:
{workflow.consolidationIds.map(id => (
<Link
href={`/dashboard/consolidation/${id}`}
className="inline-flex items-center px-2 py-1 rounded-md bg-accent"
>
Consolidation
</Link>
))}
The Transformed Workflow Template
Here's how the "Project Wisdom" step evolved. Before:
Generate insights and lessons learned for this project...
After:
Based on the consolidation intelligence below, identify specific lessons
and patterns that apply to {{projectName}}:
{{consolidations}}
Focus on actionable insights that can improve this specific project.
Include a "Lessons Applied" section showing how you're incorporating
the cross-project patterns.
Now when the workflow runs, {{consolidations}} gets replaced with actual insights from previous projects, making the wisdom step genuinely intelligent.
Lessons Learned: The Technical Gotchas
Database Migrations with Existing Data
Adding new columns to tables with existing rows requires careful consideration. We made consolidationIds optional and provided a default empty array to avoid migration issues.
Type Safety in Template Variables
The template variable system needed robust type checking. We created a ChainContext interface that explicitly defines what data is available to each workflow step:
interface ChainContext {
projectName?: string
consolidationContent?: string
previousStepOutputs: Record<string, string>
// ... other context
}
Performance Considerations
Loading consolidation content for every workflow step would be inefficient. Instead, we load it once when the workflow starts and include it in the chain context, making it available to any step that needs it.
The Result: Workflows That Actually Learn
The integration is now complete and type-safe. When you create a workflow with the Deep Build Pipeline template and link it to consolidation reports, the "Project Wisdom" step automatically incorporates lessons learned from previous projects.
Instead of generic advice, you get specific, actionable insights based on real project patterns. The workflow system has evolved from a simple execution engine to an intelligent pipeline that gets smarter with every project you complete.
What's Next?
The immediate next steps involve testing the full integration and improving the user experience. We're considering adding consolidation names (not just IDs) to the execution page display, and potentially creating a getMany endpoint to efficiently resolve consolidation metadata.
But the bigger picture is exciting: we've created a foundation for workflows that truly learn and improve over time. Each completed project feeds back into the system, making future workflows more intelligent and effective.
The dream of self-improving development pipelines is becoming reality, one template variable at a time.