Skip to main content

bai-langfuse

BAI 프로젝트 공통 Langfuse 연동 패키지. Core Agent와 Sub Agent 모두에서 사용합니다.

설정은 환경 변수로만 합니다. config / settings 모듈에 의존하지 않습니다.

환경 변수

변수 설명 기본값
LANGFUSE_ENABLED Langfuse 사용 여부 true
LANGFUSE_PUBLIC_KEY Langfuse Public Key (필수)
LANGFUSE_SECRET_KEY Langfuse Secret Key (필수)
LANGFUSE_HOST Langfuse 서버 URL https://langfuse.bai.biztechi.biz
ENVIRONMENT development이면 Langfuse 호스트에 대해 SSL 검증 비활성화 development
AGENT_TYPE 메타데이터용 (예: Core, HR, Management) Core

설치

로컬에서 다른 BAI 앱과 함께 사용할 때 (동일 저장소 내):

# bai-core-agent 또는 bai-sub-agent 디렉터리에서
pip install -e ../bai-langfuse

또는 각 앱의 requirements.txt에 -e ../bai-langfuse가 포함되어 있으면:

pip install -r requirements.txt

API 요약

공통 (Core / Sub 공통)

  • get_langfuse_callback(trace_id=None, session_id=None, user_id=None, parent_observation_id=None, trace_name=None)
    LangChain용 CallbackHandler 생성.
    • Core: trace_id + trace_name="사용자 요청"
    • Sub: trace_id + parent_observation_id (config.metadata에서 전달)
  • create_child_span(trace_id, name, parent_observation_id=None)
    자식 span 생성.
  • get_current_observation_id()
    현재 observation ID 조회.
  • flush_langfuse()
    대기 중인 데이터 전송.
  • get_usage_from_response(response)
    AIMessage 등에서 usage dict 추출 (input/output/cache 토큰).

Core Agent 전용

  • log_llm_generation(state, node_name, llm, messages, response, output_extractor=None)
    state에서 context.trace_id를 읽어 LLM generation 로깅.
  • CaptureAIMessageCallback(storage)
    LLM 호출 시 AIMessage 캡처 (usage 확인용).

Sub Agent 전용

  • log_llm_generation_span(node_name, trace_id, model, input_prompt=None, input_messages=None, output="", usage=None, model_parameters=None, parent_observation_id=None)
    trace_id/model/input/output/usage를 직접 넘겨 generation 로깅.

사용 예 (Core Agent)

from bai_langfuse import (
    get_langfuse_callback,
    flush_langfuse,
    log_llm_generation,
    get_usage_from_response,
    CaptureAIMessageCallback,
    create_child_span,
    get_current_observation_id,
)

# 콜백 (trace 이름 지정)
callback = get_langfuse_callback(
    trace_id=trace_id,
    session_id=session_id,
    user_id=user_id,
    trace_name="사용자 요청",
)
# LLM 호출 후
flush_langfuse()

사용 예 (Sub Agent)

from bai_langfuse import (
    get_langfuse_callback,
    create_child_span,
    get_current_observation_id,
    log_llm_generation_span,
)

# 콜백 (parent_observation_id로 Core와 계층 연결)
callback = get_langfuse_callback(
    trace_id=trace_id,
    user_id=user_id,
    session_id=session_id,
    parent_observation_id=parent_observation_id,
)
# 노드 내 span
span_ctx = create_child_span(trace_id, "NodeName", get_current_observation_id())
if span_ctx:
    with span_ctx:
        ...
# 명시적 generation 로깅 (선택)
log_llm_generation_span(
    node_name="Generator",
    trace_id=trace_id,
    model="claude-3-5-sonnet",
    input_messages=messages,
    output=response_text,
    usage={"input": 100, "output": 50},
)

의존성

  • langfuse (>=2.0)
  • langchain-core (>=0.2)
  • requests (>=2.28)

Metadata

Release files for bai-langfuse 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bai-langfuse 0.1.0
File Size Uploaded Provenance
bai_langfuse-0.1.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bai-langfuse 0.1.0
File Interpreter ABI Platform
bai_langfuse-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / bai_langfuse-0.1.0.tar.gz

Download URL bai_langfuse-0.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
249b2379441b36ab42fec7086cb6fcf78765cd6b8d4fd7e875d6212bbb03fa9c
BLAKE2b-256 checksum
How to use checksums
5a066e5d4506926df7fa325962c2582a2c769fa57fe28c826ca85c1e7409115c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / bai_langfuse-0.1.0-py3-none-any.whl

Download URL bai_langfuse-0.1.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5b79e8bdfeb4e5e40b31ec8e630f9315e7aaaa993c3575c4661a6c0fd7e3d9e
BLAKE2b-256 checksum
How to use checksums
b922500ed2d0aa4df5702c9f0b8f0e3f6f0bc4ed4a81407dc52ccb1162039746
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for bai-langfuse 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page