Best Practices

Essential best practices for building robust applications with FMP Tools.

Overview

Follow these best practices to build reliable, performant, and user-friendly applications with FMP Tools.

Tool Selection

Choose Only What You Need

Import only the tools you need to reduce bundle size and improve performance:

TypeScriptTypeScript

Combine tools that work well together:

TypeScriptTypeScript

Rate Limiting

Set Appropriate Limits

Use maxSteps or stopWhen to prevent excessive API calls:

app/api/chat/route.tsTypeScript

Implement Caching

Cache frequently requested data to reduce API calls:

TypeScriptTypeScript

Error Handling

Always Implement Error Boundaries

Wrap your chat components with error boundaries:

TypeScriptTypeScript

Provide User-Friendly Messages

Show clear, actionable error messages:

TypeScriptTypeScript

User Experience

Loading States

Always show loading indicators during tool execution:

TypeScriptTypeScript

Clear Feedback

Let users know when tools are being used:

TypeScriptTypeScript

Performance Optimization

Lazy Load Tools

Load tools only when needed:

TypeScriptTypeScript

Optimize Model Configuration

Use appropriate model settings:

app/api/chat/route.tsTypeScript

Security

Validate Inputs

Always validate user inputs before passing to tools:

TypeScriptTypeScript

Secure API Keys

Never expose API keys in client-side code:

.env.localbash

Monitoring and Debugging

Log Tool Usage

Track which tools are being used:

.env.localbash

Monitor Error Rates

Track errors to identify issues:

TypeScriptTypeScript

Summary

  1. Choose the right tools for your use case
  2. Implement proper rate limiting to avoid API limits
  3. Handle errors gracefully with user-friendly messages
  4. Optimize for performance with caching and lazy loading
  5. Monitor your application to identify issues early
  6. Test thoroughly before deploying to production

Next Steps