Official Python Runtime for AI-Protocol - The canonical Pythonic implementation for unified AI model interaction
Project description
ai-lib-python
Official Python Runtime for AI-Protocol - The canonical Pythonic implementation for unified AI model interaction.
๐ฏ Design Philosophy
ai-lib-python is the official Python runtime implementation for the AI-Protocol specification. It embodies the core design principle:
ไธๅ้ป่พ็็ฎๅญ๏ผไธๅ้ ็ฝฎ็ๅ่ฎฎ (All logic is operators, all configuration is protocol)
Unlike traditional adapter libraries that hardcode provider-specific logic, ai-lib-python is a protocol-driven runtime that executes AI-Protocol specifications. This means:
- Zero hardcoded provider logic: All behavior is driven by protocol manifests (YAML/JSON configurations)
- Operator-based architecture: Processing is done through composable operators (Decoder โ Selector โ Accumulator โ FanOut โ EventMapper)
- Hot-reloadable: Protocol configurations can be updated without restarting the application
- Unified interface: Developers interact with a single, consistent API regardless of the underlying provider
๐ Quick Start
Basic Usage
import asyncio
from ai_lib_python import AiClient, Message
async def main():
# Create client with model
client = await AiClient.create("openai/gpt-4o")
# Simple chat completion
response = await (
client.chat()
.user("Hello! What's 2+2?")
.execute()
)
print(response.content)
# Output: 2+2 equals 4.
await client.close()
asyncio.run(main())
โจ Features
- Protocol-Driven: All behavior is driven by YAML/JSON protocol files
- Unified Interface: Single API for all AI providers (OpenAI, Anthropic, Gemini, DeepSeek, etc.)
- Streaming First: Native async streaming with Python's
async for - Type Safe: Full type hints with Pydantic v2 models
- Production Ready: Built-in retry, rate limiting, circuit breaker, and fallback
- Extensible: Easy to add new providers via protocol configuration
- Multimodal: Support for text, images (base64/URL), and audio
- Telemetry: Structured logging, metrics, distributed tracing, and user feedback collection
- Token Counting: tiktoken integration and cost estimation
- Connection Pooling: Efficient HTTP connection management
- Request Batching: Parallel execution with concurrency control
- Model Routing: Smart model selection with load balancing strategies
- Embeddings: Embedding generation with vector operations
- Structured Output: JSON mode with schema validation
- Response Caching: Multi-backend caching with TTL support
- Plugin System: Extensible hooks and middleware architecture
- Stream Cancellation: Cooperative cancellation for streaming operations
๐ V2 Protocol Alignment
Starting with v0.5.0, ai-lib-python aligns with the AI-Protocol V2 specification. V0.7.0 adds full V2 runtime support including V2 manifest parsing, provider drivers, MCP tool bridge, Computer Use abstraction, extended multimodal, and capability registry.
Standard Error Codes (V2)
All provider errors are classified into 13 standard error codes with unified retry/fallback semantics:
| Code | Name | Retryable | Fallbackable |
|---|---|---|---|
| E1001 | invalid_request |
No | No |
| E1002 | authentication |
No | Yes |
| E1003 | permission_denied |
No | No |
| E1004 | not_found |
No | No |
| E1005 | request_too_large |
No | No |
| E2001 | rate_limited |
Yes | Yes |
| E2002 | quota_exhausted |
No | Yes |
| E3001 | server_error |
Yes | Yes |
| E3002 | overloaded |
Yes | Yes |
| E3003 | timeout |
Yes | Yes |
| E4001 | conflict |
Yes | No |
| E4002 | cancelled |
No | No |
| E9999 | unknown |
No | No |
Classification follows a priority pipeline: provider-specific error code โ HTTP status override โ standard HTTP mapping โ E9999.
Compliance Tests
Cross-runtime behavioral consistency is verified by a shared YAML-based test suite from the ai-protocol repository:
# Run compliance tests
pytest tests/compliance/ -v
# With explicit compliance directory
COMPLIANCE_DIR=../ai-protocol/tests/compliance pytest tests/compliance/ -v
For details, see CROSS_RUNTIME.md.
Testing with ai-protocol-mock
For integration and MCP e2e tests without real API calls, use ai-protocol-mock:
# Start mock server (from ai-protocol-mock repo)
docker-compose up -d
# Run tests with mock
MOCK_HTTP_URL=http://localhost:4010 MOCK_MCP_URL=http://localhost:4010/mcp pytest tests/ -v
# Run only mock E2E tests (chat, streaming, tools, MCP)
MOCK_HTTP_URL=http://localhost:4010 pytest tests/integration/test_mock_chat_e2e.py tests/integration/test_mcp_bridge_e2e.py -v
With proxy: set NO_PROXY to include the mock server IP (e.g. NO_PROXY=192.168.2.13,localhost,127.0.0.1).
Or in code: AiClient.create("openai/gpt-4o", base_url="http://localhost:4010")
๐ฆ Installation
pip install ai-lib-python
With optional features (V2 capability extras):
# Full installation with all features
pip install ai-lib-python[full]
# V2 capability extras
pip install ai-lib-python[vision] # Image processing (Pillow)
pip install ai-lib-python[audio] # Audio processing (soundfile)
pip install ai-lib-python[embeddings] # Embedding generation
pip install ai-lib-python[structured] # Structured output / JSON mode
pip install ai-lib-python[batch] # Batch processing
pip install ai-lib-python[agentic] # Agent workflow support
pip install ai-lib-python[stt] # Speech-to-Text (STT)
pip install ai-lib-python[tts] # Text-to-Speech (TTS)
pip install ai-lib-python[reranking] # Document reranking
# Infrastructure extras
pip install ai-lib-python[telemetry] # OpenTelemetry integration
pip install ai-lib-python[tokenizer] # tiktoken token counting
# For Jupyter notebook integration
pip install ai-lib-python[jupyter]
# For development
pip install ai-lib-python[dev]
๐ง Configuration
The library automatically looks for protocol manifests in the following locations (in order):
- Custom path set via
AI_PROTOCOL_PATHenvironment variable - Common dev paths:
ai-protocol/,../ai-protocol/,../../ai-protocol/ - Last resort: GitHub raw
hiddenpath/ai-protocol(main)
Provider manifests are resolved in a backward-compatible order:
dist/v1/providers/<id>.json โ v1/providers/<id>.yaml.
Useful Environment Variables
| Variable | Description | Default |
|---|---|---|
AI_PROTOCOL_PATH |
Custom protocol directory (local path or GitHub URL) | - |
AI_HTTP_TIMEOUT_SECS |
HTTP timeout in seconds | 60 |
AI_LIB_MAX_INFLIGHT |
Max concurrent requests | 10 |
AI_LIB_RPS |
Rate limit (requests per second) | - |
AI_LIB_BREAKER_FAILURE_THRESHOLD |
Circuit breaker failure threshold | 5 |
AI_LIB_BREAKER_COOLDOWN_SECS |
Circuit breaker cooldown seconds | 30 |
MOCK_HTTP_URL |
Mock server URL for testing (ai-protocol-mock) | - |
MOCK_MCP_URL |
Mock MCP endpoint for testing | - |
Provider API Keys
The runtime reads API keys from environment variables in the format: <PROVIDER_ID>_API_KEY
# Set API keys
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GOOGLE_API_KEY="..."
export DEEPSEEK_API_KEY="..."
Recommended for production: Use environment variables for CI/CD, containers, and production deployments.
๐จ Protocol-Driven Architecture
No match provider statements. All logic is derived from protocol configuration:
# The pipeline is built dynamically from protocol manifest
pipeline = Pipeline.from_manifest(manifest)
# Operators are configured via manifests (YAML/JSON), not hardcoded
# Adding a new provider requires zero code changes
Hot Reload
Protocol configurations can be updated at runtime:
from ai_lib_python.protocol import ProtocolLoader
loader = ProtocolLoader(hot_reload=True)
# Protocol changes are automatically picked up
๐ Usage Examples
Streaming
async def stream_example():
client = await AiClient.create("anthropic/claude-3-5-sonnet")
async for event in (
client.chat()
.system("You are a helpful assistant.")
.user("Tell me a short story.")
.stream()
):
if event.is_content_delta:
print(event.as_content_delta.content, end="", flush=True)
print() # Newline at end
await client.close()
With Messages List
from ai_lib_python import Message
messages = [
Message.system("You are a Python expert."),
Message.user("How do I read a file in Python?"),
]
response = await (
client.chat()
.messages(messages)
.temperature(0.7)
.max_tokens(1024)
.execute()
)
Tool Calling (Function Calling)
from ai_lib_python import ToolDefinition
# Define a tool
weather_tool = ToolDefinition.from_function(
name="get_weather",
description="Get current weather for a location",
parameters={
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
)
# Use tool in request
response = await (
client.chat()
.user("What's the weather in Tokyo?")
.tools([weather_tool])
.execute()
)
# Check for tool calls
if response.tool_calls:
for tool_call in response.tool_calls:
print(f"Call {tool_call.function_name}: {tool_call.arguments}")
Multimodal (Images)
from ai_lib_python import Message, ContentBlock
# Image from URL
message = Message.user_with_image(
"What's in this image?",
image_url="https://example.com/image.jpg"
)
# Image from base64
with open("photo.jpg", "rb") as f:
image_data = base64.b64encode(f.read()).decode()
message = Message(
role=MessageRole.USER,
content=[
ContentBlock.text("Describe this image:"),
ContentBlock.image_base64(image_data, "image/jpeg"),
]
)
response = await client.chat().messages([message]).execute()
Production-Ready Configuration
from ai_lib_python import AiClient
# Enable all resilience patterns
client = await (
AiClient.builder()
.model("openai/gpt-4o")
.production_ready() # Enables retry, rate limit, circuit breaker
.with_fallbacks(["anthropic/claude-3-5-sonnet"])
.build()
)
# Check resilience status
print(f"Circuit state: {client.circuit_state}")
print(f"In-flight requests: {client.current_inflight}")
print(client.get_resilience_stats())
Custom Resilience Configuration
from ai_lib_python import AiClient
from ai_lib_python.resilience import (
RetryConfig,
RateLimiterConfig,
CircuitBreakerConfig,
)
client = await (
AiClient.builder()
.model("openai/gpt-4o")
.with_retry(RetryConfig(
max_retries=5,
min_delay_ms=1000,
max_delay_ms=30000,
))
.with_rate_limit(RateLimiterConfig.from_rps(10))
.with_circuit_breaker(CircuitBreakerConfig(
failure_threshold=5,
cooldown_seconds=30,
))
.max_inflight(20)
.build()
)
Context Manager
async with await AiClient.create("openai/gpt-4o") as client:
response = await client.chat().user("Hello!").execute()
print(response.content)
# Client automatically closed
Token Counting and Cost Estimation
from ai_lib_python.tokens import TokenCounter, estimate_cost, get_model_pricing
# Count tokens
counter = TokenCounter.for_model("gpt-4o")
token_count = counter.count("Hello, how are you?")
print(f"Token count: {token_count}")
# Count message tokens
messages = [Message.user("Hello!"), Message.assistant("Hi there!")]
total_tokens = counter.count_messages(messages)
# Estimate cost
cost = estimate_cost(input_tokens=1000, output_tokens=500, model="gpt-4o")
print(f"Estimated cost: ${cost.total_cost:.4f}")
# Get model pricing info
pricing = get_model_pricing("gpt-4o")
print(f"Input: ${pricing.input_price_per_1k}/1K tokens")
print(f"Context window: {pricing.context_window} tokens")
Metrics and Telemetry
from ai_lib_python.telemetry import (
get_logger,
MetricsCollector,
MetricLabels,
Tracer,
)
# Structured logging
logger = get_logger("my_app")
logger.info("Request started", model="gpt-4o", tokens=100)
# Metrics collection
collector = MetricsCollector()
labels = MetricLabels(provider="openai", model="gpt-4o")
collector.record_request(labels, latency=0.5, status="success", tokens_in=100, tokens_out=50)
# Get metrics snapshot
snapshot = collector.get_snapshot()
print(f"Total requests: {snapshot.total_requests}")
print(f"P99 latency: {snapshot.latency_p99_ms:.2f}ms")
# Export to Prometheus format
prometheus_metrics = collector.to_prometheus()
# Distributed tracing
tracer = Tracer("my_service")
with tracer.span("api_call") as span:
span.set_attribute("model", "gpt-4o")
# ... do work
Batch Processing
from ai_lib_python.batch import BatchExecutor, BatchConfig
# Execute multiple requests concurrently
async def process_question(question: str) -> str:
client = await AiClient.create("openai/gpt-4o")
response = await client.chat().user(question).execute()
await client.close()
return response.content
questions = ["What is AI?", "What is Python?", "What is async?"]
executor = BatchExecutor(process_question, max_concurrent=5)
result = await executor.execute(questions)
print(f"Successful: {result.successful_count}")
print(f"Failed: {result.failed_count}")
for answer in result.get_successful_results():
print(answer)
Connection Pooling
from ai_lib_python.transport import ConnectionPool, PoolConfig
# Create connection pool with custom config
pool = ConnectionPool(PoolConfig.high_throughput())
# Use pooled connections
async with pool:
client = await pool.get_client("openai", "https://api.openai.com")
response = await client.post("/v1/chat/completions", json=payload)
# Get pool statistics
stats = pool.get_stats("openai")
print(f"Active connections: {stats['openai']['active_connections']}")
Model Routing & Selection
from ai_lib_python.routing import (
ModelManager, ModelInfo, create_openai_models, create_anthropic_models,
CostBasedSelector, QualityBasedSelector,
)
# Create a model manager with pre-configured models
manager = create_openai_models()
manager.merge(create_anthropic_models())
# Select model by capability
code_models = manager.filter_by_capability("code_generation")
print(f"Code models: {[m.name for m in code_models]}")
# Select cheapest model
selector = CostBasedSelector()
cheapest = selector.select(manager.list_models())
print(f"Cheapest: {cheapest.name} @ ${cheapest.pricing.input_cost_per_1k}/1K")
# Select highest quality model
quality_selector = QualityBasedSelector()
best = quality_selector.select(manager.list_models())
print(f"Best quality: {best.name}")
# Recommend model for use case
recommended = manager.recommend_for("chat")
Stream Cancellation
from ai_lib_python.client import create_cancel_pair, CancellableStream, CancelReason
async def cancellable_stream():
client = await AiClient.create("openai/gpt-4o")
# Create cancel token and handle
token, handle = create_cancel_pair()
# Start streaming with cancellation support
stream = client.chat().user("Write a long story...").stream()
cancellable = CancellableStream(stream, token)
# In another task, you can cancel:
# handle.cancel(CancelReason.USER_REQUEST)
async for event in cancellable:
if event.is_content_delta:
print(event.as_content_delta.content, end="")
# Check if cancelled
if token.is_cancelled:
print("\n[Cancelled]")
break
User Feedback Collection
from ai_lib_python.telemetry import (
RatingFeedback, ThumbsFeedback, ChoiceSelectionFeedback,
InMemoryFeedbackSink, set_feedback_sink, report_feedback,
)
# Set up feedback collection
sink = InMemoryFeedbackSink(max_events=1000)
set_feedback_sink(sink)
# Report user feedback
await report_feedback(RatingFeedback(
request_id="req-123",
rating=5,
category="helpfulness",
comment="Great response!"
))
await report_feedback(ThumbsFeedback(
request_id="req-456",
is_positive=True
))
# Report multi-candidate selection (for A/B testing)
await report_feedback(ChoiceSelectionFeedback(
request_id="req-789",
chosen_index=0,
rejected_indices=[1, 2],
latency_to_select_ms=1500.0
))
# Retrieve feedback
all_feedback = sink.get_events()
request_feedback = sink.get_events_by_request("req-123")
Embeddings
from ai_lib_python.embeddings import (
EmbeddingClient, cosine_similarity, find_most_similar
)
# Create embedding client
client = await EmbeddingClient.create("openai/text-embedding-3-small")
# Generate embeddings
response = await client.embed("Hello, world!")
embedding = response.first.vector
print(f"Dimensions: {len(embedding)}")
# Batch embeddings
texts = ["Hello", "World", "Python", "AI"]
response = await client.embed_batch(texts)
# Find most similar
query = response.embeddings[0].vector
candidates = [e.vector for e in response.embeddings[1:]]
results = find_most_similar(query, candidates, top_k=2)
for idx, score in results:
print(f"Text '{texts[idx+1]}' similarity: {score:.4f}")
await client.close()
Response Caching
from ai_lib_python.cache import CacheManager, CacheConfig, MemoryCache
# Create cache manager
cache = CacheManager(
config=CacheConfig(default_ttl_seconds=3600),
backend=MemoryCache(max_size=1000)
)
# Cache responses
key = cache.generate_key(model="gpt-4o", messages=messages)
# Check cache first
cached = await cache.get(key)
if cached:
print("Cache hit!")
response = cached
else:
response = await client.chat().messages(messages).execute()
await cache.set(key, response)
# Get cache statistics
stats = cache.stats()
print(f"Hit ratio: {stats.hit_ratio:.2%}")
Plugin System
from ai_lib_python.plugins import (
Plugin, PluginContext, PluginRegistry, HookType, HookManager
)
# Create a custom plugin
class LoggingPlugin(Plugin):
def name(self) -> str:
return "logging"
async def on_before_request(self, ctx: PluginContext) -> None:
print(f"Request to {ctx.model}: {ctx.request}")
async def on_after_response(self, ctx: PluginContext) -> None:
print(f"Response received: {ctx.response}")
# Register plugin
registry = PluginRegistry()
await registry.register(LoggingPlugin())
# Use hooks for fine-grained control
hooks = HookManager()
hooks.register(HookType.BEFORE_REQUEST, "log", lambda ctx: print(f"Starting {ctx.model}"))
# Trigger hooks
ctx = PluginContext(model="gpt-4o", request={"messages": [...]})
await registry.trigger_before_request(ctx)
Batch Processing
For batch execution with concurrency control:
from ai_lib_python.batch import BatchExecutor, BatchConfig
# Execute multiple requests concurrently
async def process_question(question: str) -> str:
client = await AiClient.create("openai/gpt-4o")
response = await client.chat().user(question).execute()
await client.close()
return response.content
questions = ["What is AI?", "What is Python?", "What is async?"]
executor = BatchExecutor(process_question, max_concurrent=5)
result = await executor.execute(questions)
print(f"Successful: {result.successful_count}")
print(f"Failed: {result.failed_count}")
for answer in result.get_successful_results():
print(answer)
Supported Providers
| Provider | Models | Streaming | Tools | Vision |
|---|---|---|---|---|
| OpenAI | GPT-4o, GPT-4, GPT-3.5 | โ | โ | โ |
| Anthropic | Claude 3.5, Claude 3 | โ | โ | โ |
| Gemini Pro, Gemini Flash | โ | โ | โ | |
| DeepSeek | DeepSeek Chat, Coder | โ | โ | โ |
| Qwen | Qwen2.5, Qwen-Max | โ | โ | โ |
| Groq | Llama, Mixtral | โ | โ | โ |
| Mistral | Mistral Large, Medium | โ | โ | โ |
API Reference
Core Classes
AiClient: Main entry point for AI model interactionMessage: Represents a chat message with role and contentContentBlock: Content blocks for multimodal messagesToolDefinition: Tool/function definition for function callingStreamingEvent: Events from streaming responses
Resilience Classes
RetryPolicy: Exponential backoff with jitterRateLimiter: Token bucket rate limitingCircuitBreaker: Circuit breaker patternBackpressure: Concurrency limitingFallbackChain: Multi-target failoverPreflightChecker: Unified request gatingSignalsSnapshot: Runtime state aggregation
Routing Classes
ModelManager: Centralized model managementModelInfo: Model information with capabilitiesModelArray: Load balancing across endpointsModelSelectionStrategy: Selection strategies (Cost, Quality, Performance, etc.)
Telemetry Classes
AiLibLogger: Structured logging with maskingMetricsCollector: Request metrics collectionTracer: Distributed tracingHealthChecker: Health monitoringFeedbackSink: User feedback collection
Embedding Classes
EmbeddingClient: Embedding generation clientEmbedding: Single embedding resultEmbeddingResponse: Response with usage stats
Token Classes
TokenCounter: Token counting interfaceCostEstimate: Cost estimation resultModelPricing: Model pricing information
Cache Classes
CacheManager: High-level cache managementCacheBackend: Cache backend interface (Memory, Disk, Null)CacheKeyGenerator: Deterministic key generation
Batch Classes
BatchCollector: Request groupingBatchExecutor: Parallel execution
Plugin Classes
Plugin: Base plugin classPluginRegistry: Plugin managementHookManager: Event-driven hooksMiddleware: Request/response chain
Transport Classes
ConnectionPool: HTTP connection poolingPoolConfig: Pool configuration
Cancellation Classes
CancelToken: Cooperative cancellation tokenCancelHandle: Public cancel interfaceCancellableStream: Cancellable async iterator
Error Classes
AiLibError: Base error classProtocolError: Protocol loading/validation errorsTransportError: HTTP transport errorsRemoteError: API errors from providers
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ AiClient โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ChatRequest โ โ Resilience โ โ Protocol โ โ
โ โ Builder โ โ Executor โ โ Loader โ โ
โ โโโโโโโโฌโโโโโโโ โโโโโโโโฌโโโโโโโ โโโโโโโโโโโโฌโโโโโโโโโโโ โ
โโโโโโโโโโโผโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ HttpTransport โ โ Pipeline โ โ ProtocolManifest โ
โ (httpx) โ โ (decodeโ โ โ (YAML/JSON) โ
โ โ โ selectโ โ โ โ
โ โ โ map) โ โ โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
๐งช Development
# Clone the repository
git clone https://github.com/hiddenpath/ai-lib-python.git
cd ai-lib-python
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=src/ai_lib_python
# Type checking
mypy src
# Linting
ruff check src tests
# Format code
ruff format src tests
Project Structure
ai-lib-python/
โโโ src/ai_lib_python/
โ โโโ __init__.py # Package exports
โ โโโ types/ # Type definitions
โ โ โโโ message.py # Message, ContentBlock
โ โ โโโ tool.py # ToolDefinition, ToolCall
โ โ โโโ events.py # StreamingEvent types
โ โโโ protocol/ # Protocol layer
โ โ โโโ manifest.py # ProtocolManifest models
โ โ โโโ loader.py # Protocol loading
โ โ โโโ validator.py # Schema validation (+ version/streaming checks)
โ โโโ transport/ # HTTP transport
โ โ โโโ http.py # HttpTransport
โ โ โโโ auth.py # API key resolution
โ โ โโโ pool.py # ConnectionPool
โ โโโ pipeline/ # Stream processing
โ โ โโโ decode.py # SSE/NDJSON decoders
โ โ โโโ select.py # JSONPath selectors
โ โ โโโ accumulate.py # Tool call accumulator
โ โ โโโ event_map.py # Event mappers
โ โ โโโ fan_out.py # FanOut, Replicate, Split transforms
โ โโโ resilience/ # Resilience patterns
โ โ โโโ retry.py # RetryPolicy
โ โ โโโ rate_limiter.py # RateLimiter
โ โ โโโ circuit_breaker.py
โ โ โโโ backpressure.py
โ โ โโโ fallback.py # FallbackChain
โ โ โโโ executor.py # ResilientExecutor
โ โ โโโ signals.py # SignalsSnapshot
โ โ โโโ preflight.py # PreflightChecker
โ โโโ routing/ # Model routing & load balancing
โ โ โโโ models.py # ModelInfo, ModelCapabilities
โ โ โโโ strategies.py # Selection strategies
โ โ โโโ manager.py # ModelManager
โ โ โโโ array.py # ModelArray (load balancing)
โ โโโ client/ # User API
โ โ โโโ core.py # AiClient
โ โ โโโ builder.py # Builders
โ โ โโโ response.py # ChatResponse
โ โ โโโ cancel.py # CancelToken, CancellableStream
โ โโโ embeddings/ # Embedding support
โ โ โโโ client.py # EmbeddingClient
โ โ โโโ types.py # Embedding, EmbeddingRequest
โ โ โโโ vectors.py # Vector operations
โ โโโ cache/ # Response caching
โ โ โโโ manager.py # CacheManager
โ โ โโโ backend.py # MemoryCache, DiskCache
โ โ โโโ key.py # CacheKeyGenerator
โ โโโ tokens/ # Token counting
โ โ โโโ counter.py # TokenCounter, TiktokenCounter
โ โ โโโ pricing.py # ModelPricing, CostEstimate
โ โโโ telemetry/ # Observability
โ โ โโโ logging.py # AiLibLogger
โ โ โโโ metrics.py # MetricsCollector
โ โ โโโ tracing.py # Tracer
โ โ โโโ health.py # HealthChecker
โ โ โโโ feedback.py # Feedback types and sinks
โ โโโ batch/ # Request batching
โ โ โโโ collector.py # BatchCollector
โ โ โโโ executor.py # BatchExecutor
โ โโโ plugins/ # Plugin system
โ โ โโโ base.py # Plugin base class
โ โ โโโ registry.py # PluginRegistry
โ โ โโโ hooks.py # HookManager
โ โ โโโ middleware.py # Middleware chain
โ โโโ structured/ # Structured output
โ โ โโโ json_mode.py # JsonModeConfig
โ โ โโโ schema.py # SchemaGenerator
โ โ โโโ validator.py # OutputValidator
โ โโโ utils/ # Utilities
โ โ โโโ tool_call_assembler.py # ToolCallAssembler
โ โโโ drivers/ # V2 provider drivers (OpenAI, Anthropic, Gemini)
โ โโโ mcp/ # MCP tool bridge
โ โโโ computer_use/ # Computer Use abstraction
โ โโโ multimodal/ # Extended multimodal support
โ โโโ registry/ # Capability registry
โ โโโ errors/ # Error hierarchy
โโโ tests/
โ โโโ unit/ # Unit tests
โ โโโ integration/ # Integration tests (incl. V2 compliance)
โโโ docs/ # Documentation
โโโ examples/ # Example scripts
โโโ pyproject.toml
๐ Related Projects
- AI-Protocol - Protocol specification (v1.5 / V2)
- ai-lib-rust - Rust runtime implementation
๐ค Contributing
Contributions are welcome! Please ensure that:
- All protocol configurations follow the AI-Protocol specification (v1.5 / V2)
- New features are properly documented with examples
- Tests are included for new features
- Compliance tests pass for cross-runtime behaviors (
pytest tests/compliance/) - Code follows Python best practices (PEP 8) and passes
ruff check - Type hints pass
mypy --strictfor modified modules
๐ License
This project is licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
๐ Related Projects
- AI-Protocol: Protocol specification (v1.5 / V2)
- ai-lib-rust: Rust runtime implementation
ai-lib-python - Where protocol meets Pythonic elegance. ๐โจ
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_lib_python-0.8.3-py3-none-any.whl.
File metadata
- Download URL: ai_lib_python-0.8.3-py3-none-any.whl
- Upload date:
- Size: 212.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
621ce0ab25fbd2c863dd067017a7034fd6061ff44fa8a27c70d1c40af2812d20
|
|
| MD5 |
aa6134da3a031c15af3ee033a40a1f3b
|
|
| BLAKE2b-256 |
0c9bf6ec5e36f78482723b8797b08e3751dde739cd5b86f0908090481655f3fd
|