|
| 1 | +# Latence Python SDK |
| 2 | + |
| 3 | +Thin Python SDK for Latence TRACE. |
| 4 | + |
| 5 | +```bash |
| 6 | +pip install latence |
| 7 | +``` |
| 8 | + |
| 9 | +```python |
| 10 | +from latence import Latence |
| 11 | + |
| 12 | +client = Latence(api_key="lat_...") |
| 13 | + |
| 14 | +result = client.grounding.rag( |
| 15 | + query="When will this customer be refunded?", |
| 16 | + response_text="The customer will be refunded within 48 hours.", |
| 17 | + raw_context="Refunds are reviewed manually after finance approval.", |
| 18 | +) |
| 19 | + |
| 20 | +print(result.risk_band) |
| 21 | +``` |
| 22 | + |
| 23 | +## Surface |
| 24 | + |
| 25 | +The SDK maps 1:1 to the TRACE product API: |
| 26 | + |
| 27 | +- `client.privacy.redact(...)` |
| 28 | +- `client.grounding.rag(...)` |
| 29 | +- `client.grounding.code(...)` |
| 30 | +- `client.compression.text(...)` |
| 31 | +- `client.compression.messages(...)` |
| 32 | +- `client.memory.step(...)` |
| 33 | +- `client.rollup(...)` |
| 34 | +- `client.session(...)` |
| 35 | + |
| 36 | +`Latence` is the sync client. `AsyncLatence` exposes the same product namespaces for asyncio apps. |
| 37 | + |
| 38 | +## Sessions |
| 39 | + |
| 40 | +TRACE deployments are stateless by default. The SDK owns caller-carried session state for agent workflows that need memory continuity, rollups, idempotency, and local persistence. |
| 41 | + |
| 42 | +```python |
| 43 | +from latence import FileSessionStorage, Latence |
| 44 | + |
| 45 | +client = Latence(api_key="lat_...") |
| 46 | +session = client.session( |
| 47 | + session_id="support-run-42", |
| 48 | + storage=FileSessionStorage(".trace-sessions"), |
| 49 | +) |
| 50 | + |
| 51 | +session.event("tool", "loaded refund policy") |
| 52 | +session.memory_step(turn_text="Keep finance approval as required context.") |
| 53 | +score = session.rag( |
| 54 | + query="Can I promise the refund?", |
| 55 | + response_text="Yes, the refund is guaranteed in 48 hours.", |
| 56 | + raw_context="Refunds require manual finance approval.", |
| 57 | +) |
| 58 | +session.save() |
| 59 | +``` |
| 60 | + |
| 61 | +## Compatibility |
| 62 | + |
| 63 | +The primary import is: |
| 64 | + |
| 65 | +```python |
| 66 | +from latence import Latence, AsyncLatence |
| 67 | +``` |
| 68 | + |
| 69 | +For migration from the TRACE preview SDK, `LatenceTraceClient` and `AsyncLatenceTraceClient` remain aliases. |
| 70 | + |
| 71 | +## Development |
| 72 | + |
| 73 | +```bash |
| 74 | +python -m pip install -e ".[dev]" |
| 75 | +python -m pytest |
| 76 | +python -m ruff check . |
| 77 | +python -m build |
| 78 | +python -m twine check dist/* |
| 79 | +``` |
| 80 | + |
| 81 | +Set `LATENCE_TRACE_RUNTIME_REPO=/path/to/latence-trace` when running contract tests from a non-sibling checkout. |
0 commit comments