Shared utilities for the NthLayer ecosystem
Project description
nthlayer-common
Shared utilities for the NthLayer ecosystem. Provides the unified LLM interface, provider infrastructure, identity resolution, and data models used by all ecosystem components.
Install
pip install nthlayer-common
LLM Interface
Model-agnostic — one function, any provider. No LiteLLM, no SDKs. Direct HTTP calls via httpx.
from nthlayer_common import llm_call
result = llm_call(
system="You are a triage agent...",
user="Evaluate this incident...",
)
print(result.text)
Provider support
Two API formats cover the entire market:
| Provider | Model format | API |
|---|---|---|
| Anthropic | anthropic/claude-sonnet-4-20250514 |
Messages API |
| OpenAI | openai/gpt-4o |
Chat Completions |
| Ollama | ollama/llama3.1 |
Chat Completions |
| Azure | azure/my-deployment |
Chat Completions |
| Together | together/meta-llama/Llama-3-70b |
Chat Completions |
| Groq | groq/llama-3.1-70b-versatile |
Chat Completions |
| Mistral | mistral/mistral-large-latest |
Chat Completions |
| vLLM | vllm/my-model |
Chat Completions |
| LM Studio | lmstudio/my-model |
Chat Completions |
Configuration
NTHLAYER_MODEL="anthropic/claude-sonnet-4-20250514" # default
NTHLAYER_LLM_TIMEOUT="60" # seconds
ANTHROPIC_API_KEY="sk-ant-..." # for anthropic/* models
OPENAI_API_KEY="sk-..." # for openai/*, together/*, groq/*, etc.
OPENAI_API_BASE="http://localhost:11434/v1" # override endpoint URL
Retry & resilience
Built-in retry with exponential backoff and jitter for transient errors (429, 502, 503, timeouts). Respects Retry-After headers. Permanent errors (400, 401, 403) fail immediately. Default: 3 retries.
Provider Infrastructure
Shared async providers for infrastructure services, migrated from nthlayer-generate so all ecosystem components use the same clients:
PrometheusProvider— query, query_range, get_sli_value, health_checkGrafanaProvider— dashboard CRUD, datasource management, folder operationsPagerDutyProvider— service, team, and escalation policy managementMimirRulerProvider— Prometheus rule push to Grafana MimirProviderRegistry— register/create/list providers by name
Identity Resolution
Cross-provider service name normalization and ownership attribution:
IdentityResolver— 7-strategy resolution (explicit mapping → external ID → exact → alias → normalized → fuzzy → attribute correlation)normalize_service_name()— strips env suffixes, version tags, Java package prefixes, type suffixesOwnershipResolver— queries multiple ownership sources concurrently, selects highest-confidence signal- Ownership providers — Backstage, Kubernetes, PagerDuty (live); CODEOWNERS, Declared (static, in nthlayer)
HTTP Clients
Shared HTTP client infrastructure with per-instance retry and circuit breaker:
BaseHTTPClient— httpx-based with configurable retry (tenacity) + circuit breakerCortexClient— Cortex API clientPagerDutyClient— PagerDuty REST API clientSlackAPIClient— Slack Web API (token-based,post_message)
Slack Notifications
SlackNotifier— Block Kit messages via incoming webhook (fail-open, never blocks pipelines)SlackWebClient— Web API for interactive messages (buttons, message updates, signature verification)
Error Handling
Unified error hierarchy for the entire ecosystem:
ExitCode— SUCCESS=0, WARNING=1, BLOCKED=2, CONFIG_ERROR=10, PROVIDER_ERROR=11, VALIDATION_ERROR=12NthLayerError→ConfigurationError,ProviderError,ValidationError,BlockedError@main_with_error_handling()— decorator for CLI main functions with automatic exit code conversion
Tier Definitions
Single source of truth for service tier configuration:
Tier— CRITICAL, STANDARD, LOW (with legacy aliases tier-1/2/3)TIER_CONFIGS— availability targets, latency thresholds, error budget warning/blocking percentages, PagerDuty urgencynormalize_tier(),get_tier_config(),get_slo_targets()
Data Models
Shared Pydantic/dataclass models used across the ecosystem:
- SLO models —
SLO,ErrorBudget,SLOStatus,TimeWindow - Dependency models —
DependencyGraph,DependencyType,BlastRadiusResult - Domain models —
Run,Finding,Team,Service - Gate models —
GateResult,GatePolicy,DeploymentGateCheck
Prompt Loader
Shared YAML prompt loader for agentic components:
load_prompt(path)— reads YAML, renders schema block into system promptrender_user_prompt(template, **kwargs)— simple{{ variable }}interpolationvalidate_response(data, schema)— validates model output against expected schema
Typed package
Ships with a py.typed marker (PEP 561) — mypy and pyright use inline type annotations directly without requiring a separate stub package.
License
Apache 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 nthlayer_common-0.1.5.tar.gz.
File metadata
- Download URL: nthlayer_common-0.1.5.tar.gz
- Upload date:
- Size: 55.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6627a990181280f3bc52530d91cf9a7ba5d32a01966fa0017d8bcf5362a3ff26
|
|
| MD5 |
3b3cc01868c355fc0f6404d624a5e905
|
|
| BLAKE2b-256 |
d9bfa51dec9ebd3d7df614ef8165429d2fdfab1af0a664396de3187bd6a62d1c
|
Provenance
The following attestation bundles were made for nthlayer_common-0.1.5.tar.gz:
Publisher:
release.yml on rsionnach/nthlayer-common
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nthlayer_common-0.1.5.tar.gz -
Subject digest:
6627a990181280f3bc52530d91cf9a7ba5d32a01966fa0017d8bcf5362a3ff26 - Sigstore transparency entry: 1278815984
- Sigstore integration time:
-
Permalink:
rsionnach/nthlayer-common@194f4f53ef0372e2046d67aeb9438a2210846205 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/rsionnach
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@194f4f53ef0372e2046d67aeb9438a2210846205 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nthlayer_common-0.1.5-py3-none-any.whl.
File metadata
- Download URL: nthlayer_common-0.1.5-py3-none-any.whl
- Upload date:
- Size: 56.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85281ed323b2bf094e56c27caa73bd6c2d03729d0797dec752240dac78296ce0
|
|
| MD5 |
47e869a58a58642380a5d993c325b953
|
|
| BLAKE2b-256 |
09abf442f1e9f47d347cbb6481cd3fb0d069cfcbc9a6ea78f8a58443408b7c7a
|
Provenance
The following attestation bundles were made for nthlayer_common-0.1.5-py3-none-any.whl:
Publisher:
release.yml on rsionnach/nthlayer-common
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nthlayer_common-0.1.5-py3-none-any.whl -
Subject digest:
85281ed323b2bf094e56c27caa73bd6c2d03729d0797dec752240dac78296ce0 - Sigstore transparency entry: 1278816254
- Sigstore integration time:
-
Permalink:
rsionnach/nthlayer-common@194f4f53ef0372e2046d67aeb9438a2210846205 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/rsionnach
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@194f4f53ef0372e2046d67aeb9438a2210846205 -
Trigger Event:
release
-
Statement type: