@pentatonic-ai/ai-agent-sdk 0.10.26 → 0.10.28

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.
package/dist/index.cjs CHANGED
@@ -878,7 +878,7 @@ function fireAndForgetEmit(clientConfig, sessionOpts, messages, result, model) {
878
878
  }
879
879
 
880
880
  // src/telemetry.js
881
- var VERSION = "0.10.26";
881
+ var VERSION = "0.10.28";
882
882
  var TELEMETRY_URL = "https://sdk-telemetry.philip-134.workers.dev";
883
883
  function machineId() {
884
884
  const raw = typeof process !== "undefined" ? `${process.env?.USER || process.env?.USERNAME || "u"}:${process.platform || "x"}:${process.arch || "x"}` : "browser";
package/dist/index.js CHANGED
@@ -847,7 +847,7 @@ function fireAndForgetEmit(clientConfig, sessionOpts, messages, result, model) {
847
847
  }
848
848
 
849
849
  // src/telemetry.js
850
- var VERSION = "0.10.26";
850
+ var VERSION = "0.10.28";
851
851
  var TELEMETRY_URL = "https://sdk-telemetry.philip-134.workers.dev";
852
852
  function machineId() {
853
853
  const raw = typeof process !== "undefined" ? `${process.env?.USER || process.env?.USERNAME || "u"}:${process.platform || "x"}:${process.arch || "x"}` : "browser";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pentatonic-ai/ai-agent-sdk",
3
- "version": "0.10.26",
3
+ "version": "0.10.28",
4
4
  "description": "TES SDK — LLM observability and lifecycle tracking via Pentatonic Thing Event System. Track token usage, tool calls, and conversations. Manage things through event-sourced lifecycle stages with AI enrichment and vector search.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -460,7 +460,7 @@ class StoreRequest(BaseModel):
460
460
 
461
461
  class StoreBatchRequest(BaseModel):
462
462
  records: list[dict[str, Any]] = Field(default_factory=list)
463
- arena: str | None = "general"
463
+ arena: str | None = None # no "general" default — fail closed if absent
464
464
  # v1's optional pre-computed embeddings — passed through but we
465
465
  # re-embed regardless. The shared-embed optimisation lives at the
466
466
  # SDK level now (PR #58 retry-with-jitter); compat trusts the
@@ -611,7 +611,14 @@ async def _extract(arena: str, clientId: str, userId: str | None,
611
611
  return r.json()["event_id"]
612
612
 
613
613
 
614
- def _arena_of(meta: dict[str, Any] | None, fallback: str = "general") -> str:
614
+ def _arena_of(meta: dict[str, Any] | None, fallback: str | None = None) -> str | None:
615
+ # No "general" fallback. An arena-less write used to silently land in a
616
+ # shared "general" bucket that belongs to no tenant — a cross-tenant
617
+ # hazard (and the one thing that could co-mingle entities across tenants,
618
+ # since entity ids embed the arena). Callers MUST supply an arena; the
619
+ # /store + /store-batch handlers reject when this returns None. The SDK
620
+ # (engineStore/composeArena) always stamps one, so only a raw direct
621
+ # caller can hit the rejection — which is the point (fail closed).
615
622
  if not meta:
616
623
  return fallback
617
624
  if isinstance(meta.get("arena"), str) and meta["arena"]:
@@ -690,6 +697,10 @@ async def store(req: StoreRequest):
690
697
  { id, content, layerId, engine }."""
691
698
  meta = req.metadata or {}
692
699
  arena = _arena_of(meta)
700
+ if not arena:
701
+ # Fail closed: no arena = no tenant. Mirrors /search. (Was a silent
702
+ # "general" bucket — a cross-tenant hazard.)
703
+ raise HTTPException(400, "arena required")
693
704
  clientId = meta.get("clientId") or arena.split(":")[0]
694
705
  userId = meta.get("user_id") or (arena.split(":", 1)[1] if ":" in arena else None)
695
706
  source_kind = _source_kind_of(meta)
@@ -778,7 +789,7 @@ async def store_batch(req: StoreBatchRequest):
778
789
  if not req.records:
779
790
  return {"status": "ok", "inserted": 0, "ids": [], "engine": {}}
780
791
 
781
- arena_default = req.arena or "general"
792
+ arena_default = req.arena # may be None; per-record arena can still supply it
782
793
  texts = [r["content"] for r in req.records]
783
794
  embeddings = await _embed_batch(texts)
784
795
  if len(embeddings) != len(texts):
@@ -809,6 +820,10 @@ async def store_batch(req: StoreBatchRequest):
809
820
  for r in req.records:
810
821
  meta = r.get("metadata") or {}
811
822
  arena = _arena_of(meta, fallback=arena_default)
823
+ if not arena:
824
+ # Fail closed: every record needs an arena (batch-level or its own).
825
+ # No "general" bucket — an arena-less write belongs to no tenant.
826
+ raise HTTPException(400, "arena required (batch-level or per-record)")
812
827
  clientId = meta.get("clientId") or arena.split(":")[0]
813
828
  userId = meta.get("user_id") or (arena.split(":", 1)[1] if ":" in arena else None)
814
829
  source_kind = _source_kind_of(meta)
@@ -121,6 +121,16 @@ STUDENT_API_KEY = os.environ.get("STUDENT_API_KEY", "")
121
121
  STUDENT_MODEL = os.environ.get("STUDENT_MODEL", "nuextract-2.0-4b-ft")
122
122
  STUDENT_TIMEOUT_SEC = float(os.environ.get("STUDENT_TIMEOUT_SEC", "60"))
123
123
  STUDENT_MAX_TOKENS = int(os.environ.get("STUDENT_MAX_TOKENS", "768"))
124
+ # Student-path concurrency — SEPARATE from CONCURRENT_LLM_CALLS. That knob is
125
+ # tuned for the teacher (N concurrent 27B *batch* calls of EVENTS_PER_LLM_CALL
126
+ # events each); the cascade reused it to bound student calls, throttling a 4B
127
+ # model — which batches 30–60 single-event calls at <5% KV cache on an L4 — to
128
+ # just 6/worker. Under a bursty backlog that left the student GPU-pinned but
129
+ # starved (Running:1, Waiting:0, KV:0.1%; 25k-backlog incident 2026-07-08). Each
130
+ # student call is ONE event (tiny KV), so it parallelises far higher. Tune per
131
+ # the box's KV-cache headroom. Do NOT raise CONCURRENT_LLM_CALLS to fix student
132
+ # throughput — that also raises teacher 27B concurrency (OOM risk).
133
+ STUDENT_CONCURRENT_CALLS = int(os.environ.get("STUDENT_CONCURRENT_CALLS", "48"))
124
134
  # Fraction of student-passing events ALSO sent to the teacher — NOT a quality
125
135
  # lever, this is the monitoring + active-learning sample (drift detection and
126
136
  # fresh teacher-gold on live traffic). Default conservative-ish 5%.
@@ -2649,7 +2659,10 @@ async def _process_cascade(
2649
2659
  gates: a pass writes the student's extraction (producer='student'); a fail/
2650
2660
  sample escalates to the teacher. Disjoint — the student writes XOR the event
2651
2661
  is escalated, so there is nothing to supersede."""
2652
- sem = asyncio.Semaphore(CONCURRENT_LLM_CALLS)
2662
+ # STUDENT_CONCURRENT_CALLS, not CONCURRENT_LLM_CALLS: the student is a cheap
2663
+ # single-event 4B call that batches far higher than the teacher's 27B
2664
+ # batch-calls (see the config note). Reusing the teacher knob starved it.
2665
+ sem = asyncio.Semaphore(STUDENT_CONCURRENT_CALLS)
2653
2666
 
2654
2667
  async def _student(item):
2655
2668
  async with sem: