Skip to main content

FluxLoop SDK for agent instrumentation and tracing

Project description

FluxLoop SDK

FluxLoop SDK for agent instrumentation and tracing.

Installation

pip install fluxloop

Quick Start

from fluxloop import trace, FluxLoopClient

# Initialize the client
client = FluxLoopClient()

# Use the trace decorator
@trace()
def my_agent_function(prompt: str):
    # Your agent logic here
    return result

Features

  • 🔍 Automatic Tracing: Instrument your agent code with simple decorators
  • 📊 Rich Context: Capture inputs, outputs, and metadata
  • 🔄 Async Support: Works with both sync and async functions
  • 🎯 Framework Integration: Built-in support for LangChain and LangGraph

Documentation

For detailed documentation, visit https://docs.fluxloop.dev

License

Apache License 2.0 - see LICENSE file for details

Framework Integration: Decorator Ordering and Safe Instrumentation

When integrating FluxLoop with external agent frameworks (e.g., ChatKit, LangChain), follow these rules to avoid type conflicts and ensure observations are captured reliably.

  • Outermost framework wrapper: If a framework provides its own decorator/wrapper that transforms a plain function into a framework-specific object (e.g., a Tool), that decorator MUST be the outermost (top) decorator. This preserves the type the framework expects.
  • FluxLoop instrumentation inside: Place FluxLoop decorators inside (below) the framework decorator, or instrument from within the function body using the SDK context APIs.

Two safe patterns:

  • Pattern A (safest, framework-agnostic): instrument inside the function body

    • Use get_current_context() and push/pop an ObservationData manually around your logic. This keeps signatures and framework typing unchanged.

    • Example (tool function):

      from fluxloop import get_current_context
      from fluxloop.models import ObservationData, ObservationType
      
      async def my_tool(param: str) -> dict:
          fl_ctx = get_current_context()
          obs = None
          if fl_ctx and fl_ctx.is_enabled():
              obs = ObservationData(
                  type=ObservationType.TOOL,
                  name="tool.my_tool",
                  input={"args": {"param": param}},
              )
              fl_ctx.push_observation(obs)
      
          try:
              result = {"result": do_work(param)}
              if obs:
                  obs.output = result
              return result
          except Exception as e:
              if obs:
                  obs.error = str(e)
              raise
          finally:
              if fl_ctx and obs:
                  fl_ctx.pop_observation()
      
  • Pattern B (stacking decorators): framework outermost, FluxLoop inside

    • Example with a framework tool decorator:

      @framework_tool_decorator(...)
      @fluxloop.tool(name="tool.my_tool")
      async def my_tool(...):
          ...
      
    • Important: If you reverse the order (FluxLoop outside), the framework may see a plain function instead of its expected type and raise errors like "Unknown tool type".

LLM/streaming calls:

  • For LLM calls (including async generators/streams), either:
    • Wrap the call site in a small helper decorated with @fluxloop.prompt(...), or
    • Use with fluxloop.instrument("prompt.name"): around the portion that produces model output, ensuring it runs inside the current FluxLoop context.

These patterns guarantee observations are captured (tool, generation) while keeping the external framework’s type system intact.

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

fluxloop-0.1.6.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

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

fluxloop-0.1.6-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file fluxloop-0.1.6.tar.gz.

File metadata

  • Download URL: fluxloop-0.1.6.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fluxloop-0.1.6.tar.gz
Algorithm Hash digest
SHA256 fa2d987d25e33c5457660288c34af826aa95e79c72b0ba3ded10529c3c3abc5e
MD5 b4d61f8b5d38e667e34616401650f45a
BLAKE2b-256 6a048e4a1a0e2f6ec7532dcf677faba8b13feb121fb2b6b8cef66898103f992d

See more details on using hashes here.

File details

Details for the file fluxloop-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: fluxloop-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for fluxloop-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bf5b4959f6961af0a09a3bfb277de093ead88090e18001b223f8e28b8b9881c2
MD5 60055ba5cfa08dfe6d2965467d9a02c8
BLAKE2b-256 85858789912bed060d249f2eef6dd5e1720c61caec87030bfe21648772dbf7a8

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