hexastack-ai
AI engine, LLM provider integration (LiteLLM, Instructor, PydanticAI), and CQRS agent tool reflection for the Hexastack hexagonal architecture framework.
1. Overview
hexastack-ai integrates an agnostic, production-grade AI stack directly into the Hexastack architecture:
- LiteLLM: Unified driver abstraction across 100+ LLM providers (OpenAI, Anthropic Claude, Google Gemini, Ollama, Groq, Bedrock).
- Instructor: Self-correcting structured output validation returning strongly typed Pydantic models.
- PydanticAI: Type-safe agent loop orchestration and tool execution.
- CQRS Tool Reflection: Automatically turns Hexastack CQRS Commands and Queries into callable AI Agent tools.
2. Architecture & Relationships
graph TD
subgraph Core ["hexastack-core"]
PORT["LlmProviderPort"]
MEM["InMemoryLlmProvider"]
end
subgraph AI ["hexastack-ai"]
BOOT["AiBootstrapper (order=18)"]
ADAPTER["LiteLlmAdapter"]
TOOLS["create_cqrs_agent / create_tool_for_message"]
AGENT_ADAPTER["PydanticAiAgentAdapter"]
end
subgraph CQRS ["hexastack-cqrs"]
PIPELINE["ExecutionPipeline"]
CMDS["Commands & Queries"]
end
subgraph UpstreamAI ["Agnostic AI Stack"]
LITE["LiteLLM (100+ Providers)"]
INST["Instructor (Schema Validation)"]
PY_AI["PydanticAI (Agent Execution)"]
end
BOOT -->|binds into DI| PORT
ADAPTER -. implements .-> PORT
ADAPTER --> LITE
ADAPTER --> INST
TOOLS --> PIPELINE
TOOLS --> PY_AI
AGENT_ADAPTER --> PY_AI
3. Installation
# Standalone install
pip install hexastack-ai
# Via umbrella package
pip install "hexastack[ai]"
4. Configuration Reference
[hexastack.ai]
# Provider: "memory" (default for testing), "litellm", "openai", "anthropic", "gemini", "ollama"
provider = "litellm"
model = "gpt-4o-mini"
temperature = 0.2
max_tokens = 2048
api_key = "sk-..." # Or set standard env var OPENAI_API_KEY / ANTHROPIC_API_KEY
# LiteLLM Dialect Settings
[hexastack.ai.litellm]
drop_params = true
num_retries = 3
timeout = 60.0
api_base = "http://localhost:4000" # Optional LiteLLM proxy URL
# Ollama Local Dialect Settings
[hexastack.ai.ollama]
base_url = "http://localhost:11434"
# PydanticAI Agent Settings
[hexastack.ai.agent]
max_turns = 10
system_prompt = "You are a helpful AI assistant."
5. Usage Examples
1. Structured Output Extraction
from pydantic import BaseModel
from hexastack_core.ports.ai import LlmProviderPort
class InvoiceDTO(BaseModel):
customer_id: str
total_amount: float
items: list[str]
def extract_invoice(llm: LlmProviderPort, text: str) -> InvoiceDTO:
return llm.generate_structured(
prompt=f"Extract invoice details from: {text}",
response_schema=InvoiceDTO,
)
2. Auto-Reflecting CQRS Commands as Agent Tools
from hexastack_core.domain import Command, Query
from hexastack_ai.infra.tools import create_cqrs_agent
class CancelSubscriptionCommand(Command):
user_id: str
reason: str
class GetUserPlanQuery(Query[str]):
user_id: str
# Create PydanticAI agent with CQRS handlers as native tools:
agent = create_cqrs_agent(
pipeline=runtime.pipeline,
messages=[CancelSubscriptionCommand, GetUserPlanQuery],
model="anthropic/claude-3-5-sonnet",
system_prompt="You are a customer support agent.",
)
# Agent selects appropriate tools and executes them via Hexastack ExecutionPipeline:
result = agent.run_sync("Cancel subscription for user 123 due to pricing.")
Release files for hexastack-ai 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hexastack_ai-0.1.0.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hexastack_ai-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.1 kB
Release files / hexastack_ai-0.1.0.tar.gz
| Download URL | hexastack_ai-0.1.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1b46cc0f622fe658053be93400b8a36435b492c6e4db98fc302a9eb13180002
|
|
BLAKE2b-256 checksum How to use checksums |
5b4843f4e0935de2e819d1ac539e46a6af58de433c125f7abff906af78af38aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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":null}
|
Release files / hexastack_ai-0.1.0-py3-none-any.whl
| Download URL | hexastack_ai-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67cd0609a9d3149017a16e35b43bdf37a9c3f1a51ab8c60e90b80e5eb12baecb
|
|
BLAKE2b-256 checksum How to use checksums |
077dd498a504e32ab82e3d7ae89fcbf388f64e662547ac5e68d4d83d5232a787
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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":null}
|