toolproxy 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: toolproxy
3
+ Version: 0.1.0
4
+ Summary: Universal tool-calling wrapper for non-tool-native LLMs — emulates function calling via structured JSON planning
5
+ Project-URL: Homepage, https://github.com/yourusername/toolproxy
6
+ Project-URL: Repository, https://github.com/yourusername/toolproxy
7
+ Project-URL: Bug Tracker, https://github.com/yourusername/toolproxy/issues
8
+ Author: toolproxy contributors
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,function-calling,llm,ollama,openrouter,pydantic,structured-output,tool-calling
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: httpx>=0.25
25
+ Requires-Dist: openai>=1.0
26
+ Requires-Dist: pydantic>=2.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: build>=1.0; extra == 'dev'
29
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
30
+ Requires-Dist: pytest-mock>=3.0; extra == 'dev'
31
+ Requires-Dist: pytest>=7.0; extra == 'dev'
32
+ Requires-Dist: twine>=5.0; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # toolproxy
36
+
37
+ [![PyPI version](https://badge.fury.io/py/toolproxy.svg)](https://pypi.org/project/toolproxy/)
38
+ [![Python Versions](https://img.shields.io/pypi/pyversions/toolproxy.svg)](https://pypi.org/project/toolproxy/)
39
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
40
+
41
+ **Universal Tool-Calling Wrapper for Non-Tool-Native LLMs**
42
+
43
+ A provider-agnostic Python library that adds reliable tool/function calling to *any* LLM — even models that have no native tool-calling API.
44
+
45
+ ---
46
+
47
+ ## Problem
48
+
49
+ Many LLM providers (OpenRouter, Ollama, local LLMs) expose models that don't support function calling. This library solves that by:
50
+
51
+ - **Detecting** whether the model supports native tool calling.
52
+ - **Using** native tool calls when available (OpenAI format).
53
+ - **Falling back** to a structured JSON planning protocol when not.
54
+
55
+ The developer always uses the same API regardless of the underlying model.
56
+
57
+ ---
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install toolproxy
63
+ ```
64
+
65
+ Or from source:
66
+
67
+ ```bash
68
+ pip install -e ".[dev]"
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Quick Start
74
+
75
+ ```python
76
+ from toolproxy import UniversalAgent, tool
77
+
78
+ @tool
79
+ def get_weather(city: str) -> str:
80
+ """Get the current weather for a city."""
81
+ return f"Sunny, 25°C in {city}"
82
+
83
+ agent = UniversalAgent(
84
+ model="openrouter/mistralai/mistral-7b-instruct",
85
+ tools=[get_weather],
86
+ )
87
+
88
+ result = agent.run("What is the weather in Chennai today?")
89
+ print(result.content)
90
+ ```
91
+
92
+ The same code works whether the model supports native tools or not.
93
+
94
+ ---
95
+
96
+ ## How It Works
97
+
98
+ ```
99
+ Developer
100
+
101
+
102
+ UniversalAgent.run(prompt)
103
+
104
+ ├─ Planner (auto-detects native vs emulated mode)
105
+ │ │
106
+ │ ├── Native mode → provider tool calls (OpenAI format)
107
+ │ └── Emulated mode → structured JSON Action schema
108
+
109
+ ├─ Executor (validates args, runs tool, captures errors)
110
+
111
+ └─ LoopController (repeats until final answer or max_steps)
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Model Prefixes
117
+
118
+ | Prefix | Backend |
119
+ |---|---|
120
+ | `openrouter/...` | OpenRouter API |
121
+ | `ollama/...` | Local Ollama server |
122
+ | `mock/...` | MockClient (for testing, no API key needed) |
123
+ | *(no prefix)* | OpenAI / any OpenAI-compatible endpoint |
124
+
125
+ ---
126
+
127
+ ## Advanced Options
128
+
129
+ ```python
130
+ from toolproxy import UniversalAgent, tool
131
+ from toolproxy.config import ExecutionPolicy
132
+
133
+ agent = UniversalAgent(
134
+ model="openrouter/your-model",
135
+ tools=[get_weather],
136
+ mode="auto", # "auto" | "native_only" | "emulated_only"
137
+ max_steps=10,
138
+ execution_policy=ExecutionPolicy(
139
+ mode="allow_only",
140
+ allowed_tools=["get_weather"],
141
+ ),
142
+ )
143
+
144
+ result = agent.run("...", return_trace=True)
145
+ print(result.content)
146
+ for call in result.trace.tool_calls:
147
+ print(call.tool_name, call.arguments)
148
+ ```
149
+
150
+ ### Callbacks (streaming-style)
151
+
152
+ ```python
153
+ result = agent.run(
154
+ "...",
155
+ on_tool_call=lambda step, tc: print(f"Calling: {tc.tool_name}"),
156
+ on_tool_result=lambda step, tr: print(f"Result: {tr.output}"),
157
+ on_model_output=lambda step, text: print(f"Model: {text}"),
158
+ )
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Emulated Mode Protocol
164
+
165
+ When the model does not support native tools, the agent injects a system prompt instructing the model to output one of two JSON formats:
166
+
167
+ ```json
168
+ // Tool call
169
+ {"type": "tool_call", "tool": {"tool_name": "get_weather", "arguments": {"city": "Chennai"}}}
170
+
171
+ // Final answer
172
+ {"type": "final", "content": "The weather is sunny."}
173
+ ```
174
+
175
+ Malformed responses are retried up to `parse_retries` times (default: 3) with an error explanation.
176
+
177
+ ---
178
+
179
+ ## Project Structure
180
+
181
+ ```
182
+ src/toolproxy/
183
+ __init__.py # Public API re-exports
184
+ agent.py # UniversalAgent class
185
+ llm_client.py # LLMClient + adapters
186
+ tools.py # @tool decorator + ToolRegistry
187
+ schemas.py # Pydantic schemas
188
+ planner.py # Planner logic
189
+ executor.py # Tool execution + policies
190
+ loop.py # Loop controller
191
+ exceptions.py # Custom exceptions
192
+ config.py # Configuration + capability map
193
+ examples/
194
+ basic_chat.py
195
+ openrouter_tools.py
196
+ local_ollama.py
197
+ tests/
198
+ test_agent_basic.py
199
+ test_emulated_mode.py
200
+ test_native_mode.py
201
+ test_error_handling.py
202
+ test_tool_registry.py
203
+ ```
204
+
205
+ ---
206
+
207
+ ## Publishing to PyPI
208
+
209
+ ```bash
210
+ # 1. Install build tools
211
+ pip install build twine
212
+
213
+ # 2. Build wheel + sdist
214
+ python -m build
215
+
216
+ # 3. Check the distribution
217
+ twine check dist/*
218
+
219
+ # 4. Upload to PyPI (you will be prompted for credentials)
220
+ twine upload dist/*
221
+
222
+ # Or upload to TestPyPI first
223
+ twine upload --repository testpypi dist/*
224
+ ```
225
+
226
+ ---
227
+
228
+ ## Running Tests
229
+
230
+ ```bash
231
+ pytest tests/ -v
232
+ ```
233
+
234
+ ---
235
+
236
+ ## Environment Variables
237
+
238
+ | Variable | Description |
239
+ |---|---|
240
+ | `OPENROUTER_API_KEY` | API key for OpenRouter |
241
+ | `OPENAI_API_KEY` | API key for OpenAI |
242
+ | `OLLAMA_BASE_URL` | Ollama server URL (default: `http://localhost:11434`) |
243
+ | `OLLAMA_MODEL` | Ollama model name (default: `llama3`) |
@@ -0,0 +1,15 @@
1
+ toolproxy/__init__.py,sha256=bGlujHLFUU12sGcHDkKPN97ntfdPmT7XGXld6rf1-MA,2005
2
+ toolproxy/agent.py,sha256=Hpd7wH2wl05xMcHYdK11WXUJyv1vzE3aQ_4SZisON4A,6031
3
+ toolproxy/config.py,sha256=URHUKXJz-LTjIlgapxGN23W_yVihOcvnaI7WRTre8-k,3026
4
+ toolproxy/exceptions.py,sha256=LdyNhJhjlwjCf2VzH46GXCrbeNwyh9aMVIFnKbGSZC8,1844
5
+ toolproxy/executor.py,sha256=VTCc2C6mRy0tea2enJGbL8I1bLJ557cZYcPb6ZtZkV0,4356
6
+ toolproxy/llm_client.py,sha256=5HgZWQEQHy_ixgGG-pZqfTyNOIu7dt3Io29LDBdRhZw,13521
7
+ toolproxy/loop.py,sha256=xTnRzAY2T_PkpByNT6vQzZICiurQ3VGYsPRh-W4zJYM,6072
8
+ toolproxy/planner.py,sha256=tWg3dGM13qjZqRmotutXbVeFFIPW0Xq6PK7z4x2vdlw,8512
9
+ toolproxy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ toolproxy/schemas.py,sha256=8K8rmqSuswidvlHfEztycQuviIYkmiMtwqjizMqkw2Q,3761
11
+ toolproxy/tools.py,sha256=p8bIlHm5cYB6m21AAAJcg5f5nwptIk66LiJplquxJlg,7627
12
+ toolproxy-0.1.0.dist-info/METADATA,sha256=8HqRffPwZH0qDpINXgGwqftyJHkBFlZA1BAsNsGgizs,6383
13
+ toolproxy-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
14
+ toolproxy-0.1.0.dist-info/licenses/LICENSE,sha256=uxhKfM2ewPr6GS1tqR5hpPDeEAcFJQ4WXrqORNIWBB8,1079
15
+ toolproxy-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 toolproxy contributors
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.