Skip to main content

Python client for Adaptable Agents API - wrap your LLM clients with automatic context generation

Project description

Adaptable Agents Python Client

A Python client library that wraps your LLM clients (OpenAI, Anthropic, etc.) with automatic context generation from the Adaptable Agents API. This package seamlessly integrates with your existing LLM workflows to enhance responses with relevant past experiences.

Features

  • Automatic Context Integration: Automatically fetches relevant past experiences and appends them to your prompts
  • Memory Storage: Optionally stores input/output pairs as memories for future learning
  • OpenAI Support: Drop-in replacement for OpenAI client with context integration
  • Anthropic Support: Drop-in replacement for Anthropic client with context integration
  • Easy Configuration: Simple API key-based setup

Installation

pip install adaptable-agents

Or install from source:

git clone https://github.com/your-org/adaptable-agents-python-package.git
cd adaptable-agents-python-package
pip install -e .

Development Setup with uv

This project uses uv for fast virtual environment management. To set up a development environment:

# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create and activate virtual environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install the package in editable mode with dev dependencies
uv pip install -e ".[dev]"

The .python-version file specifies Python 3.11, which uv will automatically use.

Quick Start

OpenAI Integration

from adaptable_agents import AdaptableOpenAIClient

# Initialize the client with your API keys
client = AdaptableOpenAIClient(
    adaptable_api_key="your-adaptable-agents-api-key",
    openai_api_key="your-openai-api-key",
    memory_scope_path="customer-support/billing",  # Optional: organize by scope
    api_base_url="http://localhost:8000"  # Optional: defaults to localhost
)

# Use it just like the regular OpenAI client
response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {"role": "user", "content": "User asked about billing issues with subscription renewal"}
    ]
)

print(response.choices[0].message.content)

Anthropic Integration

from adaptable_agents import AdaptableAnthropicClient

# Initialize the client
client = AdaptableAnthropicClient(
    adaptable_api_key="your-adaptable-agents-api-key",
    anthropic_api_key="your-anthropic-api-key",
    memory_scope_path="engineering/frontend",
    api_base_url="http://localhost:8000"
)

# Use it just like the regular Anthropic client
response = client.messages.create(
    model="claude-3-opus-20240229",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "How do I implement authentication?"}
    ]
)

print(response.content[0].text)

How It Works

  1. Context Retrieval: Before making an LLM call, the client automatically fetches relevant context from the Adaptable Agents API based on your input
  2. Prompt Enhancement: The context is prepended to your user prompt to provide information from past successful interactions
  3. LLM Generation: The enhanced prompt is sent to your LLM provider (OpenAI, Anthropic, etc.)
  4. Memory Storage (optional): After generation, the input/output pair is stored as a memory for future learning

Advanced Usage

Custom Context Configuration

from adaptable_agents import AdaptableOpenAIClient, ContextConfig

config = ContextConfig(
    similarity_threshold=0.85,  # Higher threshold = more similar results
    max_items=10  # Maximum number of past experiences to include
)

client = AdaptableOpenAIClient(
    adaptable_api_key="your-api-key",
    openai_api_key="your-openai-key",
    context_config=config,
    memory_scope_path="my-scope"
)

Disable Automatic Memory Storage

client = AdaptableOpenAIClient(
    adaptable_api_key="your-api-key",
    openai_api_key="your-openai-key",
    auto_store_memories=False  # Don't automatically store memories
)

Manual Memory Storage

from adaptable_agents import AdaptableAgent

agent = AdaptableAgent(
    api_key="your-api-key",
    memory_scope_path="customer-support/billing"
)

# Store a memory manually
agent.store_memory(
    input_text="User asked about refund policy",
    output_text="Explained 30-day refund policy and processed refund",
    context="Customer was unsatisfied with service",
    success_score=0.95
)

Using Existing Client Instances

from openai import OpenAI
from adaptable_agents import AdaptableOpenAIClient

# Use your existing OpenAI client
existing_client = OpenAI(api_key="your-key")

# Wrap it with adaptable agents
client = AdaptableOpenAIClient(
    adaptable_api_key="your-adaptable-key",
    openai_client=existing_client,
    memory_scope_path="my-scope"
)

API Reference

AdaptableOpenAIClient

Wrapper for OpenAI client with context integration.

Parameters:

  • adaptable_api_key (str): API key for Adaptable Agents API
  • openai_api_key (str, optional): OpenAI API key (if not using existing client)
  • api_base_url (str): Base URL of Adaptable Agents API (default: "http://localhost:8000")
  • memory_scope_path (str): Memory scope path for organizing memories (default: "default")
  • context_config (ContextConfig, optional): Configuration for context generation
  • auto_store_memories (bool): Whether to automatically store memories (default: True)
  • openai_client (OpenAI, optional): Pre-initialized OpenAI client

AdaptableAnthropicClient

Wrapper for Anthropic client with context integration.

Parameters:

  • adaptable_api_key (str): API key for Adaptable Agents API
  • anthropic_api_key (str, optional): Anthropic API key (if not using existing client)
  • api_base_url (str): Base URL of Adaptable Agents API (default: "http://localhost:8000")
  • memory_scope_path (str): Memory scope path for organizing memories (default: "default")
  • context_config (ContextConfig, optional): Configuration for context generation
  • auto_store_memories (bool): Whether to automatically store memories (default: True)
  • anthropic_client (Anthropic, optional): Pre-initialized Anthropic client

AdaptableAgent

Core client for interacting with Adaptable Agents API.

Parameters:

  • api_key (str): API key for Adaptable Agents API
  • api_base_url (str): Base URL of Adaptable Agents API (default: "http://localhost:8000")
  • memory_scope_path (str): Memory scope path (default: "default")
  • context_config (ContextConfig, optional): Context configuration

Methods:

  • get_context(input_text: str, use_cache: bool = False) -> Optional[str]: Fetch context
  • store_memory(input_text: str, output_text: str, context: Optional[str] = None, success_score: float = 1.0) -> Optional[Dict]: Store memory
  • format_prompt_with_context(user_prompt: str, context: Optional[str]) -> str: Format prompt with context

Memory Scopes

Memory scopes allow you to organize memories hierarchically. Use different scopes for different contexts:

  • customer-support/billing - Billing-related support memories
  • engineering/frontend - Frontend engineering memories
  • sales/enterprise - Enterprise sales memories
  • custom/scope/path - Any custom hierarchical structure

Requirements

  • Python >= 3.8
  • requests >= 2.31.0
  • openai >= 1.0.0 (for OpenAI support)
  • anthropic >= 0.18.0 (for Anthropic support)

License

MIT License

Contributing

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

Support

For issues and questions, please open an issue on GitHub or contact support@adaptable-agents.com.

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

adaptable_agents-0.1.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

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

adaptable_agents-0.1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adaptable_agents-0.1.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for adaptable_agents-0.1.1.tar.gz
Algorithm Hash digest
SHA256 574e41300916128954be5cf8aeaf857df70e17ea464705bbdfae5e5f832398a9
MD5 2b2f8d0c5ec6e897765c3ae7424df89b
BLAKE2b-256 e9d9b1a81fa243ecff21810e89079770bf1c2f576f9d8a91573ef0b3599e9805

See more details on using hashes here.

File details

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

File metadata

  • Download URL: adaptable_agents-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for adaptable_agents-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad036418642e6ef45b9bb1c3d82faae94be4f937851aa95663ac7b226a10955c
MD5 eed55854720cb9d525d7847c65048032
BLAKE2b-256 336a3fc5d2be050d3366b226cfe167ae0df673737ba3e8105061f17fc1953bd6

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