class langgraph_agent_toolkit.core.observability.langfuse.LangfuseObservability(remote_first=False)[source][source]

Bases: BaseObservabilityPlatform

Langfuse implementation of observability platform.

Initialize LangfuseObservability.

Parameters:

remote_first (bool) – If True, prioritize remote prompts over local ones.

__init__(remote_first=False)[source][source]

Initialize LangfuseObservability.

Parameters:

remote_first (bool) – If True, prioritize remote prompts over local ones.

property required_vars: List[str]
get_callback_handler(**kwargs)[source][source]

Get the Langfuse callback handler for LangChain.

Return type:

LangchainCallbackHandler

before_shutdown()[source][source]

Flush any pending data before shutdown.

Return type:

None

record_feedback(run_id, key, score, **kwargs)[source][source]

Record feedback/score for a trace in Langfuse.

Parameters:
Return type:

None

push_prompt(name, prompt_template, metadata=None, force_create_new_version=True)[source][source]

Push a prompt to Langfuse.

Parameters:
  • name (str) – Name of the prompt

  • prompt_template (str | List[ChatMessageDict]) – The prompt template (string or list of message dicts)

  • metadata (Dict[str, Any] | None) – Optional metadata including ‘labels’

  • force_create_new_version (bool) – If True, always create a new version

Return type:

None

pull_prompt(name, return_with_prompt_object=False, cache_ttl_seconds=DEFAULT_CACHE_TTL_SECOND, template_format='f-string', label=None, version=None, **kwargs)[source][source]

Pull a prompt from Langfuse.

Parameters:
  • name (str) – Name of the prompt

  • return_with_prompt_object (bool) – If True, return tuple of (prompt, langfuse_prompt)

  • cache_ttl_seconds (int | None) – Cache TTL for the prompt

  • template_format (Literal['f-string', 'mustache', 'jinja2']) – Format for the template

  • label (str | None) – Optional label to fetch specific version

  • version (int | None) – Optional version number to fetch

  • **kwargs – Additional kwargs (prompt_label, prompt_version as aliases)

Returns:

ChatPromptTemplate or tuple of (ChatPromptTemplate, langfuse_prompt)

Return type:

ChatPromptTemplate | str | dict | None | Tuple[ChatPromptTemplate | str | dict | None, Any]

delete_prompt(name)[source][source]

Delete a prompt - Langfuse doesn’t support programmatic deletion.

Parameters:

name (str)

Return type:

None

trace_context(run_id, **kwargs)[source][source]

Create a Langfuse trace context with predefined trace ID.

Parameters:
  • run_id (str) – The run ID to use as trace ID

  • **kwargs – Additional context parameters (user_id, input, agent_name, etc.)

Yields:

The span object (new SDK) or None (old SDK)

property remote_first: bool
static requires_env_vars(func)[source]

Validate environment variables before calling a method.

Parameters:

func (Callable[[...], T])

Return type:

Callable[[…], T]

validate_environment()[source]

Validate that required environment variables are set.

Return type:

bool