Skip to main content

Python SDK for NodeLoom AI agent monitoring and telemetry

Project description

NodeLoom Python SDK

Python SDK for instrumenting AI agents and sending telemetry to NodeLoom.

Features

  • Fire-and-forget telemetry that never blocks or crashes your application
  • Automatic batching and retry with exponential backoff
  • Context manager support for traces and spans
  • Built-in integrations for LangChain and CrewAI
  • Thread-safe client (individual traces/spans are single-threaded)
  • Bounded in-memory queue prevents unbounded memory growth
  • Configurable via constructor arguments

Requirements

  • Python 3.9+

Installation

pip install nodeloom-sdk

With LangChain integration:

pip install nodeloom-sdk[langchain]

With CrewAI integration:

pip install nodeloom-sdk[crewai]

Quick Start

from nodeloom import NodeLoom, SpanType

client = NodeLoom(api_key="sdk_your_api_key")

with client.trace("my-agent", input={"query": "What is NodeLoom?"}) as trace:
    with trace.span("llm-call", type=SpanType.LLM) as span:
        span.set_input({"messages": [{"role": "user", "content": "What is NodeLoom?"}]})
        # ... call your LLM ...
        span.set_output({"text": "NodeLoom is an AI agent operations platform."})
        span.set_token_usage(prompt=15, completion=20, model="gpt-4o")

client.shutdown()

Traces and Spans

A trace represents a single end-to-end agent execution. A span represents a unit of work within a trace (an LLM call, tool invocation, retrieval step, etc.).

Span Types

Type Description
SpanType.LLM Language model call
SpanType.TOOL Tool or function invocation
SpanType.RETRIEVAL Vector search or data retrieval
SpanType.CHAIN Pipeline or chain of steps
SpanType.AGENT Sub-agent invocation
SpanType.CUSTOM User-defined operation

Nested Spans

with client.trace("my-agent") as trace:
    with trace.span("agent-step", type=SpanType.AGENT) as parent:
        with trace.span("llm-call", type=SpanType.LLM, parent_span_id=parent.span_id) as child:
            child.set_output({"response": "..."})
            child.set_token_usage(prompt=10, completion=20, model="gpt-4o")

Standalone Events

client.event("guardrail_triggered", level=EventLevel.WARN, data={"rule": "pii_detected"})

Error Handling

Traces and spans used as context managers automatically catch exceptions, mark the span/trace as ERROR, and re-raise:

with client.trace("my-agent") as trace:
    with trace.span("risky-call", type=SpanType.TOOL) as span:
        raise ValueError("something went wrong")
        # span is automatically marked as ERROR
    # trace is automatically marked as ERROR

You can also set errors manually:

span.set_error("Connection timeout")
trace.end(status=TraceStatus.ERROR, error="Agent failed")

LangChain Integration

from nodeloom import NodeLoom
from nodeloom.integrations.langchain import NodeLoomCallbackHandler

client = NodeLoom(api_key="sdk_your_api_key")
handler = NodeLoomCallbackHandler(client)

# Pass the handler to any LangChain chain, agent, or LLM
result = chain.invoke(input, config={"callbacks": [handler]})

client.shutdown()

The callback handler automatically instruments LLM calls, chain runs, tool invocations, and retriever queries with proper parent-child span relationships.

CrewAI Integration

Decorator

from nodeloom import NodeLoom
from nodeloom.integrations.crewai import instrument_crew

client = NodeLoom(api_key="sdk_your_api_key")

@instrument_crew(client, agent_name="my-crew", agent_version="1.0.0")
def run_crew():
    crew = Crew(agents=[...], tasks=[...])
    return crew.kickoff()

run_crew()
client.shutdown()

Manual Instrumentation

from nodeloom.integrations.crewai import CrewAIInstrumentation

inst = CrewAIInstrumentation(client)
with inst.trace_crew("my-crew") as ctx:
    with ctx.task("research", agent="researcher") as span:
        result = do_research()
        span.set_output({"result": result})

Configuration

Parameter Default Description
api_key required SDK API key (starts with sdk_)
endpoint https://api.nodeloom.io NodeLoom API base URL
environment production Deployment environment label
batch_size 100 Max events per batch
flush_interval 5.0 Seconds between automatic flushes
max_retries 3 Retry attempts for failed requests
queue_max_size 10000 Max queued events before dropping
timeout 10.0 HTTP request timeout in seconds
enabled True Set to False to disable telemetry

Running Tests

pip install -e ".[dev]"
pytest

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

nodeloom_sdk-0.7.0.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

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

nodeloom_sdk-0.7.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file nodeloom_sdk-0.7.0.tar.gz.

File metadata

  • Download URL: nodeloom_sdk-0.7.0.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nodeloom_sdk-0.7.0.tar.gz
Algorithm Hash digest
SHA256 9efd9b391e6363530eacad1834a9da4b898be2f77463f408e8ee6b403bdbba53
MD5 e6557a7f4e5555d18e7bf10510102d2d
BLAKE2b-256 3dfe94c11d8f34fbbb8c3abe55abbf9f3dc2a285d0ec7dc44535e78e2caf7bfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for nodeloom_sdk-0.7.0.tar.gz:

Publisher: publish.yml on Nodeloom/nodeloom-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nodeloom_sdk-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: nodeloom_sdk-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nodeloom_sdk-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2166818c2125abab4793a1acd5334b20c32b31eb7849ff0b5d3aeee4412ee168
MD5 d42b24ea06b910c348838b2e66a15f95
BLAKE2b-256 20bce6985ae5e0ebbfe31fa53645166498ec27bb4bc5fb915876aaa06dc4ae86

See more details on using hashes here.

Provenance

The following attestation bundles were made for nodeloom_sdk-0.7.0-py3-none-any.whl:

Publisher: publish.yml on Nodeloom/nodeloom-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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