The Problem: Agent Configuration Drift at Runtime
When integrating paperclipai/paperclip into our existing workflow automation platform, we hit a recurring failure mode: agent configurations that passed TypeScript compilation would explode at runtime when provider-specific parameters were missing or malformed. The root cause wasn't paperclipai/paperclip itself—it was our inability to enforce strict type narrowing across provider boundaries in a monorepo context where agent definitions lived in separate packages.
The failure manifested during multi-provider fallback scenarios. When routing through relay gateways like B-Lost ( https://b-lost.com/v1 ) for benchmarking, our agent configs would silently fall back to incorrect defaults because TypeScript couldn't validate provider-specific schema constraints at compile time.
Strict Discriminated Union Pattern
Here's the utility type that eliminated 90% of our runtime agent config errors:
type ProviderConfig < T extends string > = T extends ' openai ' ?…