Anthropic
KaibanJS seamlessly integrates with Anthropic's powerful language models, allowing you to leverage advanced AI capabilities in your applications. This integration supports various Anthropic models, including Claude 3 Opus, Claude 3 Sonnet, and Claude 3 Haiku.
Supported Models
KaibanJS supports all of Anthropic's chat models available through the Anthropic API. These models are designed for natural language conversations and are ideal for a wide range of applications. The list of supported models is dynamic and may change as Anthropic introduces new models or retires older ones.
Here are some examples of popular Anthropic models:
- claude-3-5-sonnet-20240620
- claude-3-opus-20240229
- claude-3-haiku-20240307
For a comprehensive list of available models and their capabilities, please refer to the official Anthropic documentation.
Configuration
To use an Anthropic model in your KaibanJS agent, configure the llmConfig
property as follows:
const agent = new Agent({
name: 'Anthropic Agent',
role: 'Assistant',
llmConfig: {
provider: 'anthropic',
model: 'claude-3-5-sonnet-20240620', // or any other Anthropic model
apiKey: 'your-api-key-here'
}
});
API Key Setup
To use Anthropic models, you need to provide an API key. There are two recommended ways to do this:
- Agent Configuration: Specify the API key in the
llmConfig
when creating an agent:
const agent = new Agent({
name: 'Anthropic Agent',
role: 'Assistant',
llmConfig: {
provider: 'anthropic',
model: 'claude-3-opus-20240229',
apiKey: 'your-api-key-here'
}
});
- Team Configuration: Provide the API key in the
env
property when creating a team:
const team = new Team({
name: 'Anthropic Team',
agents: [agent],
env: {
ANTHROPIC_API_KEY: 'your-api-key-here'
}
});
When using Anthropic's API directly in browser environments with KaibanJS versions prior to v0.20.0, you may encounter CORS errors. This issue has been resolved in KaibanJS v0.20.0 and later versions through the integration of the latest @langchain/anthropic package.
If you're using an older version of KaibanJS, you have two options to resolve CORS issues:
-
Upgrade to KaibanJS v0.20.0 or later: This is the recommended solution as it includes the latest @langchain/anthropic package with built-in CORS handling.
-
Use the Kaiban LLM Proxy: For older versions, you can deploy our ready-to-use proxy solution:
- Fork and deploy kaiban-llm-proxy
- Add the proxy URL to your agent configuration using
apiBaseUrl
Example with proxy (for older versions):
const agent = new Agent({
name: 'Anthropic Agent',
role: 'Assistant',
llmConfig: {
provider: 'anthropic',
model: 'claude-3-5-sonnet-20240620',
apiKey: 'your-api-key-here',
apiBaseUrl: 'https://your-proxy-url.com/proxy/anthropic'
}
});
Always use environment variables for API keys instead of hardcoding them. This enhances security and simplifies key management across different environments.
Example:
apiKey: process.env.YOUR_API_KEY;
Never commit API keys to version control. Use a .env
file or a secure secrets management system for sensitive information.
Please refer to API Keys Management to learn more about handling API Keys safely.
Advanced Configuration and Langchain Compatibility
KaibanJS uses Langchain under the hood, which means we're compatible with all the parameters that Langchain's Anthropic integration supports. This provides you with extensive flexibility in configuring your language models.
For more control over the model's behavior, you can pass additional parameters in the llmConfig
. These parameters correspond to those supported by Langchain's Anthropic integration.
Here's an example of how to use advanced configuration options:
const agent = new Agent({
name: 'Advanced Anthropic Agent',
role: 'Assistant',
llmConfig: {
provider: 'anthropic',
model: 'claude-3-opus-20240229',
temperature: 0.7,
maxTokens: 1000
// Any other Langchain-supported parameters...
}
});
For a comprehensive list of available parameters and advanced configuration options, please refer to the official Langchain documentation:
Langchain Anthropic Integration Documentation
Best Practices
- Model Selection: Choose the appropriate model based on your task complexity and required capabilities. For example, use Claude 3 Opus for complex tasks, Claude 3 Sonnet for a balance of performance and efficiency, and Claude 3 Haiku for faster, simpler tasks.
- Cost Management: Be mindful of token usage, especially with more powerful models like Claude 3 Opus.
- Error Handling: Implement proper error handling to manage API rate limits and other potential issues.
Limitations
- Token limits vary by model. Ensure your inputs don't exceed these limits.
- Costs can accumulate quickly with heavy usage. Monitor your usage closely.
Further Resources
Is there something unclear or quirky in the docs? Maybe you have a suggestion or spotted an issue? Help us refine and enhance our documentation by submitting an issue on GitHub. We're all ears!