fence-llm 2.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. fence_llm-2.1.2/.gitignore +45 -0
  2. fence_llm-2.1.2/LICENSE.txt +21 -0
  3. fence_llm-2.1.2/PKG-INFO +284 -0
  4. fence_llm-2.1.2/README.md +254 -0
  5. fence_llm-2.1.2/fence/__init__.py +0 -0
  6. fence_llm-2.1.2/fence/agents/__init__.py +6 -0
  7. fence_llm-2.1.2/fence/agents/agent.py +482 -0
  8. fence_llm-2.1.2/fence/agents/base.py +200 -0
  9. fence_llm-2.1.2/fence/agents/bedrock/__init__.py +3 -0
  10. fence_llm-2.1.2/fence/agents/bedrock/agent.py +1206 -0
  11. fence_llm-2.1.2/fence/agents/bedrock/models.py +210 -0
  12. fence_llm-2.1.2/fence/agents/chat.py +125 -0
  13. fence_llm-2.1.2/fence/benchmark/prompts.py +107 -0
  14. fence_llm-2.1.2/fence/benchmark/run.py +227 -0
  15. fence_llm-2.1.2/fence/chains.py +268 -0
  16. fence_llm-2.1.2/fence/embeddings/base.py +104 -0
  17. fence_llm-2.1.2/fence/embeddings/bedrock/__init__.py +14 -0
  18. fence_llm-2.1.2/fence/embeddings/bedrock/base.py +173 -0
  19. fence_llm-2.1.2/fence/embeddings/bedrock/nova.py +253 -0
  20. fence_llm-2.1.2/fence/embeddings/bedrock/titan.py +216 -0
  21. fence_llm-2.1.2/fence/embeddings/google/__init__.py +7 -0
  22. fence_llm-2.1.2/fence/embeddings/google/gemini.py +168 -0
  23. fence_llm-2.1.2/fence/embeddings/mistral/__init__.py +0 -0
  24. fence_llm-2.1.2/fence/embeddings/mistral/mistral.py +96 -0
  25. fence_llm-2.1.2/fence/embeddings/ollama/ollama.py +156 -0
  26. fence_llm-2.1.2/fence/embeddings/openai/openai.py +101 -0
  27. fence_llm-2.1.2/fence/links.py +278 -0
  28. fence_llm-2.1.2/fence/mcp/client.py +338 -0
  29. fence_llm-2.1.2/fence/mcp/tool.py +152 -0
  30. fence_llm-2.1.2/fence/mcp/utils.py +63 -0
  31. fence_llm-2.1.2/fence/memory/__init__.py +6 -0
  32. fence_llm-2.1.2/fence/memory/agentcore.py +121 -0
  33. fence_llm-2.1.2/fence/memory/base.py +266 -0
  34. fence_llm-2.1.2/fence/memory/dynamodb.py +335 -0
  35. fence_llm-2.1.2/fence/memory/sqlite.py +76 -0
  36. fence_llm-2.1.2/fence/models/__init__.py +32 -0
  37. fence_llm-2.1.2/fence/models/anthropic/__init__.py +15 -0
  38. fence_llm-2.1.2/fence/models/anthropic/claude.py +428 -0
  39. fence_llm-2.1.2/fence/models/base.py +213 -0
  40. fence_llm-2.1.2/fence/models/bedrock/__init__.py +25 -0
  41. fence_llm-2.1.2/fence/models/bedrock/base.py +545 -0
  42. fence_llm-2.1.2/fence/models/bedrock/claude.py +305 -0
  43. fence_llm-2.1.2/fence/models/bedrock/nova.py +290 -0
  44. fence_llm-2.1.2/fence/models/gemini/__init__.py +21 -0
  45. fence_llm-2.1.2/fence/models/gemini/gemini.py +256 -0
  46. fence_llm-2.1.2/fence/models/mistral/__init__.py +0 -0
  47. fence_llm-2.1.2/fence/models/mistral/mistral.py +218 -0
  48. fence_llm-2.1.2/fence/models/ollama/__init__.py +3 -0
  49. fence_llm-2.1.2/fence/models/ollama/ollama.py +268 -0
  50. fence_llm-2.1.2/fence/models/openai/__init__.py +3 -0
  51. fence_llm-2.1.2/fence/models/openai/gpt.py +254 -0
  52. fence_llm-2.1.2/fence/parsers.py +262 -0
  53. fence_llm-2.1.2/fence/prompts/agents.py +137 -0
  54. fence_llm-2.1.2/fence/streaming/base.py +581 -0
  55. fence_llm-2.1.2/fence/templates/__init__.py +2 -0
  56. fence_llm-2.1.2/fence/templates/base.py +183 -0
  57. fence_llm-2.1.2/fence/templates/messages.py +209 -0
  58. fence_llm-2.1.2/fence/templates/models.py +611 -0
  59. fence_llm-2.1.2/fence/templates/string.py +108 -0
  60. fence_llm-2.1.2/fence/tools/base.py +558 -0
  61. fence_llm-2.1.2/fence/tools/math.py +80 -0
  62. fence_llm-2.1.2/fence/tools/scratch.py +23 -0
  63. fence_llm-2.1.2/fence/tools/text.py +15 -0
  64. fence_llm-2.1.2/fence/troupe/round_table.py +167 -0
  65. fence_llm-2.1.2/fence/utils/__init__.py +0 -0
  66. fence_llm-2.1.2/fence/utils/base.py +113 -0
  67. fence_llm-2.1.2/fence/utils/docstring_parser.py +227 -0
  68. fence_llm-2.1.2/fence/utils/logger.py +131 -0
  69. fence_llm-2.1.2/fence/utils/nlp.py +243 -0
  70. fence_llm-2.1.2/fence/utils/optim.py +170 -0
  71. fence_llm-2.1.2/fence/utils/shortcuts.py +186 -0
  72. fence_llm-2.1.2/pyproject.toml +95 -0
  73. fence_llm-2.1.2/tests/__init__.py +0 -0
  74. fence_llm-2.1.2/tests/agents/__init__.py +0 -0
  75. fence_llm-2.1.2/tests/agents/test_base_agent.py +122 -0
  76. fence_llm-2.1.2/tests/agents/test_bedrock_agent.py +933 -0
  77. fence_llm-2.1.2/tests/agents/test_react_agent.py +428 -0
  78. fence_llm-2.1.2/tests/embeddings/bedrock/test_bedrock_embed.py +101 -0
  79. fence_llm-2.1.2/tests/embeddings/google/test_google_embed.py +147 -0
  80. fence_llm-2.1.2/tests/embeddings/mistral/test_mistral_embed.py +71 -0
  81. fence_llm-2.1.2/tests/embeddings/ollama/test_ollama_embed.py +76 -0
  82. fence_llm-2.1.2/tests/embeddings/openai/test_openai_embed.py +88 -0
  83. fence_llm-2.1.2/tests/integration/test_image_call.py +83 -0
  84. fence_llm-2.1.2/tests/integration/test_mcp_bedrock_integration.py +435 -0
  85. fence_llm-2.1.2/tests/integration/test_tool_calling.py +414 -0
  86. fence_llm-2.1.2/tests/memory/test_agentcore.py +305 -0
  87. fence_llm-2.1.2/tests/memory/test_dynamodb.py +233 -0
  88. fence_llm-2.1.2/tests/memory/test_memory_base.py +151 -0
  89. fence_llm-2.1.2/tests/memory/test_sqlite.py +38 -0
  90. fence_llm-2.1.2/tests/models/anthropic/test_claude.py +107 -0
  91. fence_llm-2.1.2/tests/models/bedrock/test_bedrock_base.py +1095 -0
  92. fence_llm-2.1.2/tests/models/bedrock/test_nova_models.py +212 -0
  93. fence_llm-2.1.2/tests/models/gemini/test_gemini_1_5_pro.py +39 -0
  94. fence_llm-2.1.2/tests/models/gemini/test_gemini_2_5_flash.py +41 -0
  95. fence_llm-2.1.2/tests/models/gemini/test_gemini_2_5_flash_lite.py +37 -0
  96. fence_llm-2.1.2/tests/models/gemini/test_gemini_2_5_pro.py +41 -0
  97. fence_llm-2.1.2/tests/models/gemini/test_gemini_base.py +92 -0
  98. fence_llm-2.1.2/tests/models/gemini/test_gemini_flash_1_5.py +39 -0
  99. fence_llm-2.1.2/tests/models/gemini/test_gemini_flash_2_0.py +39 -0
  100. fence_llm-2.1.2/tests/models/mistral/test_mistral.py +217 -0
  101. fence_llm-2.1.2/tests/models/ollama/test_ollama.py +124 -0
  102. fence_llm-2.1.2/tests/models/openai/test_gpt.py +102 -0
  103. fence_llm-2.1.2/tests/templates/test_messages.py +303 -0
  104. fence_llm-2.1.2/tests/templates/test_models.py +151 -0
  105. fence_llm-2.1.2/tests/templates/test_string.py +135 -0
  106. fence_llm-2.1.2/tests/test_chains.py +53 -0
  107. fence_llm-2.1.2/tests/test_links.py +38 -0
  108. fence_llm-2.1.2/tests/test_parsers.py +77 -0
  109. fence_llm-2.1.2/tests/tools/test_mcp_client.py +299 -0
  110. fence_llm-2.1.2/tests/tools/test_mcp_tool.py +227 -0
  111. fence_llm-2.1.2/tests/tools/test_tool_base.py +944 -0
  112. fence_llm-2.1.2/tests/utils/test_docstring_parser.py +358 -0
  113. fence_llm-2.1.2/tests/utils/test_nlp.py +203 -0
  114. fence_llm-2.1.2/tests/utils/test_optim.py +310 -0
  115. fence_llm-2.1.2/tests/utils/test_shortcuts.py +100 -0
  116. fence_llm-2.1.2/tests/utils/test_utils_base.py +42 -0
@@ -0,0 +1,45 @@
1
+ # Virtual environments
2
+ .venv
3
+ venv
4
+
5
+ # Cache files
6
+ *.pyc
7
+ __pycache__/
8
+ .ruff_cache/
9
+
10
+ # Pycache files
11
+ .idea
12
+
13
+ # System files
14
+ .DS_Store
15
+
16
+ # Requirements base file
17
+ /requirements.in
18
+
19
+ # Local env file
20
+ /.env
21
+
22
+ # Local data files
23
+ /data/
24
+
25
+ # Local playground files
26
+ /playground/
27
+
28
+ # Distribution files
29
+ /dist/
30
+ /*.egg-info/
31
+
32
+ # Raw docs
33
+ /docs/*.ai
34
+
35
+ # Notebook checkpoints
36
+ .ipynb_checkpoints/
37
+
38
+ # Pytest coverage
39
+ .coverage
40
+
41
+ # Figures folders
42
+ **/figures/
43
+
44
+ # Demo files
45
+ demo/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2024] [Wouter Durnez]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,284 @@
1
+ Metadata-Version: 2.4
2
+ Name: fence-llm
3
+ Version: 2.1.2
4
+ Summary: The bloat moat! - A lightweight LLM and Agent interaction library
5
+ Project-URL: Repository, https://github.com/WouterDurnez/fence
6
+ Project-URL: Homepage, https://github.com/WouterDurnez/fence
7
+ Project-URL: Documentation, https://github.com/WouterDurnez/fence
8
+ Author-email: "wouter.durnez" <wouter.durnez@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE.txt
11
+ Keywords: ai,anthropic,api,claude,fence,gpt,language,llm,model,nlp,openai,wrapper
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: Implementation :: CPython
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Classifier: Topic :: Software Development
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: boto3>=1.34.100
25
+ Requires-Dist: mcp>=1.9.4
26
+ Requires-Dist: numexpr>=2.10.1
27
+ Requires-Dist: pydantic>=2.11.4
28
+ Requires-Dist: requests>=2.32.3
29
+ Description-Content-Type: text/markdown
30
+
31
+ <img src="https://github.com/WouterDurnez/fence/blob/main/docs/logo.png?raw=true" alt="tests" height="200"/>
32
+
33
+ [![Python](https://img.shields.io/pypi/pyversions/fence-llm)](https://pypi.org/project/fence-llm/)
34
+ [![Test Status](https://github.com/WouterDurnez/fence/actions/workflows/ci-pipeline.yaml/badge.svg)](https://github.com/WouterDurnez/fence/actions)
35
+ [![codecov](https://codecov.io/gh/WouterDurnez/fence/branch/main/graph/badge.svg?token=QZQZQZQZQZ)](https://codecov.io/gh/WouterDurnez/fence)
36
+ [![PyPI version](https://badge.fury.io/py/fence-llm.svg)](https://badge.fury.io/py/fence-llm)
37
+ [![Documentation Status](https://readthedocs.org/projects/fence-llm/badge/?version=latest)](https://fence-llm.readthedocs.io/en/latest/?badge=latest)
38
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
39
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
41
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
42
+
43
+ # ๐Ÿคบ Fence
44
+
45
+ **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.
46
+
47
+ 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).
48
+
49
+ ---
50
+
51
+ ## ๐Ÿค” Why Fence?
52
+
53
+ **The short answer:** By accident.
54
+
55
+ **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.
56
+
57
+ ### The problems we faced:
58
+
59
+ - **๐Ÿ˜ It's BIG.** Takes up serious space (problematic in Lambda, containers, edge environments)
60
+ - **๐ŸŒ€ It's COMPLEX.** Overwhelming for new users, hard to debug in production
61
+ - **๐Ÿ’ฅ It BREAKS.** Frequent breaking changes, version jumps that made us cry
62
+
63
+ As a result, many developers (especially those in large production environments) started building lightweight, custom solutions that favor **stability** and **robustness** over feature bloat.
64
+
65
+ ### Enter Fence ๐Ÿคบ
66
+
67
+ 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.
68
+
69
+ **Fence strikes the perfect balance between convenience and flexibility.**
70
+
71
+ > **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.
72
+
73
+ ---
74
+
75
+ ## ๐Ÿ“ฆ Installation
76
+
77
+ ```bash
78
+ pip install fence-llm
79
+ ```
80
+
81
+ That's it. Seriously. No 500MB of transitive dependencies.
82
+
83
+ ---
84
+
85
+ ## ๐Ÿš€ Quick Start
86
+
87
+ ### Hello World (The Obligatory Example)
88
+
89
+ ```python
90
+ from fence.links import Link
91
+ from fence.templates.string import StringTemplate
92
+ from fence.models.openai import GPT4omini
93
+
94
+ # Create a link
95
+ link = Link(
96
+ model=GPT4omini(),
97
+ template=StringTemplate("Write a haiku about {topic}"),
98
+ name='haiku_generator'
99
+ )
100
+
101
+ # Run it
102
+ output = link.run(topic='fencing')['state']
103
+ print(output)
104
+ ```
105
+
106
+ **Output:**
107
+
108
+ ```
109
+ [2024-10-04 17:45:15] [โ„น๏ธ INFO] [links.run:203] Executing <haiku_generator> Link
110
+ Blades flash in the light,
111
+ En garde, the dance begins now,
112
+ Touchโ€”victory's mine.
113
+ ```
114
+
115
+ Much wow. Very poetry. ๐ŸŽญ
116
+
117
+ ---
118
+
119
+ ## ๐Ÿ’ช What Can Fence Do?
120
+
121
+ Fence is built around a few core concepts that work together beautifully:
122
+
123
+ ### ๐Ÿค– **Multi-Provider LLM Support**
124
+
125
+ Uniform interface across AWS Bedrock (Claude, Nova), OpenAI (GPT-4o), Anthropic, Google Gemini, Ollama, and Mistral. Switch models with a single line change.
126
+
127
+ ๐Ÿ‘‰ **[See all supported models โ†’](docs/MODELS.md)**
128
+
129
+ ### ๐Ÿ”— **Links & Chains**
130
+
131
+ Composable building blocks that combine models, templates, and parsers. Chain them together for complex workflows.
132
+
133
+ ๐Ÿ‘‰ **[Learn about Links & Chains โ†’](docs/LINKS_AND_CHAINS.md)**
134
+
135
+ ### ๐Ÿค– **Agentic Workflows** โญ
136
+
137
+ The crown jewel! Production-ready agents using the ReAct pattern:
138
+
139
+ - **`Agent`** - Classic ReAct with tool use and multi-level delegation
140
+ - **`BedrockAgent`** - Native Bedrock tool calling with streaming
141
+ - **`ChatAgent`** - Conversational agents for multi-agent systems
142
+
143
+ ๐Ÿ‘‰ **[Dive into Agents โ†’](docs/AGENTS.md)**
144
+
145
+ ### ๐Ÿ”Œ **MCP Integration**
146
+
147
+ First-class support for the Model Context Protocol. Connect to MCP servers and automatically expose their tools to your agents.
148
+
149
+ ๐Ÿ‘‰ **[Explore MCP Integration โ†’](docs/MCP.md)**
150
+
151
+ ### ๐ŸŽญ **Multi-Agent Systems**
152
+
153
+ Build collaborative agent systems with `RoundTable` where multiple agents discuss and solve problems together.
154
+
155
+ ๐Ÿ‘‰ **[Build Multi-Agent Systems โ†’](docs/MULTI_AGENT.md)**
156
+
157
+ ### ๐Ÿง  **Memory Systems**
158
+
159
+ Persistent and ephemeral memory backends (DynamoDB, SQLite, in-memory) for stateful conversations.
160
+
161
+ ๐Ÿ‘‰ **[Configure Memory โ†’](docs/MEMORY.md)**
162
+
163
+ ### ๐Ÿ› ๏ธ **Tools & Utilities**
164
+
165
+ Custom tool creation, built-in tools, retry logic, parallelization, output parsers, logging callbacks, and benchmarking.
166
+
167
+ ๐Ÿ‘‰ **[Explore Tools & Utilities โ†’](docs/TOOLS_AND_UTILITIES.md)**
168
+
169
+ ---
170
+
171
+ ## ๐Ÿ“š Documentation
172
+
173
+ - **[Models](docs/MODELS.md)** - All supported LLM providers and how to use them
174
+ - **[Links & Chains](docs/LINKS_AND_CHAINS.md)** - Building blocks for LLM workflows
175
+ - **[Agents](docs/AGENTS.md)** - ReAct agents, tool use, and delegation
176
+ - **[MCP Integration](docs/MCP.md)** - Model Context Protocol support
177
+ - **[Multi-Agent Systems](docs/MULTI_AGENT.md)** - RoundTable and collaborative agents
178
+ - **[Memory](docs/MEMORY.md)** - Persistent and ephemeral memory backends
179
+ - **[Tools & Utilities](docs/TOOLS_AND_UTILITIES.md)** - Custom tools, parsers, and helpers
180
+
181
+ ---
182
+
183
+ ## ๐ŸŽฏ Examples
184
+
185
+ ### Simple Agent with Tools
186
+
187
+ ```python
188
+ from fence.agents import Agent
189
+ from fence.models.openai import GPT4omini
190
+ from fence.tools.math import CalculatorTool
191
+
192
+ agent = Agent(
193
+ identifier="math_wizard",
194
+ model=GPT4omini(source="demo"),
195
+ tools=[CalculatorTool()],
196
+ )
197
+
198
+ result = agent.run("What is 1337 * 42 + 999?")
199
+ print(result) # Agent thinks, uses calculator, and answers!
200
+ ```
201
+
202
+ ### BedrockAgent with MCP
203
+
204
+ ```python
205
+ from fence.agents.bedrock import BedrockAgent
206
+ from fence.mcp.client import MCPClient
207
+ from fence.models.bedrock import Claude37Sonnet
208
+
209
+ # Connect to MCP server
210
+ mcp_client = MCPClient(
211
+ transport_type="streamable_http",
212
+ url="https://your-mcp-server.com/mcp"
213
+ )
214
+
215
+ # Create agent with MCP tools
216
+ agent = BedrockAgent(
217
+ identifier="mcp_agent",
218
+ model=Claude37Sonnet(region="us-east-1"),
219
+ mcp_clients=[mcp_client], # Tools auto-registered!
220
+ )
221
+
222
+ result = agent.run("Search for customer data")
223
+ ```
224
+
225
+ ### Multi-Agent Collaboration
226
+
227
+ ```python
228
+ from fence.troupe import RoundTable
229
+ from fence.agents import ChatAgent
230
+ from fence.models.openai import GPT4omini
231
+
232
+ # Create specialized agents
233
+ detective = ChatAgent(
234
+ identifier="Detective",
235
+ model=GPT4omini(source="roundtable"),
236
+ profile="You are a sharp detective."
237
+ )
238
+
239
+ scientist = ChatAgent(
240
+ identifier="Scientist",
241
+ model=GPT4omini(source="roundtable"),
242
+ profile="You are a forensic scientist."
243
+ )
244
+
245
+ # Let them collaborate
246
+ round_table = RoundTable(agents=[detective, scientist])
247
+ transcript = round_table.run(
248
+ prompt="A painting was stolen. Let's investigate!",
249
+ max_rounds=3
250
+ )
251
+ ```
252
+
253
+ **More examples:**
254
+
255
+ - ๐Ÿ““ [Jupyter Notebooks](notebooks/) - Interactive tutorials
256
+ - ๐ŸŽฌ [Demo Scripts](demo/) - Runnable examples
257
+
258
+ ---
259
+
260
+ ## ๐Ÿค Contributing
261
+
262
+ We welcome contributions! Whether it's:
263
+
264
+ - ๐Ÿ› Bug fixes
265
+ - โœจ New features (especially new model providers!)
266
+ - ๐Ÿ“ Documentation improvements
267
+ - ๐Ÿงช More tests
268
+ - ๐ŸŽจ Better examples
269
+
270
+ Check out [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
271
+
272
+ ---
273
+
274
+ ## ๐Ÿ“„ License
275
+
276
+ MIT License - see [LICENSE.txt](LICENSE.txt) for details.
277
+
278
+ ---
279
+
280
+ ## ๐Ÿ™ Acknowledgments
281
+
282
+ Inspired by LangChain, built for production, made with โค๏ธ by developers who got tired of dependency hell.
283
+
284
+ **Now go build something awesome! ๐Ÿš€**
@@ -0,0 +1,254 @@
1
+ <img src="https://github.com/WouterDurnez/fence/blob/main/docs/logo.png?raw=true" alt="tests" height="200"/>
2
+
3
+ [![Python](https://img.shields.io/pypi/pyversions/fence-llm)](https://pypi.org/project/fence-llm/)
4
+ [![Test Status](https://github.com/WouterDurnez/fence/actions/workflows/ci-pipeline.yaml/badge.svg)](https://github.com/WouterDurnez/fence/actions)
5
+ [![codecov](https://codecov.io/gh/WouterDurnez/fence/branch/main/graph/badge.svg?token=QZQZQZQZQZ)](https://codecov.io/gh/WouterDurnez/fence)
6
+ [![PyPI version](https://badge.fury.io/py/fence-llm.svg)](https://badge.fury.io/py/fence-llm)
7
+ [![Documentation Status](https://readthedocs.org/projects/fence-llm/badge/?version=latest)](https://fence-llm.readthedocs.io/en/latest/?badge=latest)
8
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
9
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
11
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](code_of_conduct.md)
12
+
13
+ # ๐Ÿคบ Fence
14
+
15
+ **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.
16
+
17
+ 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).
18
+
19
+ ---
20
+
21
+ ## ๐Ÿค” Why Fence?
22
+
23
+ **The short answer:** By accident.
24
+
25
+ **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.
26
+
27
+ ### The problems we faced:
28
+
29
+ - **๐Ÿ˜ It's BIG.** Takes up serious space (problematic in Lambda, containers, edge environments)
30
+ - **๐ŸŒ€ It's COMPLEX.** Overwhelming for new users, hard to debug in production
31
+ - **๐Ÿ’ฅ It BREAKS.** Frequent breaking changes, version jumps that made us cry
32
+
33
+ As a result, many developers (especially those in large production environments) started building lightweight, custom solutions that favor **stability** and **robustness** over feature bloat.
34
+
35
+ ### Enter Fence ๐Ÿคบ
36
+
37
+ 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.
38
+
39
+ **Fence strikes the perfect balance between convenience and flexibility.**
40
+
41
+ > **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.
42
+
43
+ ---
44
+
45
+ ## ๐Ÿ“ฆ Installation
46
+
47
+ ```bash
48
+ pip install fence-llm
49
+ ```
50
+
51
+ That's it. Seriously. No 500MB of transitive dependencies.
52
+
53
+ ---
54
+
55
+ ## ๐Ÿš€ Quick Start
56
+
57
+ ### Hello World (The Obligatory Example)
58
+
59
+ ```python
60
+ from fence.links import Link
61
+ from fence.templates.string import StringTemplate
62
+ from fence.models.openai import GPT4omini
63
+
64
+ # Create a link
65
+ link = Link(
66
+ model=GPT4omini(),
67
+ template=StringTemplate("Write a haiku about {topic}"),
68
+ name='haiku_generator'
69
+ )
70
+
71
+ # Run it
72
+ output = link.run(topic='fencing')['state']
73
+ print(output)
74
+ ```
75
+
76
+ **Output:**
77
+
78
+ ```
79
+ [2024-10-04 17:45:15] [โ„น๏ธ INFO] [links.run:203] Executing <haiku_generator> Link
80
+ Blades flash in the light,
81
+ En garde, the dance begins now,
82
+ Touchโ€”victory's mine.
83
+ ```
84
+
85
+ Much wow. Very poetry. ๐ŸŽญ
86
+
87
+ ---
88
+
89
+ ## ๐Ÿ’ช What Can Fence Do?
90
+
91
+ Fence is built around a few core concepts that work together beautifully:
92
+
93
+ ### ๐Ÿค– **Multi-Provider LLM Support**
94
+
95
+ Uniform interface across AWS Bedrock (Claude, Nova), OpenAI (GPT-4o), Anthropic, Google Gemini, Ollama, and Mistral. Switch models with a single line change.
96
+
97
+ ๐Ÿ‘‰ **[See all supported models โ†’](docs/MODELS.md)**
98
+
99
+ ### ๐Ÿ”— **Links & Chains**
100
+
101
+ Composable building blocks that combine models, templates, and parsers. Chain them together for complex workflows.
102
+
103
+ ๐Ÿ‘‰ **[Learn about Links & Chains โ†’](docs/LINKS_AND_CHAINS.md)**
104
+
105
+ ### ๐Ÿค– **Agentic Workflows** โญ
106
+
107
+ The crown jewel! Production-ready agents using the ReAct pattern:
108
+
109
+ - **`Agent`** - Classic ReAct with tool use and multi-level delegation
110
+ - **`BedrockAgent`** - Native Bedrock tool calling with streaming
111
+ - **`ChatAgent`** - Conversational agents for multi-agent systems
112
+
113
+ ๐Ÿ‘‰ **[Dive into Agents โ†’](docs/AGENTS.md)**
114
+
115
+ ### ๐Ÿ”Œ **MCP Integration**
116
+
117
+ First-class support for the Model Context Protocol. Connect to MCP servers and automatically expose their tools to your agents.
118
+
119
+ ๐Ÿ‘‰ **[Explore MCP Integration โ†’](docs/MCP.md)**
120
+
121
+ ### ๐ŸŽญ **Multi-Agent Systems**
122
+
123
+ Build collaborative agent systems with `RoundTable` where multiple agents discuss and solve problems together.
124
+
125
+ ๐Ÿ‘‰ **[Build Multi-Agent Systems โ†’](docs/MULTI_AGENT.md)**
126
+
127
+ ### ๐Ÿง  **Memory Systems**
128
+
129
+ Persistent and ephemeral memory backends (DynamoDB, SQLite, in-memory) for stateful conversations.
130
+
131
+ ๐Ÿ‘‰ **[Configure Memory โ†’](docs/MEMORY.md)**
132
+
133
+ ### ๐Ÿ› ๏ธ **Tools & Utilities**
134
+
135
+ Custom tool creation, built-in tools, retry logic, parallelization, output parsers, logging callbacks, and benchmarking.
136
+
137
+ ๐Ÿ‘‰ **[Explore Tools & Utilities โ†’](docs/TOOLS_AND_UTILITIES.md)**
138
+
139
+ ---
140
+
141
+ ## ๐Ÿ“š Documentation
142
+
143
+ - **[Models](docs/MODELS.md)** - All supported LLM providers and how to use them
144
+ - **[Links & Chains](docs/LINKS_AND_CHAINS.md)** - Building blocks for LLM workflows
145
+ - **[Agents](docs/AGENTS.md)** - ReAct agents, tool use, and delegation
146
+ - **[MCP Integration](docs/MCP.md)** - Model Context Protocol support
147
+ - **[Multi-Agent Systems](docs/MULTI_AGENT.md)** - RoundTable and collaborative agents
148
+ - **[Memory](docs/MEMORY.md)** - Persistent and ephemeral memory backends
149
+ - **[Tools & Utilities](docs/TOOLS_AND_UTILITIES.md)** - Custom tools, parsers, and helpers
150
+
151
+ ---
152
+
153
+ ## ๐ŸŽฏ Examples
154
+
155
+ ### Simple Agent with Tools
156
+
157
+ ```python
158
+ from fence.agents import Agent
159
+ from fence.models.openai import GPT4omini
160
+ from fence.tools.math import CalculatorTool
161
+
162
+ agent = Agent(
163
+ identifier="math_wizard",
164
+ model=GPT4omini(source="demo"),
165
+ tools=[CalculatorTool()],
166
+ )
167
+
168
+ result = agent.run("What is 1337 * 42 + 999?")
169
+ print(result) # Agent thinks, uses calculator, and answers!
170
+ ```
171
+
172
+ ### BedrockAgent with MCP
173
+
174
+ ```python
175
+ from fence.agents.bedrock import BedrockAgent
176
+ from fence.mcp.client import MCPClient
177
+ from fence.models.bedrock import Claude37Sonnet
178
+
179
+ # Connect to MCP server
180
+ mcp_client = MCPClient(
181
+ transport_type="streamable_http",
182
+ url="https://your-mcp-server.com/mcp"
183
+ )
184
+
185
+ # Create agent with MCP tools
186
+ agent = BedrockAgent(
187
+ identifier="mcp_agent",
188
+ model=Claude37Sonnet(region="us-east-1"),
189
+ mcp_clients=[mcp_client], # Tools auto-registered!
190
+ )
191
+
192
+ result = agent.run("Search for customer data")
193
+ ```
194
+
195
+ ### Multi-Agent Collaboration
196
+
197
+ ```python
198
+ from fence.troupe import RoundTable
199
+ from fence.agents import ChatAgent
200
+ from fence.models.openai import GPT4omini
201
+
202
+ # Create specialized agents
203
+ detective = ChatAgent(
204
+ identifier="Detective",
205
+ model=GPT4omini(source="roundtable"),
206
+ profile="You are a sharp detective."
207
+ )
208
+
209
+ scientist = ChatAgent(
210
+ identifier="Scientist",
211
+ model=GPT4omini(source="roundtable"),
212
+ profile="You are a forensic scientist."
213
+ )
214
+
215
+ # Let them collaborate
216
+ round_table = RoundTable(agents=[detective, scientist])
217
+ transcript = round_table.run(
218
+ prompt="A painting was stolen. Let's investigate!",
219
+ max_rounds=3
220
+ )
221
+ ```
222
+
223
+ **More examples:**
224
+
225
+ - ๐Ÿ““ [Jupyter Notebooks](notebooks/) - Interactive tutorials
226
+ - ๐ŸŽฌ [Demo Scripts](demo/) - Runnable examples
227
+
228
+ ---
229
+
230
+ ## ๐Ÿค Contributing
231
+
232
+ We welcome contributions! Whether it's:
233
+
234
+ - ๐Ÿ› Bug fixes
235
+ - โœจ New features (especially new model providers!)
236
+ - ๐Ÿ“ Documentation improvements
237
+ - ๐Ÿงช More tests
238
+ - ๐ŸŽจ Better examples
239
+
240
+ Check out [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
241
+
242
+ ---
243
+
244
+ ## ๐Ÿ“„ License
245
+
246
+ MIT License - see [LICENSE.txt](LICENSE.txt) for details.
247
+
248
+ ---
249
+
250
+ ## ๐Ÿ™ Acknowledgments
251
+
252
+ Inspired by LangChain, built for production, made with โค๏ธ by developers who got tired of dependency hell.
253
+
254
+ **Now go build something awesome! ๐Ÿš€**
File without changes
@@ -0,0 +1,6 @@
1
+ from .agent import Agent
2
+ from .base import BaseAgent
3
+ from .bedrock.agent import BedrockAgent
4
+ from .chat import ChatAgent
5
+
6
+ __all__ = ["BaseAgent", "Agent", "ChatAgent", "BedrockAgent"]