55<h1 align =" center " >Latence TRACE Python SDK</h1 >
66
77<p align =" center " >
8- Real-time protection for AI agents. Verify answers, redact private data,
9- reduce wasted context, and log decisions without replacing your stack.
8+ Stateless retrieval quality for knowledge agents. Groundedness verification,
9+ context compression, privacy redaction, and context utilization scoring
10+ — without replacing your stack.
1011</p >
1112
1213<p align =" center " >
@@ -44,26 +45,24 @@ print(score.runtime_decision)
4445
4546## Why This Exists
4647
47- Agents are moving from demos into real workflows. That means private data,
48- unsupported answers, prompt attacks, tool drift, and wasted memory are no longer
49- abstract research problems. They become support escalations, broken automations,
50- audit gaps, token waste, and user trust issues.
48+ Knowledge agents are moving from demos into real workflows. That means private
49+ data, unsupported answers, and wasted context are no longer abstract research
50+ problems. They become support escalations, audit gaps, token waste, and user
51+ trust issues.
5152
52- TRACE is the protection layer that sits next to your RAG pipeline, coding agent,
53- or tool-using workflow. Your agent keeps running. TRACE checks the turn and
54- returns evidence plus a decision your application can route.
53+ TRACE is the retrieval quality layer that sits next to your RAG pipeline or
54+ knowledge workflow. Your agent keeps running. TRACE checks the turn and returns
55+ evidence plus a decision your application can route.
5556
5657## What TRACE Does
5758
5859TRACE is intentionally small at the SDK layer. The heavy work lives in your
5960TRACE runtime deployment; this package is the thin Python interface.
6061
61- - Verify RAG answers against retrieved context.
62- - Score coding-agent output against codebase context.
63- - Redact private data before it spreads through tools, logs, or prompts.
64- - Compress and repair long-running context with InfiniMem.
65- - Roll up an agent session into review-ready signals.
66- - Persist caller-carried state without forcing sticky server sessions.
62+ - ** Groundedness** — verify RAG answers against retrieved context.
63+ - ** Compression** — reduce long context to what matters.
64+ - ** Privacy** — redact private data before it spreads through tools, logs, or prompts.
65+ - ** Context utilization** — score which retrieved chunks are actually used.
6766
6867## Proof Points
6968
@@ -72,17 +71,12 @@ microbenchmarks. See the linked artifacts for full context.
7271
7372- Grounding: local managed-runtime 360 reported ` 1.00 ` AUROC for grounded vs.
7473 ungrounded RAG cases.
75- - Coding agents: local 360 reported ` 1.00 ` AUROC for code phantom detection.
76- - Wasted context: held-out unused-context classification reported ` 1.00 `
74+ - Context utilization: held-out unused-context classification reported ` 1.00 `
7775 precision and ` 1.00 ` recall.
78- - Latency: local concurrency burst reported about ` 368 ms ` RAG p95 and
79- ` 334 ms ` code p95 in the managed-runtime proof.
76+ - Latency: local concurrency burst reported about ` 368 ms ` RAG p95 in the
77+ managed-runtime proof.
8078- Privacy: redaction returns labels, offsets, scores, redacted output, entity
8179 counts, and timings for logging-ready GDPR workflows.
82- - Memory: InfiniMem is designed for up to ` 90% ` context reduction while keeping
83- hot context available to the agent.
84- - Guard checks: Prompt Guard warmup proved ` torch.compile ` enabled on CUDA in
85- the runtime proof.
8680
8781Evidence:
8882
@@ -118,14 +112,10 @@ export LATENCE_TRACE_URL="https://your-trace-endpoint.example.com"
118112
119113The SDK mirrors the TRACE product API directly:
120114
121- - Privacy: ` client.privacy.redact(...) `
122115- RAG grounding: ` client.grounding.rag(...) `
123- - Code grounding: ` client.grounding.code(...) `
124116- Text compression: ` client.compression.text(...) `
125117- Message compression: ` client.compression.messages(...) `
126- - Memory update: ` client.memory.step(...) `
127- - Stateless rollup: ` client.rollup(...) `
128- - Caller-carried sessions: ` client.session(...) `
118+ - Privacy: ` client.privacy.redact(...) `
129119
130120` Latence ` is synchronous. ` AsyncLatence ` exposes the same surface for asyncio
131121services.
@@ -157,21 +147,6 @@ if score.risk_band.value != "green":
157147
158148Example: [ RAG grounding with guard checks] ( examples/rag_grounding_guard.py )
159149
160- ### Coding Agents
161-
162- Use TRACE when an agent explains, edits, or reasons over code.
163-
164- ``` python
165- score = trace.grounding.code(
166- query = " Does this patch add retry handling?" ,
167- response_text = agent_answer,
168- raw_context = code_context,
169- extra = {" response_language_hint" : " python" },
170- )
171- ```
172-
173- Example: [ Code grounding] ( examples/code_grounding.py )
174-
175150### Privacy
176151
177152Use TRACE before customer data enters prompts, tools, traces, or logs.
@@ -187,7 +162,7 @@ print(redacted.unique_labels)
187162
188163Example: [ Privacy redaction] ( examples/privacy_redact.py )
189164
190- ### Compression And Memory
165+ ### Compression
191166
192167Use TRACE when long-running workflows start dragging dead context forward.
193168
@@ -198,51 +173,16 @@ compressed = trace.compression.text(
198173)
199174```
200175
201- ``` python
202- memory = trace.memory.step(
203- turn_text = " User asked for manual refund approval." ,
204- prior_memory_state = current_state,
205- )
206- current_state = memory.next_memory_state
207- ```
208-
209- Examples: [ Compression] ( examples/compression.py ) , [ Memory step] ( examples/memory_step.py )
210-
211- ### Sessions
212-
213- TRACE runtimes can stay stateless while the SDK carries state for your agent.
214-
215- ``` python
216- from latence import FileSessionStorage, Latence
217-
218- trace = Latence()
219- session = trace.session(
220- session_id = " support-run-42" ,
221- storage = FileSessionStorage(" .trace-sessions" ),
222- )
223-
224- session.event(" tool" , " loaded refund policy" )
225- session.memory_step(turn_text = " Keep finance approval as required context." )
226- score = session.rag(
227- query = " Can I promise the refund?" ,
228- response_text = " Yes, the refund is guaranteed in 48 hours." ,
229- raw_context = " Refunds require manual finance approval." ,
230- )
231- session.save()
232- ```
233-
234- Docs: [ Sessions] ( docs/sessions.md )
235- Example: [ Session facade] ( examples/session_facade.py )
176+ Example: [ Compression] ( examples/compression.py )
236177
237178## For Whom
238179
239180TRACE is for teams building or operating:
240181
241182- RAG products where unsupported answers are expensive.
242- - Coding agents that need codebase-grounded reasoning over many steps.
243- - Support agents that touch customer records and policies.
183+ - Knowledge agents that touch customer records and policies.
244184- Legal, finance, healthcare, or regulated workflows that need evidence.
245- - Internal agent platforms where observability, retries, and human review matter.
185+ - Internal platforms where observability, retries, and human review matter.
246186
247187It is also useful for framework authors and platform teams that need one
248188consistent protection API across LangGraph, LangChain, LlamaIndex, n8n, Cursor,
@@ -281,10 +221,10 @@ async with AsyncLatence() as trace:
281221
282222## Now What
283223
284- If you are integrating TRACE into an agent:
224+ If you are integrating TRACE into a knowledge agent:
285225
2862261 . Run the [ quickstart] ( docs/quickstart.md ) .
287- 2 . Pick one product path: RAG, code , privacy, compression, memory, or session .
227+ 2 . Pick one product path: groundedness, compression , privacy, or context utilization .
2882283 . Add one route in your app for ` green ` , ` amber ` , and ` red ` .
2892294 . Log request ID, risk band, runtime decision, and redacted evidence.
2902305 . Replay a few real failures and tune your thresholds.
0 commit comments