A library for managing multiple LangChain model configurations with validation and automatic agent creation
Project description
LangChain Agent Config
A Python library for managing multiple LangChain model configurations with validation and automatic agent creation.
Features
- ✅ Multi-provider support: Gemini (Google), OpenAI (GPT), and Anthropic (Claude)
- ✅ Robust validation: Pydantic-based validation with custom validators
- ✅ Environment-based configuration: Support for multi-line
.envfiles - ✅ Automatic agent creation: Creates LangChain agents from configuration
- ✅ Type-safe: Full type hints and Pydantic models
- ✅ Well tested: 43+ tests with pytest
Installation
pip install langchain-agent-config
Quick Start
- Create a
.envfile in your project root:
MODELS=[
{
"name":"gemini",
"model":"gemini-2.0-flash-exp",
"temperature":0.7,
"key":"your-google-api-key",
"max_tokens":2048
},
{
"name":"gpt",
"model":"gpt-4",
"temperature":0.5,
"key":"your-openai-api-key",
"max_tokens":4096
}
]
- Use in your code:
from langchain_agent_config import ModelsEnv, read_env_file
from pathlib import Path
import json
# Load configuration
env_path = Path(".env")
env_vars = read_env_file(env_path)
raw_models = json.loads(env_vars["MODELS"])
# Validate and create models
models_env = ModelsEnv(models=raw_models)
# Create agents
agents = models_env.create_agents()
# Use the agents
response = agents['gemini'].invoke("Hello!")
response2 = agents['gpt'].invoke("Hello!")
Configuration
Model Configuration Fields
- name (str): Model identifier (must contain 'gemini', 'gpt'/'openai', or 'anthropic'/'claude')
- model (str): Specific model name from the provider
- temperature (float): Value between 0.0 and 1.0
- key (str): API key for the model provider
- max_tokens (int): Maximum number of tokens (must be positive)
Supported Providers
- Gemini: Models with "gemini" in the name
- OpenAI/GPT: Models with "gpt" or "openai" in the name
- Anthropic/Claude: Models with "anthropic" or "claude" in the name
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=backend.model
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 langchain_models_config-0.0.1.tar.gz.
File metadata
- Download URL: langchain_models_config-0.0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca77dab1b32a3a1a5063761b7e44f069ed9a68570901b854c641fcdef1545e02
|
|
| MD5 |
ecafc88f5f58839364c246a36ffbaafb
|
|
| BLAKE2b-256 |
2ee1226380fd65029fa362786ee517b4e6d0ab32069da735710926377b3a4d07
|
File details
Details for the file langchain_models_config-0.0.1-py3-none-any.whl.
File metadata
- Download URL: langchain_models_config-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f59f5377957b43a13265abc75fef1059d670753068c930d1b739c211e4b353
|
|
| MD5 |
3d06ae36b5e07329580d8a4604942b63
|
|
| BLAKE2b-256 |
47a65bd4f7cdd5a9cfb7607767027c2d32d936d338ae3c49ac55fc11467e230e
|