UI Registry (Assistant.js)
The registry object from ./Assistant.js provides methods for creating interactive tools and dynamic instructions that the AI assistant can use to interact with your HTML interface in User Interface assets.
Basic Tool Registration
Use registry.addTool() to create tools that the AI assistant can invoke to interact with your UI:
Tool Configuration Options
Each tool requires the following configuration:
- toolName (string, required): Unique identifier for the tool
- description (string, required): Clear description of the tool’s purpose and functionality
- parameters (object, required): JSON Schema defining the tool’s input parameters
- Use
type: "object"withpropertiesto define parameter structure - Include
requiredarray for mandatory parameters - Use appropriate types:
"string","number","boolean","array","object" - Add
enumarrays for restricted value sets
- Use
- execute (function, required): Async function that implements the tool logic
- Receives the parameters as the first argument
- Should return an object with results or error information
- Can interact with DOM elements, make API calls, or perform other operations
Dynamic Instructions with addInstruction
In addition to tools, the registry supports adding dynamically updatable instructions to the model context using addInstruction. Use this to stream concise, structured state into the assistant’s system prompt.
Best Practices for Instructions
- Prefer compact JSON strings so the model can easily parse state
- Update only when underlying state changes to avoid noise
- Use one instruction per cohesive state domain (e.g., BMI widget state)
- Keep tool descriptions short; let instructions carry dynamic state that tools manipulate
Tool Design Best Practices
- Clear Tool Names: Use descriptive, action-oriented names (e.g.,
"updateField","submitForm","toggleVisibility") - Comprehensive Descriptions: Explain what the tool does and when to use it
- Proper Parameter Validation: Use JSON Schema to define clear parameter requirements
- Error Handling: Return meaningful error messages when operations fail
- Consistent Return Format: Always return objects with success/error indicators
- DOM Safety: Check for element existence before manipulation
- User Feedback: Provide visual feedback for user actions when appropriate
Return Format Guidelines
Tools should return objects that indicate success or failure:
- Success:
{ success: true, result: data }or{ success: true, data: formData } - Error:
{ success: false, error: "Error message" } - Include relevant data in the response that the AI assistant can use
Form-Based Interface Guidelines
When creating form-based interfaces:
- Use semantic HTML with proper
idattributes for form elements - Create tools for both individual field updates and form submission
- Provide validation and user feedback mechanisms
- Consider accessibility and user experience in tool design
