Skip to content

Eliza plugin that enables Claude thinking models to be called as an action.

Notifications You must be signed in to change notification settings

confluent-1/plugin-thinking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@elizaos/plugin-thinking

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.

Overview

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

Installation

pnpm add @elizaos/plugin-thinking

Configuration

The 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

Usage

Registering the Plugin

Register the plugin with your agent:

import { thinkingPlugin } from '@elizaos/plugin-thinking';

// In your agent setup
const runtime = new AgentRuntime({
  // ...other config
  plugins: [thinkingPlugin]
});

Using the Thinking Action Directly

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);

Creating a Provider That Uses Thinking

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;
    }
  }
};

Response Format

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;
}

Default Configuration

The plugin uses these defaults:

  • Model: claude-3-7-sonnet-20250219
  • Max tokens: 21000
  • Thinking budget: 16000

Examples

Basic Usage

// 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;

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

About

Eliza plugin that enables Claude thinking models to be called as an action.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published