Skip to main content

language-model-common

A shared Python framework for building LLM-powered agent applications with LangChain and LangGraph. It provides reusable infrastructure for configuration management, protocol conversion, MCP tool integration, file management, and more.

Features

  • Multi-source configuration loading — Read LLM model configs from local filesystem, AWS S3, or GitHub repositories with TTL-based caching and client-specific overrides (see config reader security notes)
  • LangGraph-to-OpenAI protocol conversion — Stream LangGraph agent output as OpenAI-compatible Server-Sent Events (SSE) for chat completion APIs
  • MCP (Model Context Protocol) client toolkit — Connect to and invoke tools on a single MCP server as LangChain-compatible tools, with session pooling, server-card discovery, and tool-result caching
  • Prompt template library — Load and manage prompt templates from organized directory structures with GitHub auto-download support
  • File management abstraction — Unified interface for local and AWS S3 storage with factory-based backend selection
  • Token and cost management — Token reduction for long conversations and usage metadata tracking via tiktoken
  • Authentication and authorization — OAuth with PKCE, JWT token validation, OIDC provider discovery
  • Image generation — Provider abstraction over OpenAI and AWS Bedrock image generators
  • OCR extraction — AWS Textract integration behind a factory interface
  • Dependency injection container — Pre-wired service registry using simple-container with singleton lifecycle management

Installation

pip install language-model-common

Requirements: Python >= 3.10

Quick Start

Reading Model Configurations

from languagemodelcommon.configs.config_reader import ConfigReader

config_reader = ConfigReader(
    config_paths=["./configs"],  # local path, s3:// URI, or github:// path
)

# Load base configs with optional client-specific overrides
models = await config_reader.read_model_configs_async(client_id="my-client")

Configuration sources are selected by path prefix:

  • Local: ./configs or /absolute/path
  • S3: s3://bucket-name/path
  • GitHub: Managed via GithubConfigRepoManager with automatic background refresh

Loading Prompts

from languagemodelcommon.configs.prompt_library import PromptLibraryManager

prompt_manager = PromptLibraryManager(config_paths=["./configs"])
prompt_text = prompt_manager.get_prompt("system-prompt")

Prompts are loaded from .md or .txt files in a prompts/ subdirectory of your config paths.

Streaming LangGraph Output as OpenAI SSE

from languagemodelcommon.converters import LangGraphToOpenAIConverter

converter = LangGraphToOpenAIConverter(
    streaming_manager=streaming_manager,
    token_reducer=token_reducer,
)

response = await converter.stream_response(
    graph=my_langgraph,
    messages=messages,
    config=config,
)

File Management

from languagemodelcommon.file_managers import FileManagerFactory

factory = FileManagerFactory(aws_client_factory=aws_factory)

# Automatically selects local or S3 backend based on the folder path
manager = factory.create("s3://my-bucket")
await manager.save_file_async(file_data, "s3://my-bucket", "output.json", "application/json")

Using the Dependency Injection Container

from languagemodelcommon.container import LanguageModelCommonContainerFactory
from simple_container import SimpleContainer

container = SimpleContainer()
LanguageModelCommonContainerFactory.register_services_in_container(container)

config_reader = container.resolve(ConfigReader)

Environment Variables

Variable Description Default
GITHUB_CONFIG_REPO_URL GitHub zipball API URL for config repo —
GITHUB_TOKEN GitHub token for authenticated requests —
GITHUB_CACHE_FOLDER Local cache directory for GitHub configs /tmp/github_config_cache
CONFIG_CACHE_TIMEOUT_SECONDS Config refresh interval (seconds) 120
GITHUB_TIMEOUT HTTP timeout for GitHub requests (seconds) 300

Development

Prerequisites

  • Docker and Docker Compose

Setup

make init

This builds the development Docker image, locks dependencies, and sets up pre-commit hooks.

Running Tests

make tests

Tests run inside Docker using pytest with async support (asyncio_mode = auto).

Other Commands

make shell       # Open a shell in the dev container
make update      # Update dependencies and rebuild
make build       # Build distribution package
make package     # Publish to PyPI
make testpackage # Publish to TestPyPI

Project Structure

languagemodelcommon/
├── auth/              # Token storage and auth managers
├── aws/               # AWS client factory
├── configs/           # Config reader, prompt library, schemas
├── container/         # DI container factory
├── converters/        # LangGraph-to-OpenAI conversion, streaming
├── exceptions/        # Custom exception types
├── file_managers/     # Local and S3 file management
├── graph/             # LangGraph utilities
├── history/           # Conversation history management
├── http/              # HTTP client factory
├── image_generation/  # Image generation providers
├── markdown/          # HTML/CSV to Markdown converters
├── mcp/               # MCP client, tool catalog, OAuth
├── models/            # LLM model definitions
├── mocks/             # Test mocks and fakes
├── ocr/               # OCR extraction (AWS Textract)
├── persistence/       # LangGraph checkpoint/store backends
├── schema/            # OpenAI-compatible schema definitions
├── state/             # LangGraph state definitions
├── structures/        # Request/response wrappers
├── tools/             # Resilient tool base class, MCP tools
└── utilities/         # Logging, caching, token reduction, security

License

Apache License 2.0

Release files for language-model-common 3.0.28

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for language-model-common 3.0.28
File Size Uploaded
language_model_common-3.0.28.tar.gz 170.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for language-model-common 3.0.28
File Interpreter ABI Platform
language_model_common-3.0.28-py3-none-any.whl Python 3 none any Details

Total release size: 398.5 kB

Release files / language_model_common-3.0.28.tar.gz

Download URL language_model_common-3.0.28.tar.gz
Size 170.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b7b17359eca4d6cb4d8500732eefc53869f6101bbc2951e6233d73f35d5972f3
BLAKE2b-256 checksum
How to use checksums
e79b6b15df475c3ff302267a2f4a3a192f30196d5e8acb3859a1dde4dee4face
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / language_model_common-3.0.28-py3-none-any.whl

Download URL language_model_common-3.0.28-py3-none-any.whl
Size 228.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77949fc716b90d10d328a15af2eb285d80493f28011ecafe5bbe8c4f3ba6fa7b
BLAKE2b-256 checksum
How to use checksums
49b4958f68d38d8ced8e0b2fd563f0977933daf0eb93fad02a5fb4700f524557
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.28 This release

2 release files

3.0.27

2 release files

3.0.26

2 release files

3.0.25

2 release files

3.0.24

2 release files

3.0.23

2 release files

3.0.22

2 release files

3.0.21

2 release files

3.0.20

2 release files

3.0.19

2 release files

3.0.18

2 release files

3.0.17

2 release files

3.0.16

2 release files

3.0.15

2 release files

3.0.14

2 release files

3.0.13

2 release files

3.0.12

2 release files

3.0.11

2 release files

3.0.10

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.99

2 release files

2.0.98

2 release files

2.0.97

2 release files

2.0.96

2 release files

2.0.95

2 release files

2.0.94

2 release files

2.0.93

2 release files

2.0.92

2 release files

2.0.91

2 release files

2.0.90

2 release files

2.0.89

2 release files

2.0.86

2 release files

2.0.85

2 release files

2.0.84

2 release files

2.0.83

2 release files

2.0.82

2 release files

2.0.81

2 release files

2.0.80

2 release files

2.0.64

2 release files

2.0.63

2 release files

2.0.62

2 release files

2.0.61

2 release files

2.0.60

2 release files

2.0.59

2 release files

2.0.58

2 release files

2.0.57

2 release files

2.0.56

2 release files

2.0.55

2 release files

2.0.54

2 release files

2.0.53

2 release files

2.0.52

2 release files

2.0.51

2 release files

2.0.50

2 release files

2.0.49

2 release files

2.0.48

2 release files

2.0.47

2 release files

2.0.46

2 release files

2.0.45

2 release files

2.0.44

2 release files

2.0.43

2 release files

2.0.42

2 release files

2.0.41

2 release files

2.0.40

2 release files

2.0.39

2 release files

2.0.38

2 release files

2.0.37

2 release files

2.0.32

2 release files

2.0.31

2 release files

2.0.30

2 release files

2.0.29

2 release files

2.0.28

2 release files

2.0.27

2 release files

2.0.26

2 release files

2.0.25

2 release files

2.0.24

2 release files

2.0.23

2 release files

2.0.22

2 release files

2.0.21

2 release files

2.0.20

2 release files

2.0.19

2 release files

2.0.18

2 release files

2.0.17

2 release files

2.0.16

2 release files

2.0.15

2 release files

2.0.14

2 release files

2.0.13

2 release files

2.0.12

2 release files

2.0.11

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.23

2 release files

1.0.22

2 release files

1.0.21

2 release files

1.0.20

2 release files

1.0.19

2 release files

1.0.18

2 release files

1.0.17

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page