# HACS Anthropic Integration
Generic Anthropic Claude integration for HACS providing structured outputs, tool calling, conversation management, and configurable clients that work with any HACS types.
## Features
- **Structured Outputs**: Generate any HACS model using Claude's tool calling capabilities
- **Tool Calling**: Native Anthropic tool calling with generic tools
- **Conversation Management**: Multi-turn conversations with context and memory
- **Configurable Clients**: Fully configurable Anthropic clients with custom parameters
- **Generic Utilities**: Work with any HACS Pydantic models
- **Batch Processing**: Efficient batch operations for high-volume use cases
## Installation
```bash
pip install hacs-anthropic
```
## Quick Start
### Basic Client Setup
```python
from hacs_anthropic import create_anthropic_client
# Basic client with defaults
client = create_anthropic_client()
# Custom configuration
client = create_anthropic_client(
model="claude-3-5-sonnet-20241022",
api_key="your-api-key",
base_url="https://api.anthropic.com", # Custom API URL
temperature=0.7,
max_tokens=4096
)
```
### Structured Output Generation
```python
from hacs_anthropic import create_structured_generator
from hacs_models import Patient
# Create generator
generator = create_structured_generator(
model="claude-3-5-sonnet-20241022",
temperature=0.3, # Lower for structured output
api_key="your-api-key"
)
# Generate any HACS model
patient = generator.generate_hacs_resource(
resource_type=Patient,
user_prompt="Create a patient record for John Doe, 30 years old, male"
)
print(f"Generated: {patient.display_name}")
```
### Tool Calling
```python
from hacs_anthropic import AnthropicClient, AnthropicToolRegistry
# Setup client and tool registry
client = AnthropicClient()
registry = AnthropicToolRegistry()
# Register any function as a tool
def process_text(text: str, operation: str) -> str:
operations = {
"upper": text.upper(),
"lower": text.lower(),
"reverse": text[::-1]
}
return operations.get(operation, text)
registry.register_tool(
name="process_text",
function=process_text,
description="Process text with specified operation",
input_schema={
"type": "object",
"properties": {
"text": {"type": "string"},
"operation": {"type": "string", "enum": ["upper", "lower", "reverse"]}
},
"required": ["text", "operation"]
}
)
# Use tools in conversation
response = client.tool_call(
messages=[
{"role": "user", "content": "Process the text 'Hello World' with upper operation"}
],
tools=registry.get_tools()
)
```
### Conversation Management
```python
from hacs_anthropic import create_conversation_manager
# Create conversation manager
manager = create_conversation_manager(
model="claude-3-5-sonnet-20241022",
api_key="your-api-key"
)
# Add context data
manager.add_context("user_id", "user-123")
manager.add_context("session_type", "interactive")
# Have a conversation
response1 = manager.send_message("Hello, I need help with data processing")
response2 = manager.send_message("Can you explain the previous response?")
# Get conversation history
history = manager.get_history()
```
## Advanced Usage
### Custom System Prompts
```python
from hacs_anthropic import AnthropicStructuredGenerator
# Custom system prompt
system_prompt = """You are an AI assistant that generates structured data.
Follow the provided schema exactly and ensure all required fields are populated.
Be precise and consistent in your outputs."""
generator = AnthropicStructuredGenerator(
model="claude-3-5-sonnet-20241022",
temperature=0.3,
system_prompt=system_prompt
)
# Generate with custom prompt
result = generator.generate_hacs_resource(
resource_type=YourModel,
user_prompt="Generate data based on this input"
)
```
### Batch Processing
```python
from hacs_anthropic import create_structured_generator
generator = create_structured_generator()
# Generate multiple resources
prompts = [
"Generate first resource",
"Generate second resource",
"Generate third resource"
]
results = generator.generate_batch_resources(
resource_type=YourModel,
prompts=prompts
)
for result in results:
if result:
print(f"Generated: {result}")
```
### Context-Aware Generation
```python
from hacs_anthropic import create_structured_generator
generator = create_structured_generator()
# Generate with context
context_data = {
"user_id": "user-123",
"session_id": "session-456",
"preferences": {"format": "detailed", "style": "formal"},
"previous_data": {"last_action": "create", "timestamp": "2024-01-01"}
}
result = generator.generate_with_context(
resource_type=YourModel,
user_prompt="Generate based on user preferences",
context_data=context_data
)
```
### Tool Registration with HACS Models
```python
from hacs_anthropic import AnthropicToolRegistry
from pydantic import BaseModel
registry = AnthropicToolRegistry()
# Define input model
class ProcessingInput(BaseModel):
data: str
operation: str
options: dict = {}
def process_data(data: str, operation: str, options: dict = {}) -> dict:
# Generic data processing
return {"processed": data, "operation": operation, "options": options}
# Register tool with HACS model
registry.register_hacs_tool(
name="process_data",
function=process_data,
description="Process data with specified operation and options",
input_model=ProcessingInput
)
```
## Configuration
### Environment Variables
```bash
# Anthropic API configuration
export ANTHROPIC_API_KEY="your-api-key"
export ANTHROPIC_API_URL="https://api.anthropic.com" # Custom API URL
# Default model settings
export ANTHROPIC_DEFAULT_MODEL="claude-3-5-sonnet-20241022"
export ANTHROPIC_DEFAULT_TEMPERATURE="0.7"
```
### Client Configuration
```python
from hacs_anthropic import AnthropicClient
# Fully configured client
client = AnthropicClient(
model="claude-3-5-sonnet-20241022",
api_key="your-api-key",
base_url="https://api.anthropic.com",
timeout=30.0,
max_retries=3,
max_tokens=4096,
temperature=0.7,
top_p=1.0,
top_k=None
)
```
## Error Handling
```python
from hacs_anthropic import create_structured_generator
import anthropic
generator = create_structured_generator()
try:
result = generator.generate_hacs_resource(
resource_type=YourModel,
user_prompt="Generate data"
)
except anthropic.APIError as e:
print(f"Anthropic API error: {e}")
except ValueError as e:
print(f"Validation error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
```
## Performance Optimization
### Batch Operations
```python
# Process multiple requests efficiently
results = generator.generate_batch_resources(
resource_type=YourModel,
prompts=batch_prompts,
max_tokens=1000, # Limit tokens per request
temperature=0.1 # Lower temperature for consistency
)
```
### Conversation Context Management
```python
from hacs_anthropic import AnthropicConversationManager
manager = AnthropicConversationManager(
max_context_length=100000 # Manage context window
)
# Add relevant context only
manager.add_context("current_task", task_data)
manager.add_context("user_preferences", preferences)
# Clear context when not needed
manager.clear_context()
```
## Generic Features
### Work with Any HACS Model
The utilities work with any Pydantic model:
```python
from pydantic import BaseModel
from hacs_anthropic import create_structured_generator
class CustomModel(BaseModel):
name: str
value: int
description: str
metadata: dict = {}
generator = create_structured_generator()
result = generator.generate_hacs_resource(
resource_type=CustomModel,
user_prompt="Generate a custom model instance"
)
```
### Multi-turn Workflows
```python
from hacs_anthropic import create_conversation_manager
manager = create_conversation_manager()
# Multi-turn workflow
response1 = manager.send_message("Start a new task")
response2 = manager.send_message("What are the next steps?")
response3 = manager.send_message("Execute the plan")
# Conversation maintains context throughout
```
## API Reference
### Classes
- `AnthropicClient`: Enhanced Anthropic client with HACS integration
- `AnthropicStructuredGenerator`: Generate any HACS model from text
- `AnthropicToolRegistry`: Registry for tools and functions
- `AnthropicConversationManager`: Multi-turn conversation management
### Functions
- `create_anthropic_client()`: Create configured Anthropic client
- `create_structured_generator()`: Create structured output generator
- `create_conversation_manager()`: Create conversation manager
## Model Support
### Supported Claude Models
- `claude-3-5-sonnet-20241022` (default) - Best for complex reasoning
- `claude-3-5-haiku-20241022` - Fastest for simple tasks
- `claude-3-opus-20240229` - Most capable for complex tasks
- `claude-3-sonnet-20240229` - Balanced performance
- `claude-3-haiku-20240307` - Fast and efficient
### Model Selection Guidelines
```python
# For complex reasoning tasks
client = create_anthropic_client(model="claude-3-5-sonnet-20241022")
# For simple data extraction
client = create_anthropic_client(model="claude-3-5-haiku-20241022")
# For maximum capability
client = create_anthropic_client(model="claude-3-opus-20240229")
```
## Contributing
See [Contributing Guidelines](../../CONTRIBUTING.md) for development setup and contribution process.
## License
Apache License 2.0 - see [LICENSE](../../LICENSE) for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "hacs-anthropic",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "agents, ai, anthropic, claude, clinical, communication, fhir, function-calling, healthcare, language-model, llm, standard, structured-output, tool-calling",
"author": null,
"author_email": "Solano Todeschini <solano.todeschini@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/2c/f2/b8e780e5055cb69f792f34c12a6b597aae070bef178afd72cbefa85f4f40/hacs_anthropic-0.3.1.tar.gz",
"platform": null,
"description": "# HACS Anthropic Integration\n\nGeneric Anthropic Claude integration for HACS providing structured outputs, tool calling, conversation management, and configurable clients that work with any HACS types.\n\n## Features\n\n- **Structured Outputs**: Generate any HACS model using Claude's tool calling capabilities\n- **Tool Calling**: Native Anthropic tool calling with generic tools\n- **Conversation Management**: Multi-turn conversations with context and memory\n- **Configurable Clients**: Fully configurable Anthropic clients with custom parameters\n- **Generic Utilities**: Work with any HACS Pydantic models\n- **Batch Processing**: Efficient batch operations for high-volume use cases\n\n## Installation\n\n```bash\npip install hacs-anthropic\n```\n\n## Quick Start\n\n### Basic Client Setup\n\n```python\nfrom hacs_anthropic import create_anthropic_client\n\n# Basic client with defaults\nclient = create_anthropic_client()\n\n# Custom configuration\nclient = create_anthropic_client(\n model=\"claude-3-5-sonnet-20241022\",\n api_key=\"your-api-key\",\n base_url=\"https://api.anthropic.com\", # Custom API URL\n temperature=0.7,\n max_tokens=4096\n)\n```\n\n### Structured Output Generation\n\n```python\nfrom hacs_anthropic import create_structured_generator\nfrom hacs_models import Patient\n\n# Create generator\ngenerator = create_structured_generator(\n model=\"claude-3-5-sonnet-20241022\",\n temperature=0.3, # Lower for structured output\n api_key=\"your-api-key\"\n)\n\n# Generate any HACS model\npatient = generator.generate_hacs_resource(\n resource_type=Patient,\n user_prompt=\"Create a patient record for John Doe, 30 years old, male\"\n)\n\nprint(f\"Generated: {patient.display_name}\")\n```\n\n### Tool Calling\n\n```python\nfrom hacs_anthropic import AnthropicClient, AnthropicToolRegistry\n\n# Setup client and tool registry\nclient = AnthropicClient()\nregistry = AnthropicToolRegistry()\n\n# Register any function as a tool\ndef process_text(text: str, operation: str) -> str:\n operations = {\n \"upper\": text.upper(),\n \"lower\": text.lower(),\n \"reverse\": text[::-1]\n }\n return operations.get(operation, text)\n\nregistry.register_tool(\n name=\"process_text\",\n function=process_text,\n description=\"Process text with specified operation\",\n input_schema={\n \"type\": \"object\",\n \"properties\": {\n \"text\": {\"type\": \"string\"},\n \"operation\": {\"type\": \"string\", \"enum\": [\"upper\", \"lower\", \"reverse\"]}\n },\n \"required\": [\"text\", \"operation\"]\n }\n)\n\n# Use tools in conversation\nresponse = client.tool_call(\n messages=[\n {\"role\": \"user\", \"content\": \"Process the text 'Hello World' with upper operation\"}\n ],\n tools=registry.get_tools()\n)\n```\n\n### Conversation Management\n\n```python\nfrom hacs_anthropic import create_conversation_manager\n\n# Create conversation manager\nmanager = create_conversation_manager(\n model=\"claude-3-5-sonnet-20241022\",\n api_key=\"your-api-key\"\n)\n\n# Add context data\nmanager.add_context(\"user_id\", \"user-123\")\nmanager.add_context(\"session_type\", \"interactive\")\n\n# Have a conversation\nresponse1 = manager.send_message(\"Hello, I need help with data processing\")\nresponse2 = manager.send_message(\"Can you explain the previous response?\")\n\n# Get conversation history\nhistory = manager.get_history()\n```\n\n## Advanced Usage\n\n### Custom System Prompts\n\n```python\nfrom hacs_anthropic import AnthropicStructuredGenerator\n\n# Custom system prompt\nsystem_prompt = \"\"\"You are an AI assistant that generates structured data.\nFollow the provided schema exactly and ensure all required fields are populated.\nBe precise and consistent in your outputs.\"\"\"\n\ngenerator = AnthropicStructuredGenerator(\n model=\"claude-3-5-sonnet-20241022\",\n temperature=0.3,\n system_prompt=system_prompt\n)\n\n# Generate with custom prompt\nresult = generator.generate_hacs_resource(\n resource_type=YourModel,\n user_prompt=\"Generate data based on this input\"\n)\n```\n\n### Batch Processing\n\n```python\nfrom hacs_anthropic import create_structured_generator\n\ngenerator = create_structured_generator()\n\n# Generate multiple resources\nprompts = [\n \"Generate first resource\",\n \"Generate second resource\",\n \"Generate third resource\"\n]\n\nresults = generator.generate_batch_resources(\n resource_type=YourModel,\n prompts=prompts\n)\n\nfor result in results:\n if result:\n print(f\"Generated: {result}\")\n```\n\n### Context-Aware Generation\n\n```python\nfrom hacs_anthropic import create_structured_generator\n\ngenerator = create_structured_generator()\n\n# Generate with context\ncontext_data = {\n \"user_id\": \"user-123\",\n \"session_id\": \"session-456\",\n \"preferences\": {\"format\": \"detailed\", \"style\": \"formal\"},\n \"previous_data\": {\"last_action\": \"create\", \"timestamp\": \"2024-01-01\"}\n}\n\nresult = generator.generate_with_context(\n resource_type=YourModel,\n user_prompt=\"Generate based on user preferences\",\n context_data=context_data\n)\n```\n\n### Tool Registration with HACS Models\n\n```python\nfrom hacs_anthropic import AnthropicToolRegistry\nfrom pydantic import BaseModel\n\nregistry = AnthropicToolRegistry()\n\n# Define input model\nclass ProcessingInput(BaseModel):\n data: str\n operation: str\n options: dict = {}\n\ndef process_data(data: str, operation: str, options: dict = {}) -> dict:\n # Generic data processing\n return {\"processed\": data, \"operation\": operation, \"options\": options}\n\n# Register tool with HACS model\nregistry.register_hacs_tool(\n name=\"process_data\",\n function=process_data,\n description=\"Process data with specified operation and options\",\n input_model=ProcessingInput\n)\n```\n\n## Configuration\n\n### Environment Variables\n\n```bash\n# Anthropic API configuration\nexport ANTHROPIC_API_KEY=\"your-api-key\"\nexport ANTHROPIC_API_URL=\"https://api.anthropic.com\" # Custom API URL\n\n# Default model settings\nexport ANTHROPIC_DEFAULT_MODEL=\"claude-3-5-sonnet-20241022\"\nexport ANTHROPIC_DEFAULT_TEMPERATURE=\"0.7\"\n```\n\n### Client Configuration\n\n```python\nfrom hacs_anthropic import AnthropicClient\n\n# Fully configured client\nclient = AnthropicClient(\n model=\"claude-3-5-sonnet-20241022\",\n api_key=\"your-api-key\",\n base_url=\"https://api.anthropic.com\",\n timeout=30.0,\n max_retries=3,\n max_tokens=4096,\n temperature=0.7,\n top_p=1.0,\n top_k=None\n)\n```\n\n## Error Handling\n\n```python\nfrom hacs_anthropic import create_structured_generator\nimport anthropic\n\ngenerator = create_structured_generator()\n\ntry:\n result = generator.generate_hacs_resource(\n resource_type=YourModel,\n user_prompt=\"Generate data\"\n )\nexcept anthropic.APIError as e:\n print(f\"Anthropic API error: {e}\")\nexcept ValueError as e:\n print(f\"Validation error: {e}\")\nexcept Exception as e:\n print(f\"Unexpected error: {e}\")\n```\n\n## Performance Optimization\n\n### Batch Operations\n\n```python\n# Process multiple requests efficiently\nresults = generator.generate_batch_resources(\n resource_type=YourModel,\n prompts=batch_prompts,\n max_tokens=1000, # Limit tokens per request\n temperature=0.1 # Lower temperature for consistency\n)\n```\n\n### Conversation Context Management\n\n```python\nfrom hacs_anthropic import AnthropicConversationManager\n\nmanager = AnthropicConversationManager(\n max_context_length=100000 # Manage context window\n)\n\n# Add relevant context only\nmanager.add_context(\"current_task\", task_data)\nmanager.add_context(\"user_preferences\", preferences)\n\n# Clear context when not needed\nmanager.clear_context()\n```\n\n## Generic Features\n\n### Work with Any HACS Model\n\nThe utilities work with any Pydantic model:\n\n```python\nfrom pydantic import BaseModel\nfrom hacs_anthropic import create_structured_generator\n\nclass CustomModel(BaseModel):\n name: str\n value: int\n description: str\n metadata: dict = {}\n\ngenerator = create_structured_generator()\nresult = generator.generate_hacs_resource(\n resource_type=CustomModel,\n user_prompt=\"Generate a custom model instance\"\n)\n```\n\n### Multi-turn Workflows\n\n```python\nfrom hacs_anthropic import create_conversation_manager\n\nmanager = create_conversation_manager()\n\n# Multi-turn workflow\nresponse1 = manager.send_message(\"Start a new task\")\nresponse2 = manager.send_message(\"What are the next steps?\")\nresponse3 = manager.send_message(\"Execute the plan\")\n\n# Conversation maintains context throughout\n```\n\n## API Reference\n\n### Classes\n\n- `AnthropicClient`: Enhanced Anthropic client with HACS integration\n- `AnthropicStructuredGenerator`: Generate any HACS model from text\n- `AnthropicToolRegistry`: Registry for tools and functions\n- `AnthropicConversationManager`: Multi-turn conversation management\n\n### Functions\n\n- `create_anthropic_client()`: Create configured Anthropic client\n- `create_structured_generator()`: Create structured output generator\n- `create_conversation_manager()`: Create conversation manager\n\n## Model Support\n\n### Supported Claude Models\n\n- `claude-3-5-sonnet-20241022` (default) - Best for complex reasoning\n- `claude-3-5-haiku-20241022` - Fastest for simple tasks\n- `claude-3-opus-20240229` - Most capable for complex tasks\n- `claude-3-sonnet-20240229` - Balanced performance\n- `claude-3-haiku-20240307` - Fast and efficient\n\n### Model Selection Guidelines\n\n```python\n# For complex reasoning tasks\nclient = create_anthropic_client(model=\"claude-3-5-sonnet-20241022\")\n\n# For simple data extraction\nclient = create_anthropic_client(model=\"claude-3-5-haiku-20241022\")\n\n# For maximum capability\nclient = create_anthropic_client(model=\"claude-3-opus-20240229\")\n```\n\n## Contributing\n\nSee [Contributing Guidelines](../../CONTRIBUTING.md) for development setup and contribution process.\n\n## License\n\nApache License 2.0 - see [LICENSE](../../LICENSE) for details. ",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Anthropic Claude integration for HACS (Healthcare Agent Communication Standard)",
"version": "0.3.1",
"project_urls": {
"Bug Tracker": "https://github.com/solanovisitor/hacs/issues",
"Changelog": "https://github.com/solanovisitor/hacs/blob/main/docs/reference/changelog.md",
"Documentation": "https://github.com/solanovisitor/hacs/tree/main/docs",
"Homepage": "https://github.com/solanovisitor/hacs",
"Repository": "https://github.com/solanovisitor/hacs"
},
"split_keywords": [
"agents",
" ai",
" anthropic",
" claude",
" clinical",
" communication",
" fhir",
" function-calling",
" healthcare",
" language-model",
" llm",
" standard",
" structured-output",
" tool-calling"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f104bd2aa18cbec6adf62146469d2b0caa6590bd008aa3048f13666c6af74d49",
"md5": "014b3bad4e59297a2f2a75fac1424c58",
"sha256": "398d4b3f272c2553133987034215a208e5f56e10aa2d8d74d0bc5f882a973d53"
},
"downloads": -1,
"filename": "hacs_anthropic-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "014b3bad4e59297a2f2a75fac1424c58",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 9227,
"upload_time": "2025-07-10T14:43:08",
"upload_time_iso_8601": "2025-07-10T14:43:08.180490Z",
"url": "https://files.pythonhosted.org/packages/f1/04/bd2aa18cbec6adf62146469d2b0caa6590bd008aa3048f13666c6af74d49/hacs_anthropic-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "2cf2b8e780e5055cb69f792f34c12a6b597aae070bef178afd72cbefa85f4f40",
"md5": "80853b0822c7d89a0a810b5726ac772e",
"sha256": "917690747e1e03aea3a376b252ee4b02731b6f1d41d732b463d3c379bdb1fe41"
},
"downloads": -1,
"filename": "hacs_anthropic-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "80853b0822c7d89a0a810b5726ac772e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 11037,
"upload_time": "2025-07-10T14:43:09",
"upload_time_iso_8601": "2025-07-10T14:43:09.401096Z",
"url": "https://files.pythonhosted.org/packages/2c/f2/b8e780e5055cb69f792f34c12a6b597aae070bef178afd72cbefa85f4f40/hacs_anthropic-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-10 14:43:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "solanovisitor",
"github_project": "hacs",
"github_not_found": true,
"lcname": "hacs-anthropic"
}