enterprise-agentic-ai-framework 0.1.0__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.
- enterprise_agentic_ai_framework-0.1.0/.gitignore +41 -0
- enterprise_agentic_ai_framework-0.1.0/CHANGELOG.md +0 -0
- enterprise_agentic_ai_framework-0.1.0/CONTRIBUTING.md +0 -0
- enterprise_agentic_ai_framework-0.1.0/LICENSE +201 -0
- enterprise_agentic_ai_framework-0.1.0/PKG-INFO +23 -0
- enterprise_agentic_ai_framework-0.1.0/README.md +11 -0
- enterprise_agentic_ai_framework-0.1.0/pyproject.toml +37 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/__init__.py +4 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/audit/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/compliance/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/context/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/core/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/core/agent.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/core/exceptions.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/core/orchestrator.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/core/planner.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/core/task.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/core/tool.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/data_governance/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/evaluation/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/finops/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/gateway/__init__.py +21 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/gateway/exceptions.py +22 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/gateway/litellm.py +109 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/governance/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/guardrails/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/identity/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/memory/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/monitoring/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/observability/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/operations/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/resilience/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/responsible_ai/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/secrets/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/src/agentic_ai/security/__init__.py +0 -0
- enterprise_agentic_ai_framework-0.1.0/tests/unit/gateway/test_litellm.py +115 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Byte-compiled / cache
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
.mypy_cache/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
build/
|
|
11
|
+
dist/
|
|
12
|
+
*.egg-info/
|
|
13
|
+
.eggs/
|
|
14
|
+
*.egg
|
|
15
|
+
|
|
16
|
+
# Virtual environments
|
|
17
|
+
.venv/
|
|
18
|
+
venv/
|
|
19
|
+
env/
|
|
20
|
+
|
|
21
|
+
# Environment / secrets - never commit real credentials
|
|
22
|
+
.env
|
|
23
|
+
.env.*
|
|
24
|
+
!.env.example
|
|
25
|
+
|
|
26
|
+
# Coverage
|
|
27
|
+
.coverage
|
|
28
|
+
.coverage.*
|
|
29
|
+
htmlcov/
|
|
30
|
+
coverage.xml
|
|
31
|
+
|
|
32
|
+
# IDE
|
|
33
|
+
.vscode/
|
|
34
|
+
.idea/
|
|
35
|
+
|
|
36
|
+
# OS
|
|
37
|
+
.DS_Store
|
|
38
|
+
|
|
39
|
+
# Docs build output
|
|
40
|
+
docs/_build/
|
|
41
|
+
site/
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: enterprise-agentic-ai-framework
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Enterprise Agentic AI Framework SDK
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: httpx>=0.27
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# enterprise-agentic-ai-framework
|
|
14
|
+
|
|
15
|
+
Enterprise Agentic AI Framework SDK
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install enterprise-agentic-ai-framework
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from agentic_ai.gateway import LiteLLMGateway
|
|
23
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# Pinned: hatchling >=1.29-ish emits core-metadata 2.5, which PyPI's
|
|
3
|
+
# Warehouse rejected on upload with a bare "400 Bad Request" and no
|
|
4
|
+
# useful message. hatchling <1.27 emits metadata 2.3, which is
|
|
5
|
+
# internally inconsistent with the License-Expression field this
|
|
6
|
+
# project's SPDX-style `license = "Apache-2.0"` produces (twine check
|
|
7
|
+
# catches that one locally). 1.27.0 is the version that correctly pairs
|
|
8
|
+
# metadata 2.4 with License-Expression, and 2.4 is old enough for
|
|
9
|
+
# Warehouse to accept without issue. Re-check both bounds before
|
|
10
|
+
# changing this pin.
|
|
11
|
+
requires = ["hatchling==1.27.0"]
|
|
12
|
+
build-backend = "hatchling.build"
|
|
13
|
+
|
|
14
|
+
[project]
|
|
15
|
+
# Distribution name only - the importable package stays `agentic_ai`
|
|
16
|
+
# (see [tool.hatch.build.targets.wheel] below). "agentic-ai-framework"
|
|
17
|
+
# was blocked on upload: PyPI's name-similarity check treats it as
|
|
18
|
+
# identical to the already-published "AgenticAIFramework" (hyphens/case
|
|
19
|
+
# are ignored when comparing names) - see PYPI_NAME_COLLISION note in
|
|
20
|
+
# CHANGELOG.md if that file gets filled in later.
|
|
21
|
+
name = "enterprise-agentic-ai-framework"
|
|
22
|
+
version = "0.1.0"
|
|
23
|
+
description = "Enterprise Agentic AI Framework SDK"
|
|
24
|
+
readme = "README.md"
|
|
25
|
+
license = "Apache-2.0"
|
|
26
|
+
requires-python = ">=3.10"
|
|
27
|
+
dependencies = [
|
|
28
|
+
"httpx>=0.27",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=8.0",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/agentic_ai"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
agentic_ai.gateway - LLM gateway clients.
|
|
3
|
+
|
|
4
|
+
Currently supports exactly one backend: a LiteLLM proxy the caller has
|
|
5
|
+
already deployed (see LiteLLMGateway's docstring for the deploy command).
|
|
6
|
+
This module is a thin HTTP client, never a process manager - it does not
|
|
7
|
+
start, stop, health-check-and-restart, or configure LiteLLM itself.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .exceptions import GatewayConfigError, GatewayConnectionError, GatewayError, GatewayRequestError
|
|
11
|
+
from .litellm import DEFAULT_HOST, DEFAULT_PORT, LiteLLMGateway
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"LiteLLMGateway",
|
|
15
|
+
"DEFAULT_HOST",
|
|
16
|
+
"DEFAULT_PORT",
|
|
17
|
+
"GatewayError",
|
|
18
|
+
"GatewayConfigError",
|
|
19
|
+
"GatewayConnectionError",
|
|
20
|
+
"GatewayRequestError",
|
|
21
|
+
]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Exceptions raised by agentic_ai.gateway.
|
|
2
|
+
|
|
3
|
+
Every call into a gateway client is wrapped - callers never see a raw
|
|
4
|
+
httpx/network exception, only one of these. One boundary, one exception
|
|
5
|
+
family, same rule this framework applies at every external integration.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GatewayError(Exception):
|
|
10
|
+
"""Base class for every error raised by a gateway client."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class GatewayConfigError(GatewayError):
|
|
14
|
+
"""The gateway was configured incorrectly (missing/invalid host, port, or base_url)."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class GatewayConnectionError(GatewayError):
|
|
18
|
+
"""The gateway could not reach the configured LLM proxy at all."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class GatewayRequestError(GatewayError):
|
|
22
|
+
"""The LLM proxy was reached but returned an error, or an unexpected response shape."""
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LiteLLM proxy gateway - the only LLM gateway backend this framework
|
|
3
|
+
currently supports.
|
|
4
|
+
|
|
5
|
+
This client connects to a LiteLLM proxy the caller has already deployed
|
|
6
|
+
and is running themselves; it never starts, stops, health-checks, or
|
|
7
|
+
otherwise manages that process - it only talks to it as an OpenAI-
|
|
8
|
+
compatible HTTP client (LiteLLM's proxy mirrors the OpenAI
|
|
9
|
+
/chat/completions API, so no LiteLLM-specific SDK is needed here).
|
|
10
|
+
|
|
11
|
+
Deploying LiteLLM is the caller's responsibility, e.g.:
|
|
12
|
+
|
|
13
|
+
pip install 'litellm[proxy]'
|
|
14
|
+
litellm --config litellm_config.yaml --port 4000
|
|
15
|
+
|
|
16
|
+
Only once that process is actually running does this client have
|
|
17
|
+
anything to connect to - constructing a LiteLLMGateway never launches it.
|
|
18
|
+
|
|
19
|
+
Model names passed to chat_completion()/complete() must already be
|
|
20
|
+
registered on that proxy (e.g. "gpt-4o-mini") - this client never sees or
|
|
21
|
+
cares which underlying provider actually serves the request, the proxy
|
|
22
|
+
owns that routing.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from typing import Any
|
|
26
|
+
|
|
27
|
+
import httpx
|
|
28
|
+
|
|
29
|
+
from .exceptions import GatewayConfigError, GatewayConnectionError, GatewayRequestError
|
|
30
|
+
|
|
31
|
+
DEFAULT_HOST = "localhost"
|
|
32
|
+
DEFAULT_PORT = 4000 # LiteLLM proxy's own default (`litellm --port 4000`)
|
|
33
|
+
DEFAULT_TIMEOUT = 30.0
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class LiteLLMGateway:
|
|
37
|
+
"""A client for a LiteLLM proxy the caller has already deployed.
|
|
38
|
+
|
|
39
|
+
Port resolution: pass `port=` explicitly if your deployment doesn't
|
|
40
|
+
use LiteLLM's own default; leave it unset and this connects to
|
|
41
|
+
`DEFAULT_PORT` (4000) instead. Pass a full `base_url` for anything
|
|
42
|
+
the host/port shorthand can't express (a non-http scheme, a path
|
|
43
|
+
prefix, a remote host behind TLS).
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
*,
|
|
49
|
+
host: str = DEFAULT_HOST,
|
|
50
|
+
port: int | None = None,
|
|
51
|
+
base_url: str | None = None,
|
|
52
|
+
api_key: str | None = None,
|
|
53
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
54
|
+
) -> None:
|
|
55
|
+
if base_url:
|
|
56
|
+
resolved_base_url = base_url.rstrip("/")
|
|
57
|
+
else:
|
|
58
|
+
if not host:
|
|
59
|
+
raise GatewayConfigError("host must be a non-empty string when base_url is not given")
|
|
60
|
+
resolved_port = port if port is not None else DEFAULT_PORT
|
|
61
|
+
resolved_base_url = f"http://{host}:{resolved_port}"
|
|
62
|
+
|
|
63
|
+
self.base_url = resolved_base_url
|
|
64
|
+
self.api_key = api_key
|
|
65
|
+
self.timeout = timeout
|
|
66
|
+
self._client = httpx.Client(base_url=self.base_url, timeout=self.timeout)
|
|
67
|
+
|
|
68
|
+
def _headers(self) -> dict:
|
|
69
|
+
headers = {"Content-Type": "application/json"}
|
|
70
|
+
if self.api_key:
|
|
71
|
+
headers["Authorization"] = f"Bearer {self.api_key}"
|
|
72
|
+
return headers
|
|
73
|
+
|
|
74
|
+
def chat_completion(self, model: str, messages: list[dict], **kwargs: Any) -> dict:
|
|
75
|
+
"""Call the proxy's /chat/completions with a model already
|
|
76
|
+
registered on it. Returns the raw OpenAI-compatible response
|
|
77
|
+
body - callers that want just the text should use complete()."""
|
|
78
|
+
payload = {"model": model, "messages": messages, **kwargs}
|
|
79
|
+
try:
|
|
80
|
+
response = self._client.post("/chat/completions", json=payload, headers=self._headers())
|
|
81
|
+
except httpx.RequestError as e:
|
|
82
|
+
raise GatewayConnectionError(
|
|
83
|
+
f"Could not reach the LiteLLM proxy at {self.base_url} - "
|
|
84
|
+
"is it deployed and running? (see LiteLLMGateway's docstring)"
|
|
85
|
+
) from e
|
|
86
|
+
|
|
87
|
+
if response.status_code >= 400:
|
|
88
|
+
raise GatewayRequestError(
|
|
89
|
+
f"LiteLLM proxy at {self.base_url} returned {response.status_code}: {response.text}"
|
|
90
|
+
)
|
|
91
|
+
return response.json()
|
|
92
|
+
|
|
93
|
+
def complete(self, model: str, messages: list[dict], **kwargs: Any) -> str:
|
|
94
|
+
"""Convenience wrapper: run chat_completion() and return just the
|
|
95
|
+
first choice's message content."""
|
|
96
|
+
result = self.chat_completion(model, messages, **kwargs)
|
|
97
|
+
try:
|
|
98
|
+
return result["choices"][0]["message"]["content"]
|
|
99
|
+
except (KeyError, IndexError) as e:
|
|
100
|
+
raise GatewayRequestError(f"Unexpected response shape from LiteLLM proxy: {result}") from e
|
|
101
|
+
|
|
102
|
+
def close(self) -> None:
|
|
103
|
+
self._client.close()
|
|
104
|
+
|
|
105
|
+
def __enter__(self) -> "LiteLLMGateway":
|
|
106
|
+
return self
|
|
107
|
+
|
|
108
|
+
def __exit__(self, *exc_info: object) -> None:
|
|
109
|
+
self.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Tests for agentic_ai.gateway.litellm - fully mocked, no real LiteLLM
|
|
2
|
+
proxy needed to run these."""
|
|
3
|
+
|
|
4
|
+
from unittest.mock import MagicMock
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from agentic_ai.gateway import DEFAULT_PORT, GatewayConnectionError, GatewayRequestError, LiteLLMGateway
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _fake_response(status_code=200, json_body=None):
|
|
13
|
+
response = MagicMock(spec=httpx.Response)
|
|
14
|
+
response.status_code = status_code
|
|
15
|
+
response.json.return_value = json_body or {}
|
|
16
|
+
response.text = str(json_body)
|
|
17
|
+
return response
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_default_base_url_uses_litellm_default_port():
|
|
21
|
+
gw = LiteLLMGateway()
|
|
22
|
+
assert gw.base_url == f"http://localhost:{DEFAULT_PORT}"
|
|
23
|
+
assert DEFAULT_PORT == 4000
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_custom_port_overrides_default():
|
|
27
|
+
gw = LiteLLMGateway(port=5001)
|
|
28
|
+
assert gw.base_url == "http://localhost:5001"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_custom_host_and_port():
|
|
32
|
+
gw = LiteLLMGateway(host="litellm.internal", port=8080)
|
|
33
|
+
assert gw.base_url == "http://litellm.internal:8080"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_explicit_base_url_wins_over_host_port():
|
|
37
|
+
gw = LiteLLMGateway(base_url="https://litellm.example.com/proxy/", host="ignored", port=9999)
|
|
38
|
+
assert gw.base_url == "https://litellm.example.com/proxy"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_chat_completion_posts_model_and_messages(monkeypatch):
|
|
42
|
+
gw = LiteLLMGateway(api_key="test-key")
|
|
43
|
+
captured = {}
|
|
44
|
+
|
|
45
|
+
def fake_post(url, json, headers):
|
|
46
|
+
captured["url"] = url
|
|
47
|
+
captured["json"] = json
|
|
48
|
+
captured["headers"] = headers
|
|
49
|
+
return _fake_response(200, {"choices": [{"message": {"content": "hi"}}]})
|
|
50
|
+
|
|
51
|
+
monkeypatch.setattr(gw._client, "post", fake_post)
|
|
52
|
+
|
|
53
|
+
result = gw.chat_completion("gpt-4o-mini", [{"role": "user", "content": "hello"}])
|
|
54
|
+
|
|
55
|
+
assert captured["url"] == "/chat/completions"
|
|
56
|
+
assert captured["json"]["model"] == "gpt-4o-mini"
|
|
57
|
+
assert captured["headers"]["Authorization"] == "Bearer test-key"
|
|
58
|
+
assert result["choices"][0]["message"]["content"] == "hi"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_no_api_key_omits_authorization_header(monkeypatch):
|
|
62
|
+
gw = LiteLLMGateway()
|
|
63
|
+
captured = {}
|
|
64
|
+
|
|
65
|
+
def fake_post(url, json, headers):
|
|
66
|
+
captured["headers"] = headers
|
|
67
|
+
return _fake_response(200, {"choices": [{"message": {"content": "hi"}}]})
|
|
68
|
+
|
|
69
|
+
monkeypatch.setattr(gw._client, "post", fake_post)
|
|
70
|
+
gw.chat_completion("gpt-4o-mini", [{"role": "user", "content": "hi"}])
|
|
71
|
+
|
|
72
|
+
assert "Authorization" not in captured["headers"]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_complete_extracts_message_content(monkeypatch):
|
|
76
|
+
gw = LiteLLMGateway()
|
|
77
|
+
monkeypatch.setattr(
|
|
78
|
+
gw._client, "post",
|
|
79
|
+
lambda url, json, headers: _fake_response(200, {"choices": [{"message": {"content": "the answer"}}]}),
|
|
80
|
+
)
|
|
81
|
+
assert gw.complete("gpt-4o-mini", [{"role": "user", "content": "hi"}]) == "the answer"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_unreachable_proxy_raises_gateway_connection_error(monkeypatch):
|
|
85
|
+
gw = LiteLLMGateway()
|
|
86
|
+
|
|
87
|
+
def fake_post(url, json, headers):
|
|
88
|
+
raise httpx.ConnectError("connection refused")
|
|
89
|
+
|
|
90
|
+
monkeypatch.setattr(gw._client, "post", fake_post)
|
|
91
|
+
|
|
92
|
+
with pytest.raises(GatewayConnectionError):
|
|
93
|
+
gw.chat_completion("gpt-4o-mini", [{"role": "user", "content": "hi"}])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_error_status_raises_gateway_request_error(monkeypatch):
|
|
97
|
+
gw = LiteLLMGateway()
|
|
98
|
+
monkeypatch.setattr(gw._client, "post", lambda url, json, headers: _fake_response(500, {"error": "boom"}))
|
|
99
|
+
|
|
100
|
+
with pytest.raises(GatewayRequestError):
|
|
101
|
+
gw.chat_completion("gpt-4o-mini", [{"role": "user", "content": "hi"}])
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_malformed_response_raises_gateway_request_error(monkeypatch):
|
|
105
|
+
gw = LiteLLMGateway()
|
|
106
|
+
monkeypatch.setattr(gw._client, "post", lambda url, json, headers: _fake_response(200, {"unexpected": "shape"}))
|
|
107
|
+
|
|
108
|
+
with pytest.raises(GatewayRequestError):
|
|
109
|
+
gw.complete("gpt-4o-mini", [{"role": "user", "content": "hi"}])
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_context_manager_closes_client():
|
|
113
|
+
with LiteLLMGateway() as gw:
|
|
114
|
+
assert gw.base_url
|
|
115
|
+
gw.close() # closing twice must not raise
|