A plugin for Eliza OS that provides access to Claude 3.7's thinking capabilities. This plugin enables agents to perform deep analysis and reasoning using Claude's "thinking" feature.
The thinking plugin adds a new action to your agent that allows it to send prompts to Claude 3.7 with thinking enabled. This provides:
- Access to Claude's detailed reasoning process
- Deep analysis on complex questions
- Step-by-step problem solving
- More thoughtful and thorough responses
pnpm add @elizaos/plugin-thinkingThe plugin requires an Anthropic API key. Configure it in your .env:
ANTHROPIC_API_KEY=your_api_key_here
ANTHROPIC_BASE_URL=https://api.anthropic.com/v1 # Optional, defaults to this value
Register the plugin with your agent:
import { thinkingPlugin } from '@elizaos/plugin-thinking';
// In your agent setup
const runtime = new AgentRuntime({
// ...other config
plugins: [thinkingPlugin]
});The plugin provides a thinking action that can be called directly:
// Find the thinking action
const thinkingAction = runtime.actions.find(action => action.name === 'thinking');
// Create a memory with your prompt
const prompt = {
content: {
text: "Analyze the pros and cons of quantum computing for cryptography."
}
};
// Call the thinking action
const response = await thinkingAction.handler(runtime, prompt);
// Process the response
console.log(response.content);You can create a provider that leverages the thinking action:
import { Provider, IAgentRuntime, Memory, State } from '@elizaos/core';
import { ThinkingResponse } from '@elizaos/plugin-thinking/src/types';
export const analysisProvider: Provider = {
get: async (runtime: IAgentRuntime, message: Memory, state?: State) => {
try {
// Find the thinking action
const thinkingAction = runtime.actions.find(action => action.name === 'thinking');
if (!thinkingAction) {
console.error('Thinking action not found');
return null;
}
// Create a custom prompt
const customPrompt = {
content: {
text: `Analyze deeply: ${message.content.text}`
}
};
// Call the thinking action
const response = await thinkingAction.handler(runtime, customPrompt, state);
// Extract thinking blocks and text blocks
const thinkingResponse = response as ThinkingResponse;
const thinkingBlocks = thinkingResponse.content.filter(block => block.type === 'thinking');
const textBlocks = thinkingResponse.content.filter(block => block.type === 'text');
// Return processed results to be used in context
return {
analysis: {
reasoning: thinkingBlocks.length > 0 ? thinkingBlocks[0].thinking : '',
conclusion: textBlocks.length > 0 ? textBlocks[0].text : ''
}
};
} catch (error) {
console.error('Error in analysis provider:', error);
return null;
}
}
};The thinking action returns a ThinkingResponse with this structure:
interface ThinkingResponse {
content: (ThinkingBlock | TextBlock)[];
}
interface ThinkingBlock {
type: "thinking";
thinking: string;
}
interface TextBlock {
type: "text";
text: string;
}The plugin uses these defaults:
- Model:
claude-3-7-sonnet-20250219 - Max tokens: 21000
- Thinking budget: 16000
// In a provider or action
const thinkingAction = runtime.actions.find(action => action.name === 'thinking');
const result = await thinkingAction.handler(runtime, {
content: { text: "What are the ethical implications of AI?" }
});
// Access Claude's thinking process
const thinking = result.content.find(block => block.type === "thinking")?.thinking;
// Access Claude's final answer
const answer = result.content.find(block => block.type === "text")?.text;Contributions are welcome! Please feel free to submit a Pull Request.