The bloat moat! - A lightweight LLM and Agent interaction library
Project description
🤺 Fence
The Bloat Moat! A lightweight, production-ready library for LLM communication and agentic workflows. Born from the need for something simpler than LangChain, Fence gives you powerful LLM orchestration without the heavyweight dependencies.
Think of it as the Swiss Army knife for LLM interactions—sharp, reliable, and it won't weigh down your backpack (or your Docker image).
🤔 Why Fence?
The short answer: By accident.
The slightly longer answer: LangChain used to be (is?) a pretty big package with a ton of dependencies. Great for PoCs, but in production? Not so much.
The problems we faced:
- 🐘 It's BIG. Takes up serious space (problematic in Lambda, containers, edge environments)
- 🌀 It's COMPLEX. Overwhelming for new users, hard to debug in production
- 💥 It BREAKS. Frequent breaking changes, version jumps that made us cry
As a result, many developers (especially those in large production environments) started building lightweight, custom solutions that favor stability and robustness over feature bloat.
Enter Fence 🤺
We started building basic components from scratch for our Bedrock-heavy production environment. First came the Link class (wink wink), then templates, then agents... and before we knew it, we had a miniature package that was actually fun to use.
Fence strikes the perfect balance between convenience and flexibility.
Note: Fence isn't trying to replace LangChain for complex PoCs. But if you want a simple, lightweight, production-ready package that's easy to understand and extend, you're in the right place.
📦 Installation
pip install fence-llm
That's it. Seriously. No 500MB of transitive dependencies.
🚀 Quick Start
Hello World (The Obligatory Example)
from fence.links import Link
from fence.templates.string import StringTemplate
from fence.models.openai import GPT4omini
# Create a link
link = Link(
model=GPT4omini(),
template=StringTemplate("Write a haiku about {topic}"),
name='haiku_generator'
)
# Run it
output = link.run(topic='fencing')['state']
print(output)
Output:
[2024-10-04 17:45:15] [ℹ️ INFO] [links.run:203] Executing <haiku_generator> Link
Blades flash in the light,
En garde, the dance begins now,
Touch—victory's mine.
Much wow. Very poetry. 🎭
💪 What Can Fence Do?
Fence is built around a few core concepts that work together beautifully:
🤖 Multi-Provider LLM Support
Uniform interface across AWS Bedrock (Claude, Nova), OpenAI (GPT-4o), Anthropic, Google Gemini, Ollama, and Mistral. Switch models with a single line change.
🔗 Links & Chains
Composable building blocks that combine models, templates, and parsers. Chain them together for complex workflows.
👉 Learn about Links & Chains →
🤖 Agentic Workflows ⭐
The crown jewel! Production-ready agents using the ReAct pattern:
Agent- Classic ReAct with tool use and multi-level delegationBedrockAgent- Native Bedrock tool calling with streamingChatAgent- Conversational agents for multi-agent systems
🔌 MCP Integration
First-class support for the Model Context Protocol. Connect to MCP servers and automatically expose their tools to your agents.
🎭 Multi-Agent Systems
Build collaborative agent systems with RoundTable where multiple agents discuss and solve problems together.
🧠 Memory Systems
Persistent and ephemeral memory backends (DynamoDB, SQLite, in-memory) for stateful conversations.
🛠️ Tools & Utilities
Custom tool creation, built-in tools, retry logic, parallelization, output parsers, logging callbacks, and benchmarking.
📚 Documentation
- Models - All supported LLM providers and how to use them
- Links & Chains - Building blocks for LLM workflows
- Agents - ReAct agents, tool use, and delegation
- MCP Integration - Model Context Protocol support
- Multi-Agent Systems - RoundTable and collaborative agents
- Memory - Persistent and ephemeral memory backends
- Tools & Utilities - Custom tools, parsers, and helpers
🎯 Examples
Simple Agent with Tools
from fence.agents import Agent
from fence.models.openai import GPT4omini
from fence.tools.math import CalculatorTool
agent = Agent(
identifier="math_wizard",
model=GPT4omini(source="demo"),
tools=[CalculatorTool()],
)
result = agent.run("What is 1337 * 42 + 999?")
print(result) # Agent thinks, uses calculator, and answers!
BedrockAgent with MCP
from fence.agents.bedrock import BedrockAgent
from fence.mcp.client import MCPClient
from fence.models.bedrock import Claude37Sonnet
# Connect to MCP server
mcp_client = MCPClient(
transport_type="streamable_http",
url="https://your-mcp-server.com/mcp"
)
# Create agent with MCP tools
agent = BedrockAgent(
identifier="mcp_agent",
model=Claude37Sonnet(region="us-east-1"),
mcp_clients=[mcp_client], # Tools auto-registered!
)
result = agent.run("Search for customer data")
Multi-Agent Collaboration
from fence.troupe import RoundTable
from fence.agents import ChatAgent
from fence.models.openai import GPT4omini
# Create specialized agents
detective = ChatAgent(
identifier="Detective",
model=GPT4omini(source="roundtable"),
profile="You are a sharp detective."
)
scientist = ChatAgent(
identifier="Scientist",
model=GPT4omini(source="roundtable"),
profile="You are a forensic scientist."
)
# Let them collaborate
round_table = RoundTable(agents=[detective, scientist])
transcript = round_table.run(
prompt="A painting was stolen. Let's investigate!",
max_rounds=3
)
More examples:
- 📓 Jupyter Notebooks - Interactive tutorials
- 🎬 Demo Scripts - Runnable examples
🤝 Contributing
We welcome contributions! Whether it's:
- 🐛 Bug fixes
- ✨ New features (especially new model providers!)
- 📝 Documentation improvements
- 🧪 More tests
- 🎨 Better examples
Check out CONTRIBUTING.md for guidelines.
📄 License
MIT License - see LICENSE.txt for details.
🙏 Acknowledgments
Inspired by LangChain, built for production, made with ❤️ by developers who got tired of dependency hell.
Now go build something awesome! 🚀
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 fence_llm-2.0.5.tar.gz.
File metadata
- Download URL: fence_llm-2.0.5.tar.gz
- Upload date:
- Size: 140.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d54b4e1d2f073d4f72c0c0f4f59e8532592856969c97f53370398f3d913f316b
|
|
| MD5 |
a915074c64f4f5bf49f32ab0d8e14240
|
|
| BLAKE2b-256 |
f77ca4da5602837c02f735da40ce2fffc082ef7bdd238c43c72fb207aa4cb9fb
|
Provenance
The following attestation bundles were made for fence_llm-2.0.5.tar.gz:
Publisher:
publish-pipeline.yaml on WouterDurnez/fence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fence_llm-2.0.5.tar.gz -
Subject digest:
d54b4e1d2f073d4f72c0c0f4f59e8532592856969c97f53370398f3d913f316b - Sigstore transparency entry: 630099377
- Sigstore integration time:
-
Permalink:
WouterDurnez/fence@22dcee065a783d27a4fa0347166dcffbf2580a34 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/WouterDurnez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pipeline.yaml@22dcee065a783d27a4fa0347166dcffbf2580a34 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fence_llm-2.0.5-py3-none-any.whl.
File metadata
- Download URL: fence_llm-2.0.5-py3-none-any.whl
- Upload date:
- Size: 124.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c02e499d797cc7c2f7e06568379ee38ccebb949eb242f626259f1b1e3d2c2e0
|
|
| MD5 |
c6e97adb0273f562788855c3da4cfd47
|
|
| BLAKE2b-256 |
637209514e5caddd8758f8678f98adccb0c5425095548e6330b1914961f85a71
|
Provenance
The following attestation bundles were made for fence_llm-2.0.5-py3-none-any.whl:
Publisher:
publish-pipeline.yaml on WouterDurnez/fence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fence_llm-2.0.5-py3-none-any.whl -
Subject digest:
8c02e499d797cc7c2f7e06568379ee38ccebb949eb242f626259f1b1e3d2c2e0 - Sigstore transparency entry: 630099378
- Sigstore integration time:
-
Permalink:
WouterDurnez/fence@22dcee065a783d27a4fa0347166dcffbf2580a34 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/WouterDurnez
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pipeline.yaml@22dcee065a783d27a4fa0347166dcffbf2580a34 -
Trigger Event:
workflow_dispatch
-
Statement type: