Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uselemma_tracing-4.0.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uselemma_tracing-4.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file uselemma_tracing-4.0.1.tar.gz.

File metadata

  • Download URL: uselemma_tracing-4.0.1.tar.gz
  • Upload date:
  • Size: 7.1 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

Hashes for uselemma_tracing-4.0.1.tar.gz
Algorithm Hash digest
SHA256 92feedc5891ea6b749c7afab826d94468a9dad6bdefe3eb55c0fc6ce8c50ccec
MD5 73408484b8b11ea5c18dfa9519d50bbe
BLAKE2b-256 729f95bce606dc1f5ab1538aaa192e4a13b925f53d74d646071b1555e2b53b5e

See more details on using hashes here.

File details

Details for the file uselemma_tracing-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: uselemma_tracing-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 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

Hashes for uselemma_tracing-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a46aefa1b622739e19f37111a219912615c26c5a3eeffacdfbe380602495c756
MD5 ab21a4306750b0ee23bebf57ab4a79fa
BLAKE2b-256 1216d26881f4d6a44f1f28d91ffdc92013fce0ec0f1abbe90c6d41532398fb7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page