-
Notifications
You must be signed in to change notification settings - Fork 64
feat: Add auto-fill for missing dynamic variables #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add auto-fill for missing dynamic variables #360
Conversation
Add support for automatically filling missing dynamic variables with default values
to avoid errors when agent tools require variables that aren't always available.
Features:
- New expectedDynamicVariables config option to list all variables the agent expects
- New missingDynamicVariableDefault config option to set default value for missing variables
- Supports null, string, number, and boolean default values
- Works across all SDKs: client, react, react-native, and widget
This solves the issue where conversations fail with errors like:
Missing required dynamic variables in tools: {var1, var2, ...}
Usage example:
conversation.startSession({
agentId: 'your-agent-id',
dynamicVariables: { clients: 'Client A' },
expectedDynamicVariables: ['clients', 'matters', 'history'],
missingDynamicVariableDefault: null
});
DYNAMIC_VARIABLES_GUIDE.md
Outdated
| @@ -0,0 +1,311 @@ | |||
| # Dynamic Variables Auto-Fill Feature | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Could the explanation on how to use this be put in each package's respective README file instead please?
| "clean": "turbo clean" | ||
| }, | ||
| "devDependencies": { | ||
| "turbo": "2.5.6", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please undo the changes to this file, we don't want to add dependencies or reorder them.
… package.json - Remove DYNAMIC_VARIABLES_GUIDE.md - Add dynamic variables documentation to each package's README: - packages/client/README.md - packages/react/README.md - packages/react-native/README.md - Main README.md (for widgets) - Revert changes to package.json and pnpm-lock.yaml
This is a pnpm project, so package-lock.json (npm's lock file) should not be tracked. Only pnpm-lock.yaml should be used.
|
Thank you very much for the review @PaulAsjes! I have addressed both of your feedback points:
I also removed The PR should be ready for re-review now. Let me know if there's anything else you'd like me to adjust! |
|
Thanks for the effort put in here! Spoke with the team about this and we've decided to not merge this PR. The idea that all dynamic variables should be defined before a conversation can start was made a long time ago, way before users had the ability to update variables mid-call (e.g. tool assignments). We might revisit that decision in the future as the frustration you encounter is valid. That being said, this needs to be resolved properly on the server side rather than the client. I don't think this PR fixes the described issue of
because it still relies on listing all dynamic variables that are used, directly in the client. If the agent configuration is changed to introduce a new dynamic variable, it will still break existing clients. We're tracking this issue internally and will look into properly fixing it on the server. |
|
Thank you very much @PaulAsjes, if you have any news of this changing in the future please let me know. |
Problem
When an ElevenLabs agent has tools configured with dynamic variable references, the server validates that all referenced dynamic variables are provided during conversation initiation. If any are missing, the conversation fails with an error like:
This creates problems when:
Solution
This PR adds auto-fill functionality for missing dynamic variables. Developers can now:
Changes
New Configuration Options
expectedDynamicVariables?: string[]List of all dynamic variable names that your agent's tools expect.
missingDynamicVariableDefault?: string | number | boolean | nullDefault value to use for any missing variables (defaults to
null).Usage Example
Before (would fail):
After (works!):
Web Widget Example
Benefits
✅ Prevents conversation failures due to missing dynamic variables
✅ Backward compatible - existing code works without changes
✅ Works across all SDKs - client, react, react-native, and widget
✅ Flexible defaults - supports null, strings, numbers, and booleans
✅ Developer-friendly - clear documentation and TypeScript types
✅ Decouples frontend from backend - frontend doesn't need to know all agent variables upfront
Files Changed
Client SDK
packages/client/src/utils/BaseConnection.ts- Added type definitionspackages/client/src/utils/overrides.ts- Implemented auto-fill logicReact Native SDK
packages/react-native/src/types.ts- Added type definitionspackages/react-native/src/utils/overrides.ts- Implemented auto-fill logicpackages/react-native/src/hooks/useConversationSession.ts- State managementpackages/react-native/src/ElevenLabsProvider.tsx- IntegrationWidget SDK
packages/convai-widget-core/src/types/attributes.ts- Added HTML attributespackages/convai-widget-core/src/contexts/session-config.tsx- Attribute parsingDocumentation
DYNAMIC_VARIABLES_GUIDE.md- Comprehensive usage guideTesting
Documentation
Comprehensive guide added at
DYNAMIC_VARIABLES_GUIDE.mdwith: