zambo-haystack 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.
- zambo_haystack/__init__.py +21 -0
- zambo_haystack/client.py +109 -0
- zambo_haystack/tools.py +88 -0
- zambo_haystack-0.1.0.dist-info/METADATA +102 -0
- zambo_haystack-0.1.0.dist-info/RECORD +8 -0
- zambo_haystack-0.1.0.dist-info/WHEEL +5 -0
- zambo_haystack-0.1.0.dist-info/licenses/LICENSE +21 -0
- zambo_haystack-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""zambo-haystack: Zambo's 100+ live tools as Haystack tools.
|
|
2
|
+
|
|
3
|
+
Every tool call is executed by live Zambo (https://zambo.dev/api/mcp) and
|
|
4
|
+
mints a verifiable AER-1 execution receipt. No account, no API key, free
|
|
5
|
+
tier: 20 calls per tool per day.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .client import call_tool, list_tools, ZamboReceipt, ZamboResult
|
|
9
|
+
from .tools import lookup_receipt, zambo_tool, zambo_tools
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"call_tool",
|
|
15
|
+
"list_tools",
|
|
16
|
+
"lookup_receipt",
|
|
17
|
+
"zambo_tool",
|
|
18
|
+
"zambo_tools",
|
|
19
|
+
"ZamboReceipt",
|
|
20
|
+
"ZamboResult",
|
|
21
|
+
]
|
zambo_haystack/client.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Minimal Zambo MCP client over plain JSON-RPC.
|
|
2
|
+
|
|
3
|
+
Pure stdlib (urllib), no third-party dependencies. Talks to the live
|
|
4
|
+
https://zambo.dev/api/mcp endpoint: no auth, no account, free tier.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import http.client
|
|
11
|
+
import time
|
|
12
|
+
import urllib.error
|
|
13
|
+
import urllib.request
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
|
|
16
|
+
MCP_URL = "https://zambo.dev/api/mcp"
|
|
17
|
+
_TIMEOUT = 60
|
|
18
|
+
_MAX_ATTEMPTS = 6
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class ZamboReceipt:
|
|
23
|
+
"""A verifiable AER-1 execution receipt minted by a Zambo tool call."""
|
|
24
|
+
|
|
25
|
+
id: str
|
|
26
|
+
url: str
|
|
27
|
+
status: str = ""
|
|
28
|
+
tool: str = ""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class ZamboResult:
|
|
33
|
+
text: str
|
|
34
|
+
receipt: ZamboReceipt | None = None
|
|
35
|
+
raw: dict = field(default_factory=dict)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _post(payload: dict) -> dict:
|
|
39
|
+
body = json.dumps(payload).encode("utf-8")
|
|
40
|
+
last_error: Exception | None = None
|
|
41
|
+
for attempt in range(_MAX_ATTEMPTS):
|
|
42
|
+
request = urllib.request.Request(
|
|
43
|
+
MCP_URL,
|
|
44
|
+
data=body,
|
|
45
|
+
headers={"Content-Type": "application/json", "Accept": "application/json"},
|
|
46
|
+
method="POST",
|
|
47
|
+
)
|
|
48
|
+
try:
|
|
49
|
+
with urllib.request.urlopen(request, timeout=_TIMEOUT) as response:
|
|
50
|
+
return json.loads(response.read().decode("utf-8"))
|
|
51
|
+
except (
|
|
52
|
+
urllib.error.URLError,
|
|
53
|
+
ConnectionError,
|
|
54
|
+
TimeoutError,
|
|
55
|
+
json.JSONDecodeError,
|
|
56
|
+
http.client.IncompleteRead,
|
|
57
|
+
http.client.RemoteDisconnected,
|
|
58
|
+
http.client.BadStatusLine,
|
|
59
|
+
) as exc:
|
|
60
|
+
last_error = exc
|
|
61
|
+
time.sleep(1.5 * (attempt + 1))
|
|
62
|
+
raise RuntimeError(f"Zambo API call failed after {_MAX_ATTEMPTS} attempts: {last_error}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def call_tool(tool_name: str, arguments: dict) -> ZamboResult:
|
|
66
|
+
"""Call a Zambo MCP tool and return its result plus the receipt.
|
|
67
|
+
|
|
68
|
+
Every call mints a verifiable AER-1 receipt: a public URL carrying the
|
|
69
|
+
tool, arguments, observed result, SHA-256 fingerprint, and JSON-LD.
|
|
70
|
+
"""
|
|
71
|
+
response = _post(
|
|
72
|
+
{
|
|
73
|
+
"jsonrpc": "2.0",
|
|
74
|
+
"id": f"zambo-haystack-{int(time.time() * 1000)}",
|
|
75
|
+
"method": "tools/call",
|
|
76
|
+
"params": {"name": tool_name, "arguments": arguments},
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
if "error" in response:
|
|
80
|
+
raise RuntimeError(f"Zambo tool '{tool_name}' error: {response['error']}")
|
|
81
|
+
|
|
82
|
+
result = response.get("result", {})
|
|
83
|
+
receipt_data = result.get("_receipt", {}) or {}
|
|
84
|
+
|
|
85
|
+
receipt = None
|
|
86
|
+
receipt_id = receipt_data.get("id")
|
|
87
|
+
if receipt_id:
|
|
88
|
+
receipt = ZamboReceipt(
|
|
89
|
+
id=receipt_id,
|
|
90
|
+
url=receipt_data.get("audit") or f"https://zambo.dev/run/{receipt_id}",
|
|
91
|
+
status=receipt_data.get("status", ""),
|
|
92
|
+
tool=receipt_data.get("tool", tool_name),
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
text_parts = []
|
|
96
|
+
for item in result.get("content", []) or []:
|
|
97
|
+
if isinstance(item, dict) and "text" in item:
|
|
98
|
+
text_parts.append(str(item["text"]))
|
|
99
|
+
text = "\n".join(text_parts).strip()
|
|
100
|
+
|
|
101
|
+
return ZamboResult(text=text, receipt=receipt, raw=result)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def list_tools() -> list[dict]:
|
|
105
|
+
"""Return the live Zambo tool catalog (name + description)."""
|
|
106
|
+
response = _post({"jsonrpc": "2.0", "id": "zambo-tools-list", "method": "tools/list", "params": {}})
|
|
107
|
+
if "error" in response:
|
|
108
|
+
raise RuntimeError(f"Zambo tools/list error: {response['error']}")
|
|
109
|
+
return response.get("result", {}).get("tools", []) or []
|
zambo_haystack/tools.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Haystack tools backed by live Zambo execution.
|
|
2
|
+
|
|
3
|
+
Each tool below is a real Haystack Tool. When the agent invokes it, the
|
|
4
|
+
call is executed by Zambo (https://zambo.dev/api/mcp) and mints a
|
|
5
|
+
verifiable AER-1 receipt: public URL, tool, arguments, observed result,
|
|
6
|
+
SHA-256 fingerprint, machine-readable JSON-LD.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import threading
|
|
13
|
+
import time
|
|
14
|
+
from typing import Any, Callable
|
|
15
|
+
|
|
16
|
+
from haystack.tools import Tool
|
|
17
|
+
|
|
18
|
+
from . import client as _client
|
|
19
|
+
|
|
20
|
+
# (tool_name, arguments_json) -> (receipt_url, finished_at). Written by the
|
|
21
|
+
# tool wrapper on every invocation. Thread-safe. Query it with
|
|
22
|
+
# lookup_receipt().
|
|
23
|
+
_invocation_registry: dict[tuple[str, str], tuple[str, float]] = {}
|
|
24
|
+
_registry_lock = threading.Lock()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _record_invocation(tool_name: str, arguments_json: str, receipt_url: str) -> None:
|
|
28
|
+
with _registry_lock:
|
|
29
|
+
_invocation_registry[(tool_name, arguments_json)] = (receipt_url, time.time())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def lookup_receipt(tool_name: str, arguments_json: str) -> str | None:
|
|
33
|
+
"""Return the most recent receipt URL for a (tool, args) invocation."""
|
|
34
|
+
with _registry_lock:
|
|
35
|
+
entry = _invocation_registry.get((tool_name, arguments_json))
|
|
36
|
+
return entry[0] if entry else None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def zambo_tool(
|
|
40
|
+
tool_name: str,
|
|
41
|
+
description: str | None = None,
|
|
42
|
+
params_json_schema: dict | None = None,
|
|
43
|
+
on_receipt: Callable[[str, str], Any] | None = None,
|
|
44
|
+
) -> Tool:
|
|
45
|
+
"""Build a Haystack Tool backed by a Zambo MCP tool.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
tool_name: Name of the Zambo tool (see client.list_tools(), e.g.
|
|
49
|
+
"live_price", "ghost_audit_site", "prompt_shield").
|
|
50
|
+
description: Override the tool description shown to the model.
|
|
51
|
+
params_json_schema: Override the JSON schema for the tool's arguments.
|
|
52
|
+
Defaults to a permissive object schema; Zambo validates server-side.
|
|
53
|
+
on_receipt: Optional callback invoked as on_receipt(tool_name,
|
|
54
|
+
receipt_url) after every successful invocation.
|
|
55
|
+
|
|
56
|
+
The tool's result text ends with a "Verifiable receipt: <url>" line, and
|
|
57
|
+
the URL is also recorded in the invocation registry (see
|
|
58
|
+
lookup_receipt()).
|
|
59
|
+
"""
|
|
60
|
+
schema = params_json_schema or {"type": "object", "properties": {}}
|
|
61
|
+
|
|
62
|
+
def _run(**kwargs: Any) -> str:
|
|
63
|
+
result = _client.call_tool(tool_name, dict(kwargs))
|
|
64
|
+
|
|
65
|
+
receipt_url = result.receipt.url if result.receipt else ""
|
|
66
|
+
arguments_json = json.dumps(kwargs, sort_keys=True)
|
|
67
|
+
if receipt_url:
|
|
68
|
+
_record_invocation(tool_name, arguments_json, receipt_url)
|
|
69
|
+
if on_receipt is not None:
|
|
70
|
+
on_receipt(tool_name, receipt_url)
|
|
71
|
+
|
|
72
|
+
output = result.text or "(empty result)"
|
|
73
|
+
if receipt_url:
|
|
74
|
+
output += f"\n\nVerifiable receipt: {receipt_url}"
|
|
75
|
+
return output
|
|
76
|
+
|
|
77
|
+
return Tool(
|
|
78
|
+
name=tool_name,
|
|
79
|
+
description=description
|
|
80
|
+
or f"Zambo tool '{tool_name}' (zambo.dev). Every call mints a verifiable execution receipt.",
|
|
81
|
+
parameters=schema,
|
|
82
|
+
function=_run,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def zambo_tools(tool_names: list[str], **kwargs: Any) -> list[Tool]:
|
|
87
|
+
"""Build several Zambo-backed Haystack Tools at once."""
|
|
88
|
+
return [zambo_tool(name, **kwargs) for name in tool_names]
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zambo-haystack
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zambo's 100+ tools as Haystack tools. Every call mints a verifiable AER-1 execution receipt.
|
|
5
|
+
Author-email: Zambo <brennanzambo@zambo.dev>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://zambo.dev
|
|
8
|
+
Project-URL: Documentation, https://zambo.dev/aer-1/
|
|
9
|
+
Project-URL: Repository, https://zambo.dev
|
|
10
|
+
Keywords: haystack,deepset,agents,ai-agents,zambo,mcp,receipts,verification
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: haystack-ai>=2.0
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# zambo-haystack
|
|
26
|
+
|
|
27
|
+
Give your Haystack agent Zambo's 100+ live tools. Every tool call is executed by Zambo and mints a **verifiable AER-1 receipt**: a public URL carrying the tool, its arguments, the observed result, a SHA-256 fingerprint, and machine-readable JSON-LD.
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from haystack.components.agents import Agent
|
|
31
|
+
from haystack.components.generators.chat import OpenAIChatGenerator
|
|
32
|
+
from zambo_haystack import zambo_tools
|
|
33
|
+
|
|
34
|
+
agent = Agent(
|
|
35
|
+
chat_generator=OpenAIChatGenerator(), # any Haystack chat generator works
|
|
36
|
+
tools=zambo_tools(["live_price", "prompt_shield"]),
|
|
37
|
+
)
|
|
38
|
+
result = agent.run([{"role": "user", "content": "What is the live BTC price?"}])
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Bring any Haystack chat generator (`OpenAIChatGenerator` above needs `OPENAI_API_KEY`; the Zambo calls themselves need no account and no key).
|
|
42
|
+
No account. No API key. Free tier: 20 calls per tool per day.
|
|
43
|
+
|
|
44
|
+
## What the receipt actually proves
|
|
45
|
+
|
|
46
|
+
Each receipt page (for example `https://zambo.dev/run/<id>`) is Zambo's tamper-evident record that **Zambo executed the tool call itself**: the tool name, the exact arguments your agent sent, the observed result, a timestamp, and a SHA-256 fingerprint of the record, published as JSON-LD. Anyone can re-verify it with no account.
|
|
47
|
+
|
|
48
|
+
Every Haystack tool returned by `zambo_tool` appends the minted receipt URL to its result text, and records it in a registry you can query with `lookup_receipt(tool_name, arguments_json)`:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from zambo_haystack import lookup_receipt
|
|
52
|
+
|
|
53
|
+
url = lookup_receipt("live_price", '{"symbol": "BTC"}')
|
|
54
|
+
print(url) # https://zambo.dev/run/<id>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Or register a callback to capture each receipt as it is minted:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from zambo_haystack import zambo_tool
|
|
61
|
+
|
|
62
|
+
price_tool = zambo_tool(
|
|
63
|
+
"live_price",
|
|
64
|
+
on_receipt=lambda tool, url: print(f"[receipt] {tool}: {url}"),
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Install
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install zambo-haystack
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## One tool, custom schema
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from zambo_haystack import zambo_tool
|
|
78
|
+
|
|
79
|
+
price_tool = zambo_tool(
|
|
80
|
+
"live_price",
|
|
81
|
+
params_json_schema={
|
|
82
|
+
"type": "object",
|
|
83
|
+
"properties": {"symbol": {"type": "string"}},
|
|
84
|
+
"required": ["symbol"],
|
|
85
|
+
},
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Browse the full catalog any time with `zambo_haystack.list_tools()`, or pick tools by use case through Zambo's `capability_search` tool.
|
|
90
|
+
|
|
91
|
+
## Notes
|
|
92
|
+
|
|
93
|
+
- Zambo calls need no key and no signup. Heavy runs (dozens of tool calls) will reach the free daily limit; the tool raises a clear error and the agent run continues with the other tools.
|
|
94
|
+
- The receipt registry is thread-safe and never breaks your run: the wrapper only reads and writes its own registry entry, and it ignores anything else in the pipeline.
|
|
95
|
+
- Receipts are public by design. Do not pass secrets as tool arguments.
|
|
96
|
+
|
|
97
|
+
## Links
|
|
98
|
+
|
|
99
|
+
- Zambo: https://zambo.dev
|
|
100
|
+
- AER-1 receipt spec: https://zambo.dev/aer-1/
|
|
101
|
+
|
|
102
|
+
MIT License.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
zambo_haystack/__init__.py,sha256=EIb41a7n6bSc9utoJdHt-PMGN9BH1LbsPjQXCj-GXEc,547
|
|
2
|
+
zambo_haystack/client.py,sha256=s3muJxAe1HfCILfvERan0SllFK3zgp7mqcKEnFPExfw,3437
|
|
3
|
+
zambo_haystack/tools.py,sha256=pE37QDowBJpNLOVtep9TdW52WqMDGkx8QA8QQN8o2NU,3226
|
|
4
|
+
zambo_haystack-0.1.0.dist-info/licenses/LICENSE,sha256=qrt0SYvOjAeo34V444C2UgxsdQdDHTKDv2eIemjDpRM,1074
|
|
5
|
+
zambo_haystack-0.1.0.dist-info/METADATA,sha256=J35TXS_YvAqsQBmcpK9DSbUckgJxkI-c0V4bfTvc1MM,3802
|
|
6
|
+
zambo_haystack-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
7
|
+
zambo_haystack-0.1.0.dist-info/top_level.txt,sha256=pBA9gsqcACb--j8wPP9AOFicQEezkisZhId5e0s7CEA,15
|
|
8
|
+
zambo_haystack-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zambo (zambo.dev)
|
|
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 @@
|
|
|
1
|
+
zambo_haystack
|