blocksize-agent-tools 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.
- blocksize_agent_tools-0.1.0/.gitignore +32 -0
- blocksize_agent_tools-0.1.0/PKG-INFO +73 -0
- blocksize_agent_tools-0.1.0/README.md +55 -0
- blocksize_agent_tools-0.1.0/blocksize_agent_tools/__init__.py +11 -0
- blocksize_agent_tools-0.1.0/blocksize_agent_tools/client.py +83 -0
- blocksize_agent_tools-0.1.0/blocksize_agent_tools/langchain.py +28 -0
- blocksize_agent_tools-0.1.0/blocksize_agent_tools/llamaindex.py +29 -0
- blocksize_agent_tools-0.1.0/blocksize_agent_tools/openai_agents.py +36 -0
- blocksize_agent_tools-0.1.0/pyproject.toml +29 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.env
|
|
2
|
+
.venv/
|
|
3
|
+
node_modules/
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.pyc
|
|
6
|
+
*.egg-info/
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
agent_wallet.json
|
|
11
|
+
credits.db
|
|
12
|
+
usage_events.db
|
|
13
|
+
x402_payments*.sqlite3
|
|
14
|
+
x402_payments*.sqlite3-wal
|
|
15
|
+
x402_payments*.sqlite3-shm
|
|
16
|
+
rwa_observations.db
|
|
17
|
+
*.db-shm
|
|
18
|
+
*.db-wal
|
|
19
|
+
*entitlements.db
|
|
20
|
+
anthropic_entitlements.db
|
|
21
|
+
cursor_entitlements.db
|
|
22
|
+
.tmp_stork_coverage/
|
|
23
|
+
tmp/
|
|
24
|
+
outputs/
|
|
25
|
+
backups/
|
|
26
|
+
.DS_Store
|
|
27
|
+
mcp-registry-key.pem
|
|
28
|
+
tools/mcp-publisher
|
|
29
|
+
.railway-release-*.json*
|
|
30
|
+
|
|
31
|
+
# Shared free-tier grant ledger (set FREE_TIER_LEDGER_DB_PATH to the volume in production)
|
|
32
|
+
free_tier_ledger.db
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: blocksize-agent-tools
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Blocksize live market data tools for LangChain, LlamaIndex and OpenAI Agents SDK agents, with x402 pay-per-call.
|
|
5
|
+
Project-URL: Homepage, https://mcp.blocksize.info
|
|
6
|
+
Project-URL: Source, https://github.com/jf-cmyk/agentic-payments/tree/main/integrations/python
|
|
7
|
+
Author: Blocksize Capital
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Keywords: ai-agents,blocksize,langchain,llamaindex,market-data,openai-agents,x402
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Provides-Extra: langchain
|
|
12
|
+
Requires-Dist: langchain>=1.3.14; extra == 'langchain'
|
|
13
|
+
Provides-Extra: llamaindex
|
|
14
|
+
Requires-Dist: llama-index-core>=0.14.23; extra == 'llamaindex'
|
|
15
|
+
Provides-Extra: openai-agents
|
|
16
|
+
Requires-Dist: openai-agents>=0.18.3; extra == 'openai-agents'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# blocksize-agent-tools
|
|
20
|
+
|
|
21
|
+
Blocksize live market data (VWAP and bid/ask for crypto and equities) as read-only tools for Python agent frameworks. Calls go to [https://mcp.blocksize.info](https://mcp.blocksize.info): a stable agent ID gets the standard starter allowance, after that each call is paid per request through x402. Responses keep Blocksize timestamps and citation metadata.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install blocksize-agent-tools # core client only, no dependencies
|
|
27
|
+
pip install "blocksize-agent-tools[langchain]"
|
|
28
|
+
pip install "blocksize-agent-tools[llamaindex]"
|
|
29
|
+
pip install "blocksize-agent-tools[openai-agents]"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Set a stable agent ID (at least 8 characters) with `BLOCKSIZE_AGENT_ID`, or pass `agent_id=` to any builder.
|
|
33
|
+
|
|
34
|
+
## Core client
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from blocksize_agent_tools import BlocksizeHTTPClient, BlocksizePaymentRequired
|
|
38
|
+
|
|
39
|
+
client = BlocksizeHTTPClient("my-research-agent-01")
|
|
40
|
+
try:
|
|
41
|
+
print(client.get_vwap("BTC-USD"))
|
|
42
|
+
except BlocksizePaymentRequired as exc:
|
|
43
|
+
print("x402 challenge:", exc.payment_required)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## LangChain
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from langchain.agents import create_agent
|
|
50
|
+
from blocksize_agent_tools.langchain import build_blocksize_tools
|
|
51
|
+
|
|
52
|
+
agent = create_agent("openai:gpt-5", tools=build_blocksize_tools("my-research-agent-01"))
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## LlamaIndex
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from llama_index.core.agent.workflow import FunctionAgent
|
|
59
|
+
from blocksize_agent_tools.llamaindex import build_blocksize_tools
|
|
60
|
+
|
|
61
|
+
agent = FunctionAgent(tools=build_blocksize_tools("my-research-agent-01"), llm=llm)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## OpenAI Agents SDK
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from agents import Agent
|
|
68
|
+
from blocksize_agent_tools.openai_agents import build_blocksize_tools
|
|
69
|
+
|
|
70
|
+
agent = Agent(name="Markets", tools=build_blocksize_tools("my-research-agent-01"))
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Docs and pricing: [https://mcp.blocksize.info](https://mcp.blocksize.info)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# blocksize-agent-tools
|
|
2
|
+
|
|
3
|
+
Blocksize live market data (VWAP and bid/ask for crypto and equities) as read-only tools for Python agent frameworks. Calls go to [https://mcp.blocksize.info](https://mcp.blocksize.info): a stable agent ID gets the standard starter allowance, after that each call is paid per request through x402. Responses keep Blocksize timestamps and citation metadata.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install blocksize-agent-tools # core client only, no dependencies
|
|
9
|
+
pip install "blocksize-agent-tools[langchain]"
|
|
10
|
+
pip install "blocksize-agent-tools[llamaindex]"
|
|
11
|
+
pip install "blocksize-agent-tools[openai-agents]"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Set a stable agent ID (at least 8 characters) with `BLOCKSIZE_AGENT_ID`, or pass `agent_id=` to any builder.
|
|
15
|
+
|
|
16
|
+
## Core client
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from blocksize_agent_tools import BlocksizeHTTPClient, BlocksizePaymentRequired
|
|
20
|
+
|
|
21
|
+
client = BlocksizeHTTPClient("my-research-agent-01")
|
|
22
|
+
try:
|
|
23
|
+
print(client.get_vwap("BTC-USD"))
|
|
24
|
+
except BlocksizePaymentRequired as exc:
|
|
25
|
+
print("x402 challenge:", exc.payment_required)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## LangChain
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from langchain.agents import create_agent
|
|
32
|
+
from blocksize_agent_tools.langchain import build_blocksize_tools
|
|
33
|
+
|
|
34
|
+
agent = create_agent("openai:gpt-5", tools=build_blocksize_tools("my-research-agent-01"))
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## LlamaIndex
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from llama_index.core.agent.workflow import FunctionAgent
|
|
41
|
+
from blocksize_agent_tools.llamaindex import build_blocksize_tools
|
|
42
|
+
|
|
43
|
+
agent = FunctionAgent(tools=build_blocksize_tools("my-research-agent-01"), llm=llm)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## OpenAI Agents SDK
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from agents import Agent
|
|
50
|
+
from blocksize_agent_tools.openai_agents import build_blocksize_tools
|
|
51
|
+
|
|
52
|
+
agent = Agent(name="Markets", tools=build_blocksize_tools("my-research-agent-01"))
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Docs and pricing: [https://mcp.blocksize.info](https://mcp.blocksize.info)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Blocksize market data tools for agent frameworks.
|
|
2
|
+
|
|
3
|
+
The core client has no dependencies. Framework tools live in submodules that import
|
|
4
|
+
their framework only when used: ``blocksize_agent_tools.langchain``,
|
|
5
|
+
``blocksize_agent_tools.llamaindex`` and ``blocksize_agent_tools.openai_agents``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .client import BlocksizeHTTPClient, BlocksizePaymentRequired
|
|
9
|
+
|
|
10
|
+
__all__ = ["BlocksizeHTTPClient", "BlocksizePaymentRequired"]
|
|
11
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Small dependency-free Blocksize HTTP client shared by every framework integration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import Any
|
|
8
|
+
from urllib.error import HTTPError
|
|
9
|
+
from urllib.parse import quote, urlencode
|
|
10
|
+
from urllib.request import Request, urlopen
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BlocksizePaymentRequired(RuntimeError):
|
|
14
|
+
"""Raised when Blocksize returns a valid x402 payment challenge."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, message: str, *, payment_required: str | None = None) -> None:
|
|
17
|
+
super().__init__(message)
|
|
18
|
+
self.payment_required = payment_required
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BlocksizeHTTPClient:
|
|
22
|
+
"""Read-only Blocksize HTTP client for agent framework tools."""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
agent_id: str,
|
|
27
|
+
*,
|
|
28
|
+
base_url: str = "https://mcp.blocksize.info",
|
|
29
|
+
timeout: float = 20.0,
|
|
30
|
+
opener: Callable[..., Any] = urlopen,
|
|
31
|
+
) -> None:
|
|
32
|
+
clean_agent_id = agent_id.strip()
|
|
33
|
+
if len(clean_agent_id) < 8:
|
|
34
|
+
raise ValueError("agent_id must be a stable identifier with at least 8 characters")
|
|
35
|
+
self.agent_id = clean_agent_id
|
|
36
|
+
self.base_url = base_url.rstrip("/")
|
|
37
|
+
self.timeout = timeout
|
|
38
|
+
self._opener = opener
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def _instrument(value: str) -> str:
|
|
42
|
+
clean = value.strip().lower().replace("_", "-").replace("/", "-")
|
|
43
|
+
if not clean or any(character not in "abcdefghijklmnopqrstuvwxyz0123456789-" for character in clean):
|
|
44
|
+
raise ValueError("instrument must contain only letters, numbers, slash, underscore, or hyphen")
|
|
45
|
+
return quote(clean, safe="-")
|
|
46
|
+
|
|
47
|
+
def _get(self, path: str, query: dict[str, str] | None = None) -> dict[str, Any]:
|
|
48
|
+
suffix = f"?{urlencode(query)}" if query else ""
|
|
49
|
+
request = Request(
|
|
50
|
+
f"{self.base_url}{path}{suffix}",
|
|
51
|
+
headers={
|
|
52
|
+
"Accept": "application/json",
|
|
53
|
+
"X-Agent-ID": self.agent_id,
|
|
54
|
+
"User-Agent": "blocksize-framework-integration/1.0",
|
|
55
|
+
},
|
|
56
|
+
method="GET",
|
|
57
|
+
)
|
|
58
|
+
try:
|
|
59
|
+
with self._opener(request, timeout=self.timeout) as response:
|
|
60
|
+
payload = json.loads(response.read().decode("utf-8"))
|
|
61
|
+
except HTTPError as exc:
|
|
62
|
+
if exc.code == 402:
|
|
63
|
+
raise BlocksizePaymentRequired(
|
|
64
|
+
"Blocksize starter credits are unavailable or exhausted; complete the returned x402 challenge.",
|
|
65
|
+
payment_required=exc.headers.get("PAYMENT-REQUIRED"),
|
|
66
|
+
) from exc
|
|
67
|
+
body = exc.read().decode("utf-8", errors="replace")[:800]
|
|
68
|
+
raise RuntimeError(f"Blocksize returned HTTP {exc.code}: {body}") from exc
|
|
69
|
+
if not isinstance(payload, dict):
|
|
70
|
+
raise RuntimeError("Blocksize returned a non-object JSON response")
|
|
71
|
+
return payload
|
|
72
|
+
|
|
73
|
+
def search(self, query: str, *, asset_class: str | None = None) -> dict[str, Any]:
|
|
74
|
+
params = {"q": query.strip()}
|
|
75
|
+
if asset_class:
|
|
76
|
+
params["asset_class"] = asset_class.strip().lower()
|
|
77
|
+
return self._get("/v1/search", params)
|
|
78
|
+
|
|
79
|
+
def get_vwap(self, pair: str) -> dict[str, Any]:
|
|
80
|
+
return self._get(f"/v1/vwap/{self._instrument(pair)}")
|
|
81
|
+
|
|
82
|
+
def get_bid_ask(self, pair: str) -> dict[str, Any]:
|
|
83
|
+
return self._get(f"/v1/bidask/{self._instrument(pair)}")
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""LangChain tools backed by Blocksize production market data."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from langchain.tools import tool
|
|
8
|
+
|
|
9
|
+
from .client import BlocksizeHTTPClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_blocksize_tools(agent_id: str | None = None) -> list:
|
|
13
|
+
"""Return the Blocksize VWAP and bid/ask tools for a LangChain agent."""
|
|
14
|
+
client = BlocksizeHTTPClient(
|
|
15
|
+
agent_id or os.environ.get("BLOCKSIZE_AGENT_ID", "langchain-blocksize-agent")
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
@tool
|
|
19
|
+
def blocksize_vwap(pair: str) -> dict:
|
|
20
|
+
"""Get the latest Blocksize VWAP for a pair such as BTC-USD, including timestamp and citation metadata."""
|
|
21
|
+
return client.get_vwap(pair)
|
|
22
|
+
|
|
23
|
+
@tool
|
|
24
|
+
def blocksize_bid_ask(pair: str) -> dict:
|
|
25
|
+
"""Get the latest Blocksize bid/ask for a supported crypto or equity instrument."""
|
|
26
|
+
return client.get_bid_ask(pair)
|
|
27
|
+
|
|
28
|
+
return [blocksize_vwap, blocksize_bid_ask]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""LlamaIndex FunctionTool wrappers for Blocksize market data."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from llama_index.core.tools import FunctionTool
|
|
8
|
+
|
|
9
|
+
from .client import BlocksizeHTTPClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_blocksize_tools(agent_id: str | None = None) -> list[FunctionTool]:
|
|
13
|
+
"""Return the Blocksize VWAP and bid/ask tools for a LlamaIndex agent."""
|
|
14
|
+
client = BlocksizeHTTPClient(
|
|
15
|
+
agent_id or os.environ.get("BLOCKSIZE_AGENT_ID", "llamaindex-blocksize-agent")
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def blocksize_vwap(pair: str) -> dict:
|
|
19
|
+
"""Return Blocksize VWAP, source timestamp, methodology, and citation metadata."""
|
|
20
|
+
return client.get_vwap(pair)
|
|
21
|
+
|
|
22
|
+
def blocksize_bid_ask(pair: str) -> dict:
|
|
23
|
+
"""Return Blocksize bid/ask data for a supported crypto or equity instrument."""
|
|
24
|
+
return client.get_bid_ask(pair)
|
|
25
|
+
|
|
26
|
+
return [
|
|
27
|
+
FunctionTool.from_defaults(fn=blocksize_vwap),
|
|
28
|
+
FunctionTool.from_defaults(fn=blocksize_bid_ask),
|
|
29
|
+
]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""OpenAI Agents SDK function tools for Blocksize production data."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from agents import function_tool
|
|
8
|
+
|
|
9
|
+
from .client import BlocksizeHTTPClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_blocksize_tools(agent_id: str | None = None) -> list:
|
|
13
|
+
"""Return the Blocksize VWAP and bid/ask tools for an OpenAI Agents SDK agent."""
|
|
14
|
+
client = BlocksizeHTTPClient(
|
|
15
|
+
agent_id or os.environ.get("BLOCKSIZE_AGENT_ID", "openai-agents-blocksize")
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
@function_tool
|
|
19
|
+
def blocksize_vwap(pair: str) -> dict:
|
|
20
|
+
"""Get a live Blocksize VWAP with its source timestamp and citation metadata.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
pair: Instrument such as BTC-USD.
|
|
24
|
+
"""
|
|
25
|
+
return client.get_vwap(pair)
|
|
26
|
+
|
|
27
|
+
@function_tool
|
|
28
|
+
def blocksize_bid_ask(pair: str) -> dict:
|
|
29
|
+
"""Get a live Blocksize bid/ask for a supported crypto or equity instrument.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
pair: Instrument such as ETH-USD or AAPL.
|
|
33
|
+
"""
|
|
34
|
+
return client.get_bid_ask(pair)
|
|
35
|
+
|
|
36
|
+
return [blocksize_vwap, blocksize_bid_ask]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "blocksize-agent-tools"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Blocksize live market data tools for LangChain, LlamaIndex and OpenAI Agents SDK agents, with x402 pay-per-call."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = [{ name = "Blocksize Capital" }]
|
|
9
|
+
keywords = ["blocksize", "market-data", "x402", "ai-agents", "langchain", "llamaindex", "openai-agents"]
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[project.optional-dependencies]
|
|
13
|
+
langchain = ["langchain>=1.3.14"]
|
|
14
|
+
llamaindex = ["llama-index-core>=0.14.23"]
|
|
15
|
+
openai-agents = ["openai-agents>=0.18.3"]
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://mcp.blocksize.info"
|
|
19
|
+
Source = "https://github.com/jf-cmyk/agentic-payments/tree/main/integrations/python"
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["hatchling"]
|
|
23
|
+
build-backend = "hatchling.build"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.build.targets.wheel]
|
|
26
|
+
packages = ["blocksize_agent_tools"]
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.sdist]
|
|
29
|
+
include = ["/blocksize_agent_tools", "/README.md"]
|