Skip to main content

Python SDK to track AI agents with Value actions and auto-instrument LLM calls (Gemini, LangChain)

Project description

Value Python SDK

PyPI version CI Python Versions License: MIT

Python SDK to track AI agents with Value actions and auto-instrument LLM calls (Gemini, LangChain).

Features

  • Value Actions: Track agent behavior using action_context with user_id and anonymous_id, send custom actions via ctx.send()
  • Auto-Instrumentation: Automatically capture LLM calls from Gemini and LangChain with zero code changes
  • OpenTelemetry-Based: Built on OpenTelemetry for standardized, vendor-neutral observability

Installation

Basic Installation

Install the core SDK without auto-instrumentation dependencies:

pip install value-python

With Google GenAI Auto-Instrumentation

Install with Google Generative AI (Gemini) auto-instrumentation support:

pip install value-python[genai]

With LangChain Auto-Instrumentation

Install with LangChain auto-instrumentation support:

pip install value-python[langchain]

With All Auto-Instrumentation Libraries

Install with all supported auto-instrumentation libraries:

pip install value-python[all]

Multiple Extras

You can also install multiple extras:

pip install value-python[genai,langchain]

Supported Platforms

  • Python: 3.9, 3.10, 3.11, 3.12, 3.13
  • Operating Systems: Linux, macOS, Windows

Quick Start

Basic Usage

import asyncio
from value import initialize_async

async def main():
    client = await initialize_async()

    async def process_data(data: str) -> str:
        print(f"Processing data: {data}")
        await asyncio.sleep(0.5)
        result = data.upper()

        with client.action_context(user_id="user123", anonymous_id="anon456") as ctx:
            ctx.send(
                action_name="transform_data",
                **{"value.action.description": f"Transformed data from {len(data)} to {len(result)} characters"}
            )
        return result

    result = await process_data("hello async world")
    print(f"Result: {result}")

asyncio.run(main())

Synchronous Usage

from value import initialize_sync

client = initialize_sync()

with client.action_context(user_id="user123") as ctx:
    # Your code here
    ctx.send(action_name="my_action", **{"custom.attribute": "value"})

Auto-Instrumentation

Enable automatic tracing for supported AI libraries:

from value import initialize_sync, auto_instrument

# Initialize the client
client = initialize_sync()

# Auto-instrument specific libraries
auto_instrument(["gemini", "langchain"])

# Or auto-instrument all available libraries
auto_instrument()

Google GenAI Example

from value import initialize_sync, auto_instrument
from google import genai

# Initialize Value client and auto-instrument
client = initialize_sync()
auto_instrument(["gemini"])

# Use Gemini as usual - traces are automatically captured
gemini_client = genai.Client(api_key="your-api-key")
response = gemini_client.models.generate_content(
    model="gemini-2.5-flash",
    contents=["Write a poem about tracing"]
)

print(response.text)

Configuration

Configure the SDK using environment variables:

Variable Description Default
VALUE_AGENT_SECRET Agent authentication secret Required
VALUE_OTEL_ENDPOINT OpenTelemetry collector endpoint http://localhost:4317
VALUE_BACKEND_URL Value Control Plane backend URL Required
VALUE_SERVICE_NAME Service name for OpenTelemetry resource value-control-agent
VALUE_CONSOLE_EXPORT Enable console span exporter for debugging false

Supported Auto-Instrumentation Libraries

Library Extra Instrumentor
Google Generative AI (Gemini) genai opentelemetry-instrumentation-google-generativeai
LangChain langchain opentelemetry-instrumentation-langchain

API Reference

Core Functions

  • initialize_sync() - Initialize a synchronous Value client
  • initialize_async() - Initialize an asynchronous Value client
  • auto_instrument(libraries=None) - Enable auto-instrumentation for specified libraries
  • uninstrument(libraries=None) - Disable auto-instrumentation
  • get_supported_libraries() - Get list of supported library names
  • is_library_available(library) - Check if a library's instrumentation is installed

Client Methods

  • action_context(user_id=None, anonymous_id=None) - Create a context for sending actions
  • ctx.send(action_name, **attributes) - Send an action with custom attributes

Development

Setup

# Clone the repository
git clone https://github.com/valmi-io/value-python.git
cd value-python

# Install dependencies
poetry install

# Install with all extras for development
poetry install --extras all

Running Tests

# Run tests
poetry run pytest

# Run tests with coverage
poetry run pytest --cov=value --cov-report=html

# Run specific test file
poetry run pytest tests/test_client.py

Code Quality

# Format code
poetry run black src/ tests/

# Lint code
poetry run ruff check src/ tests/

# Type check
poetry run mypy src/

Publishing

The package is automatically published to PyPI when a new release is created on GitHub.

Manual Publishing

# Build the package
poetry build

# Publish to TestPyPI (for testing)
poetry publish -r testpypi

# Publish to PyPI
poetry publish

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

Links

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

value_python-0.1.2.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

value_python-0.1.2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file value_python-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for value_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 474b5e060bdce58955f133e3b87ccd98027d353224ebf3812e9891495d1a24e0
MD5 00c69d8ed0b16e698422c992f7c990fd
BLAKE2b-256 4f4d6f64a91121c2a19ad2da91f7a9a249d69a77067918c1c4e7cd3ebbab20cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for value_python-0.1.2.tar.gz:

Publisher: publish.yml on valmi-io/value-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 value_python-0.1.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for value_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 72237d95e068763ebb247e53c4772c73f5fbbe92f7015611459ea0f0e5b27d00
MD5 e35ad479f7201da875948fa00ab5b4f4
BLAKE2b-256 a4493af53d8add4b0c3f72c7c126be80a896dcc0f6363a5b8feb08be8a8c8724

See more details on using hashes here.

Provenance

The following attestation bundles were made for value_python-0.1.2-py3-none-any.whl:

Publisher: publish.yml on valmi-io/value-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