HTTP tracing SDK for Lemma
Project description
uselemma-tracing
HTTP tracing SDK for AI agents. The primary API sends completed trace payloads directly to Lemma.
Installation
pip install uselemma-tracing
Quick Start
from uselemma_tracing import Lemma
lemma = Lemma()
def run(trace):
docs = search_docs(user_message)
trace.record_tool(
name="search_docs",
input={"query": user_message},
output=docs,
duration_ms=25,
tool_parameters={"query": "string"},
)
response = call_model(user_message, docs)
trace.record_generation(
name="draft-reply",
input=response.messages,
output=response.text,
model="gpt-4o",
usage={
"input_tokens": response.usage.input_tokens,
"output_tokens": response.usage.output_tokens,
},
duration_ms=40,
llm_input_messages=[{"role": "user", "content": user_message}],
llm_invocation_parameters={"temperature": 0.2},
)
return response.text
answer = lemma.trace(
"support-agent",
run,
input=user_message,
thread_id=conversation_id,
user_id=user.id,
duration_ms=1234,
)
Live Spans
def run(trace):
span = trace.start_span(name="retrieve-context", input=query)
try:
docs = retrieve(query)
span.end(
output=docs,
duration_ms=250,
retrieval_documents=[
{"id": doc.id, "content": doc.text, "score": doc.score}
for doc in docs
],
)
return docs
except Exception as error:
span.end(status="ERROR", error=error)
raise
Pass duration_ms when you already measured a child span, generation, or tool call. When child records omit duration_ms, Lemma splits the parent's remaining unclaimed duration equally across siblings that also omitted duration.
Configuration
| Option | Environment variable | Default |
|---|---|---|
api_key |
LEMMA_API_KEY |
Required |
project_id |
LEMMA_PROJECT_ID |
Required |
base_url |
none | https://api.uselemma.ai |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uselemma_tracing-4.0.0.tar.gz.
File metadata
- Download URL: uselemma_tracing-4.0.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eb887303bba84b62dace65de2501fcaa43bacfbeccb324fef157e394e07fde2
|
|
| MD5 |
9642fd312f4c3820a367b77f3204609a
|
|
| BLAKE2b-256 |
de984ec729d077a48a4a2103f083f61ae90ce72e1654d75039351e05bf8d49e7
|
File details
Details for the file uselemma_tracing-4.0.0-py3-none-any.whl.
File metadata
- Download URL: uselemma_tracing-4.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cf87d0d46f091a1de47a005d9f465e395faf8f019905545390cf974bf56f2b0
|
|
| MD5 |
4b1e6692f601e4a0ef3e2bbe0e9a956e
|
|
| BLAKE2b-256 |
cb2fdf7988c567ac4d096a1285b65306cc0fd98b042878f318c0693a8c93fe47
|