adachsoft/ai-integration-anthropic

Anthropic Claude tool-calling SPI adapter for adachsoft/ai-integration.

Maintainers

Package info

gitlab.com/a.adach/ai-integration-anthropic

Issues

pkg:composer/adachsoft/ai-integration-anthropic

Statistics

Installs: 12

Dependents: 0

Suggesters: 0

Stars: 0

v0.3.0 2026-05-09 09:34 UTC

This package is auto-updated.

Last update: 2026-05-09 10:08:38 UTC


README

Integration of Anthropic Claude (tool calling) with the adachsoft/ai-integration library.

Version

Current version: 0.1.0 (first public release).

Requirements

  • PHP >= 8.3
  • guzzlehttp/guzzle ^7.0 || ^8.0
  • adachsoft/ai-integration ^0.6.3

Installation

composer require adachsoft/ai-integration-anthropic:^0.1.0

Basic usage

Example of wiring the Anthropic SPI provider with the tool-calling facade from adachsoft/ai-integration:

use AdachSoft\AiIntegration\PublicApi\Builder\ToolCallingChatFacadeBuilder;
use AdachSoft\AiIntegrationAnthropic\AnthropicToolCallingChatSpi;

$apiKey = getenv('ANTHROPIC_KEY');

$builder = new ToolCallingChatFacadeBuilder();
$builder->withSpiProvider('anthropic', new AnthropicToolCallingChatSpi($apiKey));

$facade = $builder->build();

More detailed usage examples can be found in the production tests:

  • tests/Production/ToolCalling/AnthropicProviderProductionTest.php
  • tests/Production/ToolCalling/AnthropicFileToolsConversationProductionTest.php

Anthropic cache configuration

This package exposes an explicit configuration surface for controlling Anthropic ephemeral cache via ToolCallingChatSpiRequest::$parameters. All cache-related keys are prefixed with ai_integration-.

You can control three independent sections:

  • ai_integration-cache_system – caching of the system prompt (off, 5min, 1hour).
  • ai_integration-cache_tools – caching of tool definitions (off, 5min, 1hour).
  • ai_integration-cache_messages – caching of conversation messages (off, 5min, 1hour).

When ai_integration-cache_messages is enabled (5min or 1hour), you can also choose how the message cache is applied using:

  • ai_integration-cache_messages_strategy – built-in strategies: off, first_user, last_user.

The cache layer is opt-in and non-intrusive – if you do not provide any ai_integration-* keys, all cache behaviour is disabled and requests behave exactly as before.

For a full description of the configuration format, TTL semantics, beta headers and built-in message cache strategies, see:

  • docs/CACHE_STRATEGIES.md

Tests

The default phpunit.xml configuration defines two test suites:

  • unit – unit tests (no production calls).
  • production – production/integration tests that require a real Anthropic API key.

Example commands:

# All tests
vendor/bin/phpunit

# Only unit tests
vendor/bin/phpunit --testsuite unit

# Only production tests (requires ANTHROPIC_KEY)
ANTHROPIC_KEY=... vendor/bin/phpunit --testsuite production