Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

hier-config-gpt

PyPI version Python 3.10+ License Documentation

An enhanced hierarchical configuration library that integrates Large Language Model (LLM) capabilities for advanced network configuration analysis and remediation.

Overview

hier-config-gpt extends the powerful hier-config library by adding AI-driven custom remediation workflows. It addresses complex network configuration edge cases that fall outside standard negation and idempotency workflows by leveraging LLMs to dynamically generate remediation plans.

Key Features

  • Multi-Provider LLM Support: Works with OpenAI GPT, Anthropic Claude, and Ollama (self-hosted) models
  • Intelligent Remediation: Automatically generates complex configuration remediation steps
  • Quorum Mode: Optional consensus mechanism across multiple LLM providers for increased reliability
  • Response Caching: Built-in caching to reduce API costs and improve performance
  • Rate Limiting: Token bucket algorithm to prevent API throttling
  • Configurable Prompts: Customize prompt templates for your specific needs
  • Production Ready: Comprehensive error handling, retry logic, and logging

Installation

Basic Installation

pip install hier-config-gpt

Install with Specific Provider(s)

# OpenAI GPT models
pip install hier-config-gpt[openai]

# Anthropic Claude models
pip install hier-config-gpt[anthropic]

# Ollama (self-hosted) models
pip install hier-config-gpt[ollama]

# All providers
pip install hier-config-gpt[all]

Quick Start

Basic Example with OpenAI

import os
from hier_config import HConfig, Platform
from hier_config.models import MatchRule
from hier_config_gpt import GPTWorkflowRemediation
from hier_config_gpt.models import GPTRemediationRule, GPTRemediationExample
from hier_config_gpt.clients import ChatGPTClient

# Load configurations
running_config = open("running_config.conf").read()
generated_config = open("desired_config.conf").read()

# Initialize workflow
wfr = GPTWorkflowRemediation(
    running_config=HConfig.from_text(Platform.CISCO_IOS, running_config),
    generated_config=HConfig.from_text(Platform.CISCO_IOS, generated_config)
)

# Define remediation rule
description = """When remediating an access-list on Cisco IOS devices:
1. Resequence the access-list so each sequence number is a multiple of 10
2. Add a temporary 'permit any' statement at sequence 1
3. Apply the required changes from the generated configuration
4. Remove the temporary permit statement
"""

lineage = (MatchRule(startswith="ip access-list"),)
example = GPTRemediationExample(
    running_config="ip access-list extended TEST\n  12 permit ip host 10.0.0.1 any",
    remediation_config="ip access-list resequence TEST 10 10\nip access-list extended TEST\n  1 permit ip any any\n  no 10\n  10 permit ip host 10.0.0.2 any\n  no 1"
)

gpt_rule = GPTRemediationRule(
    description=description,
    lineage=lineage,
    example=example
)

# Add rule and set up client
wfr.add_gpt_rule(gpt_rule)
client = ChatGPTClient(api_key=os.getenv("OPENAI_API_KEY"), model="gpt-4o")
wfr.set_gpt_client(client)

# Generate remediation plan
remediation = wfr.gpt_remediation_config()
print(remediation)

Using Anthropic Claude

from hier_config_gpt.clients import ClaudeGPTClient

client = ClaudeGPTClient(
    api_key=os.getenv("ANTHROPIC_API_KEY"),
    model="claude-3-5-sonnet-20241022"
)
wfr.set_gpt_client(client)

Using Ollama (Self-Hosted)

from hier_config_gpt.clients import OllamaGPTClient

client = OllamaGPTClient(
    host="http://localhost:11434",
    model="llama3.2"
)
wfr.set_gpt_client(client)

Advanced Features

Response Caching

Reduce API costs and improve performance with built-in caching:

from hier_config_gpt.clients import ChatGPTClient, CachedGPTClient, ResponseCache

# Create base client
base_client = ChatGPTClient(api_key=os.getenv("OPENAI_API_KEY"))

# Wrap with caching (1 hour TTL)
cache = ResponseCache(ttl_seconds=3600)
client = CachedGPTClient(base_client, cache=cache)

wfr.set_gpt_client(client)

Rate Limiting

Prevent API throttling with automatic rate limiting:

from hier_config_gpt.clients import ChatGPTClient, RateLimitedGPTClient

# Create base client
base_client = ChatGPTClient(api_key=os.getenv("OPENAI_API_KEY"))

# Wrap with rate limiting (60 requests per minute)
client = RateLimitedGPTClient(
    base_client,
    max_requests=60,
    time_window_seconds=60.0
)

wfr.set_gpt_client(client)

Combining Caching and Rate Limiting

from hier_config_gpt.clients import (
    ChatGPTClient,
    CachedGPTClient,
    RateLimitedGPTClient,
    ResponseCache
)

# Create layered client: rate limiting -> caching -> base client
base_client = ChatGPTClient(api_key=os.getenv("OPENAI_API_KEY"))
cached_client = CachedGPTClient(base_client, cache=ResponseCache())
client = RateLimitedGPTClient(cached_client, max_requests=60)

wfr.set_gpt_client(client)

Quorum Mode (Multi-Provider Consensus)

Use multiple LLM providers with majority voting for critical operations:

from hier_config_gpt.clients import (
    ChatGPTClient,
    ClaudeGPTClient,
    OllamaGPTClient,
    MultiProviderGPTClient
)

# Create multiple provider clients
openai_client = ChatGPTClient(api_key=os.getenv("OPENAI_API_KEY"))
claude_client = ClaudeGPTClient(api_key=os.getenv("ANTHROPIC_API_KEY"))
ollama_client = OllamaGPTClient()

# Create quorum client (requires majority agreement)
client = MultiProviderGPTClient(
    providers=[openai_client, claude_client, ollama_client],
    enable_quorum=True
)

wfr.set_gpt_client(client)

Custom Prompt Templates

Customize the prompt structure for your specific needs:

from hier_config_gpt import PromptTemplate, GPTWorkflowRemediation

# Define custom template
custom_template = """
Generate network commands to transform the configuration.

CURRENT STATE:
{running_config}

DESIRED STATE:
{generated_config}

RULES:
{description}

EXAMPLE:
Running: {example_running_config}
Remediation: {example_remediation_config}

Return JSON with "plan" array of command strings.
"""

# Use custom template
template = PromptTemplate(template=custom_template)
wfr = GPTWorkflowRemediation(
    running_config=running,
    generated_config=generated,
    prompt_template=template
)

Configuration Timeouts

All clients support configurable timeouts:

# OpenAI with 30-second timeout
client = ChatGPTClient(
    api_key=os.getenv("OPENAI_API_KEY"),
    timeout=30.0
)

# Claude with custom timeout
client = ClaudeGPTClient(
    api_key=os.getenv("ANTHROPIC_API_KEY"),
    timeout=45.0
)

Use Cases

  • Access List Resequencing: Automatically handle complex ACL resequencing with temporary permit statements
  • Interface Configuration: Generate safe interface configuration changes with proper ordering
  • Routing Protocol Updates: Handle complex routing protocol transitions
  • VLAN Reconfiguration: Manage VLAN changes across multiple switches
  • QoS Policy Updates: Coordinate policy-map and class-map changes

Documentation

Full documentation is available at hier-config-gpt.readthedocs.io

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Security

For security considerations and best practices, see SECURITY.md.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Credits

Support

Download files

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

Source Distribution

hier_config_gpt-0.1.1a0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

hier_config_gpt-0.1.1a0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file hier_config_gpt-0.1.1a0.tar.gz.

File metadata

  • Download URL: hier_config_gpt-0.1.1a0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.14 Darwin/25.5.0

File hashes

Hashes for hier_config_gpt-0.1.1a0.tar.gz
Algorithm Hash digest
SHA256 6909ec66d3ad9c05a2653c78e934107c8f911996e968df3f18633c0d9efe96ca
MD5 33c14e059149af98e3d30512a5a31977
BLAKE2b-256 aa1238be6c94c791a21023485ea3162d036aa76ea37e32d751cd2f7ace7eb569

See more details on using hashes here.

File details

Details for the file hier_config_gpt-0.1.1a0-py3-none-any.whl.

File metadata

  • Download URL: hier_config_gpt-0.1.1a0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.14 Darwin/25.5.0

File hashes

Hashes for hier_config_gpt-0.1.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d56896dd729f380260220a4f043501784d90df8911910fc89b1eae49f803cf5
MD5 efe1cd54cb4a844a1acbff71f3128348
BLAKE2b-256 6ded26c9393f6cc0907b9b66224cce1b0358d2bc322e7e0755a40e513f28c0e6

See more details on using hashes here.

Supported by

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