Anthemic

Gem Version Build Status License: MIT

Anthemic is a Ruby framework for building agentic AI applications with large language models. It provides a flexible and extensible way to create, configure, and orchestrate AI agents that can perform tasks autonomously.

Features

  • 🤖 Agent-based Architecture: Create autonomous AI agents with goals, instructions, and tools
  • 🔌 Multiple LLM Providers: Seamlessly switch between OpenAI, Anthropic, and other LLM providers
  • 🧰 Extensible Tools System: Equip agents with custom capabilities via the tool system
  • 🧠 Memory Management: Built-in systems for conversation memory and context tracking
  • 🔄 Workflow Automation: Chain multiple agents together to solve complex tasks

Installation

Add this line to your application's Gemfile:

gem 'anthemic'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install anthemic

Quick Start

require 'anthemic'

# Configure global settings
Anthemic.configure do |config|
  config.api_keys = {
    openai: ENV['OPENAI_API_KEY'],
    anthropic: ENV['ANTHROPIC_API_KEY']
  }
  config.default_provider = :anthropic
end

# Create a simple agent
agent = Anthemic::Agent.new(
  name: "Helpful Assistant",
  instructions: "You are a helpful assistant that provides concise and accurate information."
)

# Run the agent with a task
response = agent.run("What's the capital of France?")
puts response

Advanced Usage

Custom Tools

class WebSearchTool < Anthemic::Tools::Base
  def initialize(api_key: nil)
    super(
      name: "web_search",
      description: "Search the web for information"
    )
    @api_key = api_key || ENV['SEARCH_API_KEY']
  end

  def run(args = {})
    query = args[:query] || raise(ArgumentError, "query is required")
    # Implementation to search the web...
    # Return the search results
  end
end

# Create an agent with the custom tool
agent = Anthemic::Agent.new(
  name: "Research Assistant",
  instructions: "You help users research topics by searching the web.",
  tools: [WebSearchTool.new]
)

Custom Memory Systems

class VectorMemory < Anthemic::Memory::Base
  def initialize(provider: nil)
    @provider = provider || Anthemic::Providers::Openai.new
    @messages = []
    @vector_store = {}
  end

  def add(role:, content:)
    message = { role: role, content: content, timestamp: Time.now.to_i }
    @messages << message

    # Create and store an embedding for the message
    embedding = @provider.embed(content)
    @vector_store[message] = embedding
  end

  def get(query)
    return @messages if query.nil?

    # Get embedding for the query
    query_embedding = @provider.embed(query)

    # Find relevant messages based on embedding similarity
    # ...implementation of vector similarity search...
  end

  # other required methods...
end

Documentation

For complete documentation, see https://github.com/timeless-residents/anthemic/wiki

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/timeless-residents/anthemic.

License

The gem is available as open source under the terms of the MIT License.