Skip to main content

Claudine AI agent

Project description

🤖 Claudine

A Python wrapper for the Anthropic Claude API that simplifies tool use, token tracking, and agent functionality.

📦 Installation

# Using pip
pip install claudine

✨ Features

  • 🔌 Easy integration with Claude 3 models
  • 🛠️ Tool registration and management
  • 🔢 Token usage tracking and reporting
  • 💰 Cost information tracking
  • 📞 Support for tool callbacks
  • 💬 Simplified message handling

🚀 Quick Start

from claudine import Agent

# Initialize the agent
agent = Agent()

# Process a prompt
response = agent.process_prompt("Write a short poem about programming.")
print(response)

# Get token usage information
token_info = agent.get_token_usage()
print(f"Total tokens used: {token_info.total_usage.total_tokens}")

# Get cost information
cost_info = agent.get_cost()
print(f"Total cost: ${cost_info['total_cost'].total_cost:.6f} {cost_info['total_cost'].unit}")

🔧 Tool Usage

from claudine import Agent

def search_web(query: str) -> str:
    """Search the web for information."""
    # Implementation here
    return f"Results for: {query}"

# Initialize agent with tools
agent = Agent(
    tools=[search_web]
)

# Process a prompt that might use tools
response = agent.process_prompt("What's the weather in London?")
print(response)

📝 Text Editor Tool

Claudine supports the text editor tool for Claude, allowing it to view and edit text files:

def handle_editor_tool(command, **kwargs):
    # Implement the text editor tool
    # ...

# Initialize the agent with the text editor tool
agent = Agent(text_editor_tool=handle_editor_tool)

The text editor tool supports the following commands:

  • 👁️ view: View the contents of a file
  • 🔄 str_replace: Replace text in a file
  • create: Create a new file
  • insert: Insert text at a specific position
  • ↩️ undo_edit: Undo the last edit

For more information, see the Anthropic documentation.

🔢 Token Tracking

Claudine provides detailed token usage information:

token_info = agent.get_token_usage()

# Text usage
print(f"Text input tokens: {token_info.text_usage.input_tokens}")
print(f"Text output tokens: {token_info.text_usage.output_tokens}")

# Tool usage
print(f"Tool input tokens: {token_info.tools_usage.input_tokens}")
print(f"Tool output tokens: {token_info.tools_usage.output_tokens}")

# Total usage
print(f"Total tokens: {token_info.total_usage.total_tokens}")

🐛 Debugging

Claudine provides a debug mode to help you understand what's happening behind the scenes:

# Initialize agent with debug mode
agent = Agent(debug_mode=True)

# Process a prompt
response = agent.process_prompt("Hello, Claude!")

When debug mode is enabled, Claudine will print detailed information about the API requests being sent to Claude, including:

  • 💬 Message content
  • 🛠️ Tool definitions
  • ⚙️ Model parameters

This is particularly useful when debugging tool use and text editor interactions.

💰 Cost Tracking

Claudine also provides detailed cost information:

cost_info = agent.get_cost()

# Text costs
print(f"Text input cost: ${cost_info['text_cost'].input_cost:.6f} {cost_info['text_cost'].unit}")
print(f"Text output cost: ${cost_info['text_cost'].output_cost:.6f} {cost_info['text_cost'].unit}")
print(f"Text total cost: ${cost_info['text_cost'].total_cost:.6f} {cost_info['text_cost'].unit}")

# Tool costs
print(f"Tool input cost: ${cost_info['tools_cost'].input_cost:.6f} {cost_info['tools_cost'].unit}")
print(f"Tool output cost: ${cost_info['tools_cost'].output_cost:.6f} {cost_info['tools_cost'].unit}")
print(f"Tool total cost: ${cost_info['tools_cost'].total_cost:.6f} {cost_info['tools_cost'].unit}")

# Total cost
print(f"Total cost: ${cost_info['total_cost'].total_cost:.6f} {cost_info['total_cost'].unit}")

# Cost by tool
for tool_name, cost in cost_info['by_tool'].items():
    print(f"Tool: {tool_name}")
    print(f"  Input cost: ${cost.input_cost:.6f} {cost.unit}")
    print(f"  Output cost: ${cost.output_cost:.6f} {cost.unit}")
    print(f"  Total cost: ${cost.total_cost:.6f} {cost.unit}")

📄 License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claudine-0.1.1.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claudine-0.1.1-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file claudine-0.1.1.tar.gz.

File metadata

  • Download URL: claudine-0.1.1.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for claudine-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b6199c98eeb2d63fd33e6f90041279c4cb3b947ef46c2d4eb71b24a48b04146e
MD5 e5db8569bd36f07b0bdfbe4216874435
BLAKE2b-256 2f32af747aa5bb81ec6643e6c8a4df0a3a982d0b8d298a25d9d0ca36af8bd966

See more details on using hashes here.

File details

Details for the file claudine-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: claudine-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for claudine-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dbdc85c8e9ac595c64d531e44536928e36fba70beac406d365f97b042a27ada
MD5 17d3f1c1d6aa97c44ba0efd18d526d3d
BLAKE2b-256 5200e11ac81f197b211180a21b74f973e1ff91aa13f80e5dddc899f012a89b7f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page