Skip to main content

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_check
  • GrafanaProvider — dashboard CRUD, datasource management, folder operations
  • PagerDutyProvider — service, team, and escalation policy management
  • MimirRulerProvider — Prometheus rule push to Grafana Mimir
  • ProviderRegistry — 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 suffixes
  • OwnershipResolver — 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 breaker
  • CortexClient — Cortex API client
  • PagerDutyClient — PagerDuty REST API client
  • SlackAPIClient — 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=12
  • NthLayerErrorConfigurationError, 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 urgency
  • normalize_tier(), get_tier_config(), get_slo_targets()

Data Models

Shared Pydantic/dataclass models used across the ecosystem:

  • SLO modelsSLO, ErrorBudget, SLOStatus, TimeWindow
  • Dependency modelsDependencyGraph, DependencyType, BlastRadiusResult
  • Domain modelsRun, Finding, Team, Service
  • Gate modelsGateResult, GatePolicy, DeploymentGateCheck

Prompt Loader

Shared YAML prompt loader for agentic components:

  • load_prompt(path) — reads YAML, renders schema block into system prompt
  • render_user_prompt(template, **kwargs) — simple {{ variable }} interpolation
  • validate_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nthlayer_common-0.1.3.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nthlayer_common-0.1.3-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file nthlayer_common-0.1.3.tar.gz.

File metadata

  • Download URL: nthlayer_common-0.1.3.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nthlayer_common-0.1.3.tar.gz
Algorithm Hash digest
SHA256 59e04a6211ef46c02b3f63d01a4e48e4b28a5f8ca2927eb17430df1fd0b60cb1
MD5 2c8127dde51d0f3d22d2044a4befc3fa
BLAKE2b-256 ab4c21956c6c8ed96946cfe43a7ecdc32919f7a3b2318fa87abf40c2e0cff050

See more details on using hashes here.

Provenance

The following attestation bundles were made for nthlayer_common-0.1.3.tar.gz:

Publisher: release.yml on rsionnach/nthlayer-common

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nthlayer_common-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nthlayer_common-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nthlayer_common-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b9ca7e229427231c4b49b68a5d1e756253ceaa50b0e4b9839bca7e93dddf7cff
MD5 5eb7ec6a02cc1d7d52ccdfe44cadb1e3
BLAKE2b-256 2c1523d3c529e35f58aa2e48eab59fde96a1d805dcb80aac6bf496ab167afb66

See more details on using hashes here.

Provenance

The following attestation bundles were made for nthlayer_common-0.1.3-py3-none-any.whl:

Publisher: release.yml on rsionnach/nthlayer-common

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page