agntz 0.0.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.
Files changed (66) hide show
  1. agntz-0.0.0/.gitignore +9 -0
  2. agntz-0.0.0/CHANGELOG.md +7 -0
  3. agntz-0.0.0/PKG-INFO +421 -0
  4. agntz-0.0.0/README.md +399 -0
  5. agntz-0.0.0/pyproject.toml +59 -0
  6. agntz-0.0.0/src/agntz/__init__.py +165 -0
  7. agntz-0.0.0/src/agntz/_db.py +52 -0
  8. agntz-0.0.0/src/agntz/agent_ref.py +77 -0
  9. agntz-0.0.0/src/agntz/cli/__init__.py +78 -0
  10. agntz-0.0.0/src/agntz/client/__init__.py +77 -0
  11. agntz-0.0.0/src/agntz/client/_sse.py +92 -0
  12. agntz-0.0.0/src/agntz/client/client.py +1440 -0
  13. agntz-0.0.0/src/agntz/client/errors.py +32 -0
  14. agntz-0.0.0/src/agntz/client/events.py +128 -0
  15. agntz-0.0.0/src/agntz/client/models.py +370 -0
  16. agntz-0.0.0/src/agntz/context.py +214 -0
  17. agntz-0.0.0/src/agntz/core/__init__.py +56 -0
  18. agntz-0.0.0/src/agntz/core/http_tool.py +81 -0
  19. agntz-0.0.0/src/agntz/core/ids.py +23 -0
  20. agntz-0.0.0/src/agntz/core/litellm_provider.py +290 -0
  21. agntz-0.0.0/src/agntz/core/mcp_tool.py +52 -0
  22. agntz-0.0.0/src/agntz/core/model_provider.py +80 -0
  23. agntz-0.0.0/src/agntz/core/resources.py +92 -0
  24. agntz-0.0.0/src/agntz/core/tools.py +48 -0
  25. agntz-0.0.0/src/agntz/evals.py +646 -0
  26. agntz-0.0.0/src/agntz/manifest/__init__.py +65 -0
  27. agntz-0.0.0/src/agntz/manifest/conditions.py +92 -0
  28. agntz-0.0.0/src/agntz/manifest/executor.py +157 -0
  29. agntz-0.0.0/src/agntz/manifest/parser.py +205 -0
  30. agntz-0.0.0/src/agntz/manifest/state.py +93 -0
  31. agntz-0.0.0/src/agntz/manifest/template.py +148 -0
  32. agntz-0.0.0/src/agntz/manifest/types.py +119 -0
  33. agntz-0.0.0/src/agntz/manifest/validate.py +114 -0
  34. agntz-0.0.0/src/agntz/memrez.py +794 -0
  35. agntz-0.0.0/src/agntz/memrez_llm_reasoner.py +358 -0
  36. agntz-0.0.0/src/agntz/memrez_postgres.py +476 -0
  37. agntz-0.0.0/src/agntz/memrez_provider.py +399 -0
  38. agntz-0.0.0/src/agntz/memrez_reasoner.py +156 -0
  39. agntz-0.0.0/src/agntz/memrez_sqlite.py +423 -0
  40. agntz-0.0.0/src/agntz/py.typed +1 -0
  41. agntz-0.0.0/src/agntz/resources/__init__.py +3 -0
  42. agntz-0.0.0/src/agntz/resources/memrez.py +82 -0
  43. agntz-0.0.0/src/agntz/sdk/__init__.py +5 -0
  44. agntz-0.0.0/src/agntz/sdk/local.py +2061 -0
  45. agntz-0.0.0/src/agntz/stores/__init__.py +29 -0
  46. agntz-0.0.0/src/agntz/stores/memory.py +807 -0
  47. agntz-0.0.0/src/agntz/stores/postgres.py +1282 -0
  48. agntz-0.0.0/src/agntz/stores/sqlite.py +1241 -0
  49. agntz-0.0.0/tests/cli/test_cli.py +57 -0
  50. agntz-0.0.0/tests/client/test_client_memory.py +178 -0
  51. agntz-0.0.0/tests/client/test_hosted_client.py +460 -0
  52. agntz-0.0.0/tests/contracts/test_memrez_contracts.py +97 -0
  53. agntz-0.0.0/tests/contracts/test_phase0_contracts.py +88 -0
  54. agntz-0.0.0/tests/manifest/test_manifest_contract.py +158 -0
  55. agntz-0.0.0/tests/sdk/test_local_memory_resource.py +51 -0
  56. agntz-0.0.0/tests/sdk/test_local_sdk.py +896 -0
  57. agntz-0.0.0/tests/test_context_memrez.py +216 -0
  58. agntz-0.0.0/tests/test_evals.py +138 -0
  59. agntz-0.0.0/tests/test_memrez_deletes.py +144 -0
  60. agntz-0.0.0/tests/test_memrez_postgres.py +173 -0
  61. agntz-0.0.0/tests/test_memrez_reasoner.py +310 -0
  62. agntz-0.0.0/tests/test_memrez_resource_provider.py +296 -0
  63. agntz-0.0.0/tests/test_memrez_sqlite.py +125 -0
  64. agntz-0.0.0/tests/test_namespace_root_store.py +60 -0
  65. agntz-0.0.0/tests/test_postgres_store.py +231 -0
  66. agntz-0.0.0/tests/test_postgres_store_unit.py +8 -0
agntz-0.0.0/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ .pytest_cache/
3
+ .ruff_cache/
4
+ .basedpyright/
5
+ __pycache__/
6
+ *.py[cod]
7
+ dist/
8
+ build/
9
+ *.egg-info/
@@ -0,0 +1,7 @@
1
+ # agntz
2
+
3
+ ## 0.0.0 - 2026-06-26
4
+
5
+ - Establish the public baseline for the Python SDK.
6
+ - Includes hosted sync/async clients, local manifest execution, resources, memrez integration, namespace grants, eval helpers, in-memory/SQLite/Postgres stores, and typed package exports.
7
+ - Earlier PyPI releases were experimental pre-baseline iterations and should be yanked on the registry.
agntz-0.0.0/PKG-INFO ADDED
@@ -0,0 +1,421 @@
1
+ Metadata-Version: 2.4
2
+ Name: agntz
3
+ Version: 0.0.0
4
+ Summary: Python SDK and hosted client for Agntz
5
+ Author: Agntz
6
+ License: MIT
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: httpx>=0.28.0
9
+ Requires-Dist: pydantic>=2.8.0
10
+ Requires-Dist: pyyaml>=6.0.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: basedpyright>=1.31.0; extra == 'dev'
13
+ Requires-Dist: build>=1.2.0; extra == 'dev'
14
+ Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
15
+ Requires-Dist: pytest>=8.3.0; extra == 'dev'
16
+ Requires-Dist: ruff>=0.8.0; extra == 'dev'
17
+ Provides-Extra: litellm
18
+ Requires-Dist: litellm>=1.75.0; extra == 'litellm'
19
+ Provides-Extra: postgres
20
+ Requires-Dist: psycopg[binary]>=3.2.0; extra == 'postgres'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Agntz Python
24
+
25
+ Python SDK and hosted client for Agntz.
26
+
27
+ The compatibility rule is simple: an agent definition YAML file should have the
28
+ same observable behavior in the TypeScript and Python runtimes. Python code uses
29
+ Python naming conventions, but the agent, run, session, trace, and tool concepts
30
+ match the TypeScript SDK.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install agntz
36
+ ```
37
+
38
+ For local LLM execution through LiteLLM:
39
+
40
+ ```bash
41
+ pip install "agntz[litellm]"
42
+ ```
43
+
44
+ For local LLM execution with Postgres-backed stores:
45
+
46
+ ```bash
47
+ pip install "agntz[postgres,litellm]"
48
+ ```
49
+
50
+ ## Create an agent
51
+
52
+ Save this as `agents/support.yaml`:
53
+
54
+ ```yaml
55
+ id: support
56
+ kind: llm
57
+ name: Support Assistant
58
+ description: Answers support questions with a concise plan.
59
+ model:
60
+ provider: openai
61
+ name: gpt-5.4
62
+ temperature: 0.2
63
+ instruction: |
64
+ You are a careful support agent.
65
+ prompt: |
66
+ Help with this request: {{userQuery}}
67
+ inputSchema:
68
+ userQuery: string
69
+ outputSchema:
70
+ answer: string
71
+ confidence: number
72
+ ```
73
+
74
+ The same file can be loaded by the TypeScript and Python SDKs.
75
+
76
+ ## Run locally
77
+
78
+ ```python
79
+ from agntz import LiteLLMModelProvider, agntz
80
+
81
+ client = agntz(
82
+ agents="./agents",
83
+ model_provider=LiteLLMModelProvider(),
84
+ )
85
+
86
+ result = client.agents.run(
87
+ agent_id="support",
88
+ input={"userQuery": "Help me debug this invoice"},
89
+ )
90
+
91
+ print(result.output)
92
+ print(result.session_id)
93
+ ```
94
+
95
+ Use `client.agents.arun(...)` inside an existing event loop.
96
+
97
+ ## Hosted client
98
+
99
+ ```python
100
+ import os
101
+ from agntz import AgntzClient
102
+
103
+ client = AgntzClient(
104
+ api_key=os.environ["AGNTZ_API_KEY"],
105
+ base_url="https://api.agntz.co",
106
+ )
107
+
108
+ result = client.agents.run(agent_id="support", input="Hello")
109
+ ```
110
+
111
+ The async hosted client has the same resource shape:
112
+
113
+ ```python
114
+ from agntz import AsyncAgntzClient
115
+
116
+ async with AsyncAgntzClient(api_key="...", base_url="https://api.agntz.co") as client:
117
+ result = await client.agents.run(agent_id="support", input="Hello")
118
+ ```
119
+
120
+ Pass runtime namespace grants with `context` when the run needs resource access:
121
+
122
+ ```python
123
+ result = client.agents.run(
124
+ agent_id="support",
125
+ input="Hello",
126
+ context=["app/user/u_123"],
127
+ )
128
+ ```
129
+
130
+ ## Local tools
131
+
132
+ ```python
133
+ from typing import Any
134
+
135
+ from pydantic import BaseModel
136
+ from agntz import LiteLLMModelProvider, agntz, tool
137
+
138
+
139
+ class LookupInput(BaseModel):
140
+ order_id: str
141
+
142
+
143
+ def lookup_order(args: LookupInput) -> dict[str, Any]:
144
+ return {"status": "shipped", "eta": "Tomorrow"}
145
+
146
+
147
+ client = agntz(
148
+ agents="./agents",
149
+ tools=[
150
+ tool(
151
+ name="lookup_order",
152
+ description="Look up an order by ID",
153
+ input_schema=LookupInput,
154
+ execute=lookup_order,
155
+ )
156
+ ],
157
+ model_provider=LiteLLMModelProvider(),
158
+ )
159
+ ```
160
+
161
+ Reference the tool from YAML:
162
+
163
+ ```yaml
164
+ tools:
165
+ - kind: local
166
+ tools: [lookup_order]
167
+ ```
168
+
169
+ LLM agents can also call HTTP tools, MCP tools over HTTP JSON-RPC, and
170
+ agent-as-tool entries from the same manifest tool declarations used by the
171
+ TypeScript runtime.
172
+
173
+ ## Sessions
174
+
175
+ Pass the same `session_id` across runs to continue a conversation. Local
176
+ sessions are persisted by the configured store and are replayed into model calls.
177
+
178
+ ```python
179
+ first = client.agents.run(
180
+ agent_id="support",
181
+ input={"userQuery": "Hi, I need help"},
182
+ session_id="customer-42",
183
+ )
184
+
185
+ second = client.agents.run(
186
+ agent_id="support",
187
+ input={"userQuery": "My order is #12345"},
188
+ session_id=first.session_id,
189
+ )
190
+
191
+ messages = client.sessions.get_messages("customer-42")
192
+ ```
193
+
194
+ ## Runs and traces
195
+
196
+ Local execution records runs, sessions, and trace spans. The same store backs all
197
+ three surfaces.
198
+
199
+ ```python
200
+ runs = client.runs.list(status="completed")
201
+ trace_rows = client.traces.list(agent_id="support")
202
+
203
+ trace_id = trace_rows["rows"][0]["traceId"]
204
+ detail = client.traces.get(trace_id)
205
+
206
+ print(detail["summary"])
207
+ print(detail["spans"])
208
+ ```
209
+
210
+ ## SQLite persistence
211
+
212
+ ```python
213
+ from agntz import LiteLLMModelProvider, SQLiteStore, agntz
214
+
215
+ client = agntz(
216
+ agents="./agents",
217
+ store=SQLiteStore("./agntz.sqlite"),
218
+ model_provider=LiteLLMModelProvider(),
219
+ )
220
+ ```
221
+
222
+ SQLite persists local runs, trace spans, sessions, messages, agent versions,
223
+ aliases, datasets, evals, eval runs, latest scores, and API keys across process
224
+ restarts.
225
+
226
+ ## Versioned agents
227
+
228
+ Agents loaded from YAML files are imported into the configured store as
229
+ immutable versions. Unchanged files are deduped by content hash, so restarting a
230
+ local process does not create duplicate versions.
231
+
232
+ ```python
233
+ result = client.agents.run(
234
+ agent_id="support@latest",
235
+ input={"userQuery": "Help me debug this invoice"},
236
+ )
237
+
238
+ versions = client.agents.list_versions("support")
239
+ client.agents.set_alias("support", "stable", versions[0].created_at)
240
+
241
+ stable = client.agents.run(agent_id="support@stable", input={"userQuery": "Hello"})
242
+ exact = client.agents.run(
243
+ agent_id=f"support@{versions[0].created_at}",
244
+ input={"userQuery": "Replay this exact version"},
245
+ )
246
+ ```
247
+
248
+ The same resource exposes `list`, `get`, `create`, `update`, `delete`,
249
+ `get_version`, `activate_version`, `set_alias`, and `remove_alias` for local and
250
+ hosted clients.
251
+
252
+ ## Datasets and evals
253
+
254
+ Datasets are scoped to an agent, and eval definitions can point to a default
255
+ dataset. Eval runs preserve immutable history and update the latest score for
256
+ the eval, dataset, and resolved agent version.
257
+
258
+ ```python
259
+ dataset = client.datasets.create(
260
+ agent_id="support",
261
+ name="Refund checks",
262
+ items=[
263
+ {
264
+ "id": "refund-1",
265
+ "input": {"userQuery": "How do I request a refund?"},
266
+ "expected": {"intent": "refund"},
267
+ }
268
+ ],
269
+ )
270
+
271
+ definition = client.evals.create(
272
+ agent_id="support",
273
+ name="Support quality",
274
+ default_dataset_id=dataset.id,
275
+ criteria=[{"id": "helpful", "name": "Helpful", "threshold": 0.7}],
276
+ pass_threshold=0.7,
277
+ )
278
+
279
+ run = client.evals.run(eval_id=definition.id, agent_version="latest")
280
+ latest = client.evals.get_latest_score(
281
+ eval_id=definition.id,
282
+ dataset_id=dataset.id,
283
+ resolved_agent_version=run.agent_version,
284
+ )
285
+ ```
286
+
287
+ Hosted eval runs return immediately with `running` status. Poll
288
+ `client.evals.get_run(run.id)` or use `client.evals.cancel_run(run.id)` to stop a
289
+ run. Pending cases are marked `cancelled`; in-flight provider calls are
290
+ best-effort and may finish before the background runner observes cancellation.
291
+
292
+ ## Hosted deployments
293
+
294
+ Python no longer ships a hosted worker implementation. Use `AgntzClient` or
295
+ `AsyncAgntzClient` to call the TypeScript worker hosted by agntz.co or your own
296
+ self-hosted TS deployment. The Python package continues to support embedded
297
+ local execution, stores, resources, and memrez for in-process applications.
298
+
299
+ ## Memrez
300
+
301
+ The Python package includes namespace grants, the memrez core, memory resource
302
+ provider wiring, and in-memory/SQLite/Postgres memory stores. By default,
303
+ `create_memrez()` wires memrez's built-in LLM reasoner for tagging and
304
+ curation through direct LiteLLM calls. Install `agntz[litellm]` and set the
305
+ provider key for the default model, such as `OPENAI_API_KEY`, when you want
306
+ the default reasoner to run locally. Pass `DeterministicReasoner()` for tests
307
+ or no-LLM kill-switch behavior.
308
+
309
+ ```python
310
+ from agntz import LiteLLMModelProvider, agntz
311
+ from agntz.resources.memrez import SqliteMemoryStore, create_memrez
312
+
313
+ memrez = create_memrez(store=SqliteMemoryStore("./memory.db"))
314
+
315
+ client = agntz(
316
+ agents="./agents",
317
+ resources={"memory": memrez.provider()},
318
+ model_provider=LiteLLMModelProvider(),
319
+ )
320
+
321
+ client.agents.run(
322
+ agent_id="support-with-memory",
323
+ input="Remember that I prefer metric units.",
324
+ context=["app/user/u_123"],
325
+ )
326
+ ```
327
+
328
+ You can also use memrez directly:
329
+
330
+ ```python
331
+ memrez.write(["app/user/u_123"], "Prefers metric units.", topics_hint=["prefs"])
332
+ entries = memrez.read(["app/user/u_123"], "prefs")
333
+ ```
334
+
335
+ Configure invoke-time preload in the resource declaration. Topic taxonomy and
336
+ reasoner policy belong to Memrez-level configuration, not the agent manifest:
337
+
338
+ ```yaml
339
+ resources:
340
+ memory:
341
+ kind: memory
342
+ mode: read-write
343
+ preload:
344
+ core: true
345
+ topics: [goals, equipment]
346
+ limit: 30
347
+ maxChars: 10000
348
+ types: [fact, preference, summary]
349
+ ```
350
+
351
+ Override the reasoner explicitly when needed:
352
+
353
+ ```python
354
+ from agntz.resources.memrez import (
355
+ DeterministicReasoner,
356
+ ReasonerModelConfig,
357
+ create_memrez,
358
+ llm_reasoner,
359
+ )
360
+
361
+ memrez = create_memrez(
362
+ reasoner=llm_reasoner(
363
+ tagger_model=ReasonerModelConfig(provider="anthropic", name="claude-haiku-4-5")
364
+ )
365
+ )
366
+
367
+ test_memrez = create_memrez(reasoner=DeterministicReasoner())
368
+ ```
369
+
370
+ ## CLI
371
+
372
+ The terminal CLI is distributed through the Node package `@agntz/sdk`, while
373
+ Python service code uses the `agntz` Python package.
374
+
375
+ ```bash
376
+ npx @agntz/sdk create "Answer support questions in a concise tone" -o ./agents/support.yaml
377
+ npx @agntz/sdk run ./agents/support.yaml --input '{"userQuery":"hello"}'
378
+ npx @agntz/sdk --help
379
+ ```
380
+
381
+ Use Python code when the agent needs Python local tools, a Python resource
382
+ provider, or a Python store. The same YAML file can be loaded by both runtimes.
383
+
384
+ ## Current parity
385
+
386
+ Implemented in this package:
387
+
388
+ - Hosted sync and async clients for agents, versions, aliases, run, run stream,
389
+ async runs, traces, datasets, evals, eval runs, cancellation, and eval scores.
390
+ - Local YAML execution for `llm`, `tool`, `sequential`, and `parallel` agents.
391
+ - Local Python tools, HTTP tools, MCP JSON-RPC tools, and agent-as-tool calls.
392
+ - Versioned local and hosted agent resolution for bare ids, `@latest`, exact
393
+ timestamps, and aliases.
394
+ - First-class datasets, eval definitions, eval runs, and latest-score tracking.
395
+ - Runtime namespace grants, resource providers, and the memrez memory provider.
396
+ - Memrez LLM reasoner default, preload/topic policy, in-memory, SQLite, and
397
+ Postgres memory stores.
398
+ - LiteLLM-backed model execution with tool-call loop support.
399
+ - Memory, SQLite, and Postgres stores for local data including runs,
400
+ traces, sessions, agent versions, aliases, eval data, latest scores, and API
401
+ keys and namespace roots.
402
+ - Import surfaces for agents, sessions, and memory use Pythonic `import_`
403
+ methods on local and hosted clients.
404
+ - Contract fixtures shared with the TypeScript core manifest runtime.
405
+
406
+ Still intentionally outside this first Python package slice:
407
+
408
+ - The hosted product UI remains TypeScript.
409
+ - Terminal eval commands remain in the Node CLI.
410
+ - Streaming token deltas for local Python execution are not exposed yet.
411
+
412
+ ## Development
413
+
414
+ ```bash
415
+ python -m venv .venv
416
+ .venv/bin/python -m pip install -e '.[dev,litellm]'
417
+ .venv/bin/python -m pytest
418
+ .venv/bin/python -m ruff check .
419
+ .venv/bin/python -m basedpyright
420
+ .venv/bin/python -m build
421
+ ```