reinogent 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.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: reinogent
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK & CLI for discovering, downloading, and running AI Models, MCP Servers, and Agents from ReinoGent
5
+ Requires-Python: >=3.9
6
+ Description-Content-Type: text/markdown
7
+ Provides-Extra: transformers
8
+ Requires-Dist: torch>=2.1.0; extra == "transformers"
9
+ Requires-Dist: transformers>=4.41.0; extra == "transformers"
10
+ Requires-Dist: safetensors>=0.4.0; extra == "transformers"
11
+ Requires-Dist: accelerate>=0.30.0; extra == "transformers"
12
+ Provides-Extra: embeddings
13
+ Requires-Dist: sentence-transformers>=3.0.0; extra == "embeddings"
14
+ Provides-Extra: mcp
15
+ Requires-Dist: mcp>=1.0.0; extra == "mcp"
16
+ Provides-Extra: agent
17
+ Requires-Dist: fastapi>=0.115.0; extra == "agent"
18
+ Requires-Dist: uvicorn[standard]>=0.32.0; extra == "agent"
19
+ Requires-Dist: httpx>=0.27.0; extra == "agent"
20
+ Provides-Extra: all
21
+ Requires-Dist: torch>=2.1.0; extra == "all"
22
+ Requires-Dist: transformers>=4.41.0; extra == "all"
23
+ Requires-Dist: safetensors>=0.4.0; extra == "all"
24
+ Requires-Dist: accelerate>=0.30.0; extra == "all"
25
+ Requires-Dist: sentence-transformers>=3.0.0; extra == "all"
26
+ Requires-Dist: mcp>=1.0.0; extra == "all"
27
+ Requires-Dist: fastapi>=0.115.0; extra == "all"
28
+ Requires-Dist: uvicorn[standard]>=0.32.0; extra == "all"
29
+ Requires-Dist: httpx>=0.27.0; extra == "all"
30
+
31
+ # `reinogent` — Official Python SDK & CLI
32
+
33
+ Lightweight Python SDK and `reino` CLI for discovering, downloading, installing dependencies for, and running **AI Models**, **MCP Servers**, and **Agents** from ReinoGent.
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ # Core SDK + CLI (zero mandatory dependencies)
39
+ pip install -e ./cli
40
+
41
+ # Or install with optional runtime dependency extras:
42
+ pip install -e "./cli[transformers]" # torch, transformers, safetensors, accelerate
43
+ pip install -e "./cli[embeddings]" # sentence-transformers
44
+ pip install -e "./cli[mcp]" # mcp Python SDK
45
+ pip install -e "./cli[agent]" # fastapi, uvicorn, httpx (for building agents)
46
+ pip install -e "./cli[all]" # all runtime extras
47
+ ```
48
+
49
+ *(Once published to PyPI: `pip install reinogent` / `pip install "reinogent[transformers]"`.)*
50
+
51
+ ## CLI Quick Start
52
+
53
+ ```bash
54
+ # Point at your ReinoGent backend API
55
+ reino config set-api https://your-backend.onrender.com/api
56
+
57
+ # Browse & inspect dependencies
58
+ reino list models --african --task text-generation
59
+ reino deps model bge-small-en-v1-5
60
+ reino deps mcp github-mcp-server
61
+
62
+ # Pull resources (generates `reino.json` + `reino_run.py` bundle) & install deps
63
+ reino pull model bge-small-en-v1-5 --install-deps
64
+ reino pull mcp github-mcp-server --config
65
+ reino pull mcp github-mcp-server --install-deps
66
+ reino pull agent <agent-id> --install-deps
67
+
68
+ # Run any packaged ReinoGent bundle (`model`, `mcp`, or `agent`)
69
+ reino run ./bge-small-en-v1-5 --prompt "Hello ReinoGent"
70
+ reino run ./github-mcp-server
71
+
72
+ # Scaffold a new SDK-native ReinoGent AgentApp project
73
+ reino init "Swahili Support Bot" --model bge-small-en-v1-5 --mcp github-mcp-server
74
+ ```
75
+
76
+ ## Build an Agent in 10 Lines (`reinogent.AgentApp`)
77
+
78
+ ```python
79
+ import reinogent
80
+
81
+ app = reinogent.AgentApp(
82
+ name="Swahili Support Bot",
83
+ model="bge-small-en-v1-5",
84
+ mcp_tools=["github-mcp-server"],
85
+ )
86
+
87
+ @app.on_message
88
+ async def handle(ctx: reinogent.AgentContext):
89
+ return f"Received: {ctx.input}"
90
+
91
+ if __name__ == "__main__":
92
+ app.serve(port=8001) # Exposes POST /invoke (HMAC verified), GET /health, GET /reino-manifest
93
+ ```
94
+
95
+ ## Python SDK Quick Start
96
+
97
+ ```python
98
+ import reinogent
99
+
100
+ # 1. Load a ReinoGent model directly (auto-resolves Transformers / Sentence-Transformers)
101
+ model = reinogent.load_model("bge-small-en-v1-5")
102
+
103
+ # 2. Download raw model weights/files from upstream CDN
104
+ local_dir = reinogent.download_model("bge-small-en-v1-5", dest_dir="./weights")
105
+
106
+ # 3. Fetch ready-to-use MCP client configuration
107
+ mcp_cfg = reinogent.get_mcp_config("github-mcp-server")
108
+
109
+ # 4. Run a hosted ReinoGent agent
110
+ result = reinogent.run_agent("agt_12345", "Summarize Q4 metrics", token="<your-jwt>")
111
+
112
+ # 5. Verify ReinoGent webhook HMAC-SHA256 signatures inside your FastAPI/Flask agent
113
+ is_valid = reinogent.verify_signature(body, x_reino_signature, x_reino_timestamp, SECRET_KEY)
114
+ ```
115
+
116
+ ## Publishing to PyPI
117
+
118
+ ```bash
119
+ pip install build twine
120
+ cd cli
121
+ python -m build
122
+ twine upload dist/*
123
+ ```
@@ -0,0 +1,93 @@
1
+ # `reinogent` — Official Python SDK & CLI
2
+
3
+ Lightweight Python SDK and `reino` CLI for discovering, downloading, installing dependencies for, and running **AI Models**, **MCP Servers**, and **Agents** from ReinoGent.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Core SDK + CLI (zero mandatory dependencies)
9
+ pip install -e ./cli
10
+
11
+ # Or install with optional runtime dependency extras:
12
+ pip install -e "./cli[transformers]" # torch, transformers, safetensors, accelerate
13
+ pip install -e "./cli[embeddings]" # sentence-transformers
14
+ pip install -e "./cli[mcp]" # mcp Python SDK
15
+ pip install -e "./cli[agent]" # fastapi, uvicorn, httpx (for building agents)
16
+ pip install -e "./cli[all]" # all runtime extras
17
+ ```
18
+
19
+ *(Once published to PyPI: `pip install reinogent` / `pip install "reinogent[transformers]"`.)*
20
+
21
+ ## CLI Quick Start
22
+
23
+ ```bash
24
+ # Point at your ReinoGent backend API
25
+ reino config set-api https://your-backend.onrender.com/api
26
+
27
+ # Browse & inspect dependencies
28
+ reino list models --african --task text-generation
29
+ reino deps model bge-small-en-v1-5
30
+ reino deps mcp github-mcp-server
31
+
32
+ # Pull resources (generates `reino.json` + `reino_run.py` bundle) & install deps
33
+ reino pull model bge-small-en-v1-5 --install-deps
34
+ reino pull mcp github-mcp-server --config
35
+ reino pull mcp github-mcp-server --install-deps
36
+ reino pull agent <agent-id> --install-deps
37
+
38
+ # Run any packaged ReinoGent bundle (`model`, `mcp`, or `agent`)
39
+ reino run ./bge-small-en-v1-5 --prompt "Hello ReinoGent"
40
+ reino run ./github-mcp-server
41
+
42
+ # Scaffold a new SDK-native ReinoGent AgentApp project
43
+ reino init "Swahili Support Bot" --model bge-small-en-v1-5 --mcp github-mcp-server
44
+ ```
45
+
46
+ ## Build an Agent in 10 Lines (`reinogent.AgentApp`)
47
+
48
+ ```python
49
+ import reinogent
50
+
51
+ app = reinogent.AgentApp(
52
+ name="Swahili Support Bot",
53
+ model="bge-small-en-v1-5",
54
+ mcp_tools=["github-mcp-server"],
55
+ )
56
+
57
+ @app.on_message
58
+ async def handle(ctx: reinogent.AgentContext):
59
+ return f"Received: {ctx.input}"
60
+
61
+ if __name__ == "__main__":
62
+ app.serve(port=8001) # Exposes POST /invoke (HMAC verified), GET /health, GET /reino-manifest
63
+ ```
64
+
65
+ ## Python SDK Quick Start
66
+
67
+ ```python
68
+ import reinogent
69
+
70
+ # 1. Load a ReinoGent model directly (auto-resolves Transformers / Sentence-Transformers)
71
+ model = reinogent.load_model("bge-small-en-v1-5")
72
+
73
+ # 2. Download raw model weights/files from upstream CDN
74
+ local_dir = reinogent.download_model("bge-small-en-v1-5", dest_dir="./weights")
75
+
76
+ # 3. Fetch ready-to-use MCP client configuration
77
+ mcp_cfg = reinogent.get_mcp_config("github-mcp-server")
78
+
79
+ # 4. Run a hosted ReinoGent agent
80
+ result = reinogent.run_agent("agt_12345", "Summarize Q4 metrics", token="<your-jwt>")
81
+
82
+ # 5. Verify ReinoGent webhook HMAC-SHA256 signatures inside your FastAPI/Flask agent
83
+ is_valid = reinogent.verify_signature(body, x_reino_signature, x_reino_timestamp, SECRET_KEY)
84
+ ```
85
+
86
+ ## Publishing to PyPI
87
+
88
+ ```bash
89
+ pip install build twine
90
+ cd cli
91
+ python -m build
92
+ twine upload dist/*
93
+ ```
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "reinogent"
7
+ version = "0.1.0"
8
+ description = "Official Python SDK & CLI for discovering, downloading, and running AI Models, MCP Servers, and Agents from ReinoGent"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = []
12
+
13
+ [project.optional-dependencies]
14
+ transformers = [
15
+ "torch>=2.1.0",
16
+ "transformers>=4.41.0",
17
+ "safetensors>=0.4.0",
18
+ "accelerate>=0.30.0",
19
+ ]
20
+ embeddings = [
21
+ "sentence-transformers>=3.0.0",
22
+ ]
23
+ mcp = [
24
+ "mcp>=1.0.0",
25
+ ]
26
+ agent = [
27
+ "fastapi>=0.115.0",
28
+ "uvicorn[standard]>=0.32.0",
29
+ "httpx>=0.27.0",
30
+ ]
31
+ all = [
32
+ "torch>=2.1.0",
33
+ "transformers>=4.41.0",
34
+ "safetensors>=0.4.0",
35
+ "accelerate>=0.30.0",
36
+ "sentence-transformers>=3.0.0",
37
+ "mcp>=1.0.0",
38
+ "fastapi>=0.115.0",
39
+ "uvicorn[standard]>=0.32.0",
40
+ "httpx>=0.27.0",
41
+ ]
42
+
43
+ [project.scripts]
44
+ reino = "reinogent.cli:main"
45
+
46
+ [tool.setuptools.packages.find]
47
+ where = ["."]
48
+ include = ["reinogent*", "reino_cli*"]
@@ -0,0 +1,3 @@
1
+ """ReinoGent CLI package."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,7 @@
1
+ """Backward-compatible shim forwarding to `reinogent.cli`."""
2
+ from reinogent.cli import build_parser, main
3
+
4
+ __all__ = ["build_parser", "main"]
5
+
6
+ if __name__ == "__main__":
7
+ main()
@@ -0,0 +1,52 @@
1
+ """
2
+ ReinoGent Python SDK & CLI
3
+ Discover, download, package, install dependencies for, and run AI Models,
4
+ MCP Servers, and Agents.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ from reinogent.agent_app import AgentApp, AgentContext
9
+ from reinogent.bundle import (
10
+ ENTRYPOINT_FILENAME,
11
+ MANIFEST_FILENAME,
12
+ load_bundle_manifest,
13
+ run_bundle,
14
+ write_bundle_entrypoint,
15
+ write_bundle_manifest,
16
+ )
17
+ from reinogent.client import (
18
+ DEFAULT_API_URL,
19
+ ReinoClient,
20
+ download_model,
21
+ get_mcp_config,
22
+ get_model,
23
+ infer_model_dependencies,
24
+ install_python_packages,
25
+ load_model,
26
+ run_agent,
27
+ verify_signature,
28
+ )
29
+
30
+ __version__ = "0.1.0"
31
+
32
+ __all__ = [
33
+ "AgentApp",
34
+ "AgentContext",
35
+ "DEFAULT_API_URL",
36
+ "ENTRYPOINT_FILENAME",
37
+ "MANIFEST_FILENAME",
38
+ "ReinoClient",
39
+ "__version__",
40
+ "download_model",
41
+ "get_mcp_config",
42
+ "get_model",
43
+ "infer_model_dependencies",
44
+ "install_python_packages",
45
+ "load_bundle_manifest",
46
+ "load_model",
47
+ "run_agent",
48
+ "run_bundle",
49
+ "verify_signature",
50
+ "write_bundle_entrypoint",
51
+ "write_bundle_manifest",
52
+ ]
@@ -0,0 +1,226 @@
1
+ """
2
+ ReinoGent Native Agent Runtime (`reinogent.AgentApp`)
3
+ Provides a clean, high-level runtime for building ReinoGent-compatible hosted
4
+ or local agents with built-in HMAC-SHA256 verification, event routing, model
5
+ loading, and MCP tool configuration discovery.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import inspect
10
+ import os
11
+ from dataclasses import dataclass, field
12
+ from typing import Any, Callable, Dict, List, Optional
13
+
14
+ from reinogent.client import ReinoClient, verify_signature
15
+
16
+
17
+ @dataclass
18
+ class AgentContext:
19
+ """Context object passed into `@app.on_message` and `@app.on_event` handlers."""
20
+
21
+ event: str
22
+ input: str
23
+ conversation_id: str = ""
24
+ session_id: str = ""
25
+ user: Dict[str, Any] = field(default_factory=dict)
26
+ agent: Dict[str, Any] = field(default_factory=dict)
27
+ attachments: List[Dict[str, Any]] = field(default_factory=list)
28
+ history: List[Dict[str, Any]] = field(default_factory=list)
29
+ raw: Dict[str, Any] = field(default_factory=dict)
30
+ _app: Optional["AgentApp"] = field(default=None, repr=False)
31
+
32
+ def load_model(self, **kwargs: Any) -> Any:
33
+ if not self._app or not self._app.model_slug:
34
+ raise ValueError("No `model` slug configured on this AgentApp.")
35
+ return self._app.get_model(**kwargs)
36
+
37
+ @property
38
+ def mcp_configs(self) -> Dict[str, Any]:
39
+ if not self._app:
40
+ return {}
41
+ return self._app.get_mcp_configs()
42
+
43
+
44
+ class AgentApp:
45
+ """
46
+ Build a ReinoGent-compatible hosted or local agent in a few lines of Python.
47
+
48
+ Example:
49
+ import reinogent
50
+
51
+ app = reinogent.AgentApp(
52
+ name="Swahili Support Agent",
53
+ model="bge-small-en-v1-5",
54
+ mcp_tools=["github-mcp-server"],
55
+ )
56
+
57
+ @app.on_message
58
+ async def handle(ctx: reinogent.AgentContext):
59
+ return f"Echo: {ctx.input}"
60
+
61
+ if __name__ == "__main__":
62
+ app.serve(port=8001)
63
+ """
64
+
65
+ def __init__(
66
+ self,
67
+ name: str = "ReinoGent Agent",
68
+ secret_key: Optional[str] = None,
69
+ model: Optional[str] = None,
70
+ mcp_tools: Optional[List[str]] = None,
71
+ api_url: Optional[str] = None,
72
+ require_auth: bool = True,
73
+ ) -> None:
74
+ self.name = name
75
+ self.secret_key = (secret_key or os.getenv("REINO_AGENTS_API_KEY") or "").strip()
76
+ self.model_slug = (model or "").strip() or None
77
+ self.mcp_tool_slugs = [s.strip() for s in (mcp_tools or []) if s and s.strip()]
78
+ self.require_auth = require_auth
79
+ self.client = ReinoClient(api_url=api_url)
80
+
81
+ self._handlers: Dict[str, Callable[[AgentContext], Any]] = {}
82
+ self._default_handler: Optional[Callable[[AgentContext], Any]] = None
83
+ self._cached_model: Any = None
84
+ self._cached_mcp_configs: Optional[Dict[str, Any]] = None
85
+ self._asgi_app: Any = None
86
+
87
+ def on_event(self, event_name: str) -> Callable[[Callable[[AgentContext], Any]], Callable[[AgentContext], Any]]:
88
+ """Register a handler for a specific ReinoGent event (e.g. `chat.message`, `workflow.start`)."""
89
+ def decorator(fn: Callable[[AgentContext], Any]) -> Callable[[AgentContext], Any]:
90
+ self._handlers[event_name] = fn
91
+ return fn
92
+ return decorator
93
+
94
+ def on_message(self, fn: Callable[[AgentContext], Any]) -> Callable[[AgentContext], Any]:
95
+ """Register the primary handler for `chat.message` (and default fallback)."""
96
+ self._handlers["chat.message"] = fn
97
+ if self._default_handler is None:
98
+ self._default_handler = fn
99
+ return fn
100
+
101
+ def get_model(self, **kwargs: Any) -> Any:
102
+ if self._cached_model is None:
103
+ if not self.model_slug:
104
+ raise ValueError("AgentApp was initialized without a `model` slug.")
105
+ self._cached_model = self.client.load_model(self.model_slug, **kwargs)
106
+ return self._cached_model
107
+
108
+ def get_mcp_configs(self) -> Dict[str, Any]:
109
+ if self._cached_mcp_configs is None:
110
+ merged: Dict[str, Any] = {}
111
+ for slug in self.mcp_tool_slugs:
112
+ try:
113
+ merged[slug] = self.client.get_mcp_config(slug)
114
+ except Exception:
115
+ merged[slug] = {"slug": slug, "error": "Could not fetch MCP config"}
116
+ self._cached_mcp_configs = merged
117
+ return self._cached_mcp_configs
118
+
119
+ def verify_request_auth(
120
+ self,
121
+ body: Dict[str, Any],
122
+ signature: Optional[str] = None,
123
+ timestamp: Optional[str] = None,
124
+ reino_key: Optional[str] = None,
125
+ ) -> bool:
126
+ """Verify incoming ReinoGent gateway auth headers (HMAC-SHA256 or X-Reino-Key)."""
127
+ if not self.require_auth or not self.secret_key:
128
+ return True
129
+ if signature and timestamp:
130
+ return verify_signature(body, signature, timestamp, self.secret_key)
131
+ if reino_key:
132
+ return reino_key.strip() == self.secret_key
133
+ return False
134
+
135
+ async def dispatch(self, payload: Dict[str, Any]) -> Dict[str, Any]:
136
+ """Dispatch a ReinoGent payload dict to the matching handler (useful for HTTP and unit tests)."""
137
+ event = str(payload.get("event") or "chat.message")
138
+ ctx = AgentContext(
139
+ event=event,
140
+ input=str(payload.get("input") or ""),
141
+ conversation_id=str(payload.get("conversation_id") or ""),
142
+ session_id=str(payload.get("session_id") or ""),
143
+ user=payload.get("user") if isinstance(payload.get("user"), dict) else {},
144
+ agent=payload.get("agent") if isinstance(payload.get("agent"), dict) else {},
145
+ attachments=payload.get("attachments") if isinstance(payload.get("attachments"), list) else [],
146
+ history=payload.get("history") if isinstance(payload.get("history"), list) else [],
147
+ raw=payload,
148
+ _app=self,
149
+ )
150
+
151
+ handler = self._handlers.get(event) or self._default_handler
152
+ if handler is None:
153
+ return {"output": f"[{self.name}] Event '{event}' received."}
154
+
155
+ result = handler(ctx)
156
+ if inspect.isawaitable(result):
157
+ result = await result
158
+
159
+ if isinstance(result, dict):
160
+ return result
161
+ return {"output": "" if result is None else str(result)}
162
+
163
+ @property
164
+ def asgi(self) -> Any:
165
+ """Return a FastAPI ASGI application exposing `/invoke`, `/health`, and `/reino-manifest`."""
166
+ if self._asgi_app is not None:
167
+ return self._asgi_app
168
+
169
+ try:
170
+ from fastapi import FastAPI, Header, HTTPException, Request # type: ignore
171
+ except ImportError as exc:
172
+ raise ImportError(
173
+ 'Running AgentApp as an HTTP server requires FastAPI. Install with: pip install "reinogent[agent]"'
174
+ ) from exc
175
+
176
+ fastapi_app = FastAPI(title=self.name)
177
+
178
+ @fastapi_app.get("/health")
179
+ async def _health():
180
+ return {
181
+ "status": "ok",
182
+ "agent": self.name,
183
+ "sdk": "reinogent",
184
+ "model": self.model_slug,
185
+ "mcp_tools": self.mcp_tool_slugs,
186
+ }
187
+
188
+ @fastapi_app.get("/reino-manifest")
189
+ async def _manifest():
190
+ return {
191
+ "name": self.name,
192
+ "sdk": "reinogent",
193
+ "model": self.model_slug,
194
+ "mcp_tools": self.mcp_tool_slugs,
195
+ "events": sorted(self._handlers.keys()) or ["chat.message"],
196
+ }
197
+
198
+ @fastapi_app.post("/invoke")
199
+ async def _invoke(
200
+ request: Request,
201
+ x_reino_signature: Optional[str] = Header(default=None, alias="X-Reino-Signature"),
202
+ x_reino_timestamp: Optional[str] = Header(default=None, alias="X-Reino-Timestamp"),
203
+ x_reino_key: Optional[str] = Header(default=None, alias="X-Reino-Key"),
204
+ ):
205
+ body = await request.json()
206
+ if not self.verify_request_auth(
207
+ body=body,
208
+ signature=x_reino_signature,
209
+ timestamp=x_reino_timestamp,
210
+ reino_key=x_reino_key,
211
+ ):
212
+ raise HTTPException(status_code=401, detail="Invalid ReinoGent signature or API key.")
213
+ return await self.dispatch(body)
214
+
215
+ self._asgi_app = fastapi_app
216
+ return fastapi_app
217
+
218
+ def serve(self, host: str = "0.0.0.0", port: int = 8001) -> None:
219
+ """Launch the AgentApp with Uvicorn."""
220
+ try:
221
+ import uvicorn # type: ignore
222
+ except ImportError as exc:
223
+ raise ImportError(
224
+ 'Serving AgentApp requires Uvicorn. Install with: pip install "reinogent[agent]"'
225
+ ) from exc
226
+ uvicorn.run(self.asgi, host=host, port=port)