lc-agent-factory
A thin, config-driven wrapper around LangChain's create_agent.
Our create_agent(config, **kwargs) accepts an additional config parameter on top of LangChain's create_agent's keyword arguments — letting you declare complex object arguments (e.g. model, middleware, tools) in a plain dict or external file, instead of wiring them in code. The returned agent is exactly what create_agent returns. No magic, no lock-in.
Note: Not all
create_agentparameters are configurable yet — pass unsupported ones directly askwargs. When a parameter appears in both,kwargstake priority for scalar values, while lists are merged.
from lc_agent_factory import create_agent
agent = create_agent(config) # config is just a dict
create_agent() accepts a plain dict. Load it however fits your stack — YAML file, JSON, environment variable, database, or constructed directly in code.
Install
pip install lc-agent-factory
Then install your LLM provider:
pip install langchain-openai # OpenAI
pip install langchain-anthropic # Anthropic
pip install langchain-google-genai # Google GenAI
# see https://python.langchain.com/docs/integrations/chat/ for all providers
Quickstart
1. Create a config file:
# config.yaml
models:
primary:
model_provider: google_genai
model: gemini-2.5-flash
temperature: 0
middleware:
prebuilt:
- ModelCallLimitMiddleware:
run_limit: 10
exit_behavior: 'end'
2. Set your API key:
export GOOGLE_API_KEY="..."
3. Run:
import yaml
from lc_agent_factory import create_agent
agent = create_agent(yaml.safe_load(open("config.yaml")))
res = agent.invoke({"messages": [ {"role": "user", "content": "Hello!"} ]})
print(res["messages"][-1].content)
Configuration reference
globals (optional)
globals:
set_debug: false # default: false
set_verbose: false # default: false
models
Named model configurations. primary is required. Any additional models (e.g. fallback) are referenced by name in middleware.
models:
primary:
model_provider: openai # any init_chat_model provider
model: gpt-4o
temperature: 0
timeout: 60
fallback:
model_provider: openai
model: gpt-4o-mini
temperature: 0
All keys under a model entry are passed as-is to LangChain's init_chat_model — refer to its docs for available options per provider.
middleware.prebuilt (optional)
A list of LangChain built-in middleware. Each entry is a single-key dict: {MiddlewareClassName: {kwargs}}.
middleware:
prebuilt:
# Stop after N model calls
- ModelCallLimitMiddleware:
run_limit: 10
exit_behavior: 'end'
# Stop after N total tool calls
- ToolCallLimitMiddleware:
run_limit: 20
# Per-tool call limit
- ToolCallLimitMiddleware:
tool_name: 'web_search'
run_limit: 5
# Retry failed model calls
- ModelRetryMiddleware:
max_retries: 3
backoff_factor: 2.0
initial_delay: 1.0
# Retry failed tool calls
- ToolRetryMiddleware:
max_retries: 2
backoff_factor: 2.0
initial_delay: 1.0
# Automatically switch to fallback model on failure.
# first_model defaults to 'fallback' when that model is declared.
# additional_models (optional) are tried in order after it;
# an unknown name there raises at build.
- ModelFallbackMiddleware:
first_model: 'fallback'
additional_models: ['fallback_2']
# Trim old tool messages when context grows too large
- ContextEditingMiddleware:
token_count_method: 'approximate'
edits:
- ClearToolUsesEdit:
trigger: 50000
keep: 3
clear_tool_inputs: false
placeholder: '[cleared]'
Kwargs are passed as-is to LangChain middleware constructors — refer to LangChain middleware docs for the full list and options.
middleware.custom (optional)
Same structure as middleware.prebuilt, for your own AgentMiddleware subclasses.
Adding tools
Pass tools at call time — they are merged and deduplicated with any tools returned by internal loaders:
from langchain.tools import tool
@tool
def web_search(query: str) -> str:
"""Search the web."""
...
agent = create_agent(config, tools=[web_search])
Async
The returned agent is a compiled LangGraph and supports all four invocation modes out of the box:
# sync
agent.invoke({"messages": [...]})
# async
await agent.ainvoke({"messages": [...]})
# streaming
for chunk in agent.stream({"messages": [...]}):
print(chunk)
# async streaming
async for chunk in agent.astream({"messages": [...])):
print(chunk)
License
MIT — free to use for any purpose, personal or commercial. See LICENSE.
Metadata
Release files for lc-agent-factory 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lc_agent_factory-0.1.3.tar.gz | 108.7 kB | Without provenance | Details for lc_agent_factory-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lc_agent_factory-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for lc_agent_factory-0.1.3-py3-none-any.whl |
Total release size: 120.4 kB
Release files / lc_agent_factory-0.1.3.tar.gz
| Download URL | lc_agent_factory-0.1.3.tar.gz |
|---|---|
| Size | 108.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60e588250d957929c38cb33ae5a86bb38a572832cf7a86b736ebeb1853267889
|
|
BLAKE2b-256 checksum How to use checksums |
52c539e64b5025f3e23d44475f180c2540e3fb11822f17add099873ce6a65be2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.4
|
Release files / lc_agent_factory-0.1.3-py3-none-any.whl
| Download URL | lc_agent_factory-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c34a188b4c337601143dac12d0d7edd435648521a8bde6702e4fc06e97eaef43
|
|
BLAKE2b-256 checksum How to use checksums |
ebd15625cf4d1156eaf2c14059b63ffd19641716309533bfc20d31638c1d945b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.4
|
Security for lc-agent-factory 0.1.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.