Skip to content

Add Langfuse prompt backend (text prompts)#93

Merged
chris-colinsky merged 2 commits into
mainfrom
feature/langfuse-prompt-backend
May 29, 2026
Merged

Add Langfuse prompt backend (text prompts)#93
chris-colinsky merged 2 commits into
mainfrom
feature/langfuse-prompt-backend

Conversation

@chris-colinsky
Copy link
Copy Markdown
Member

@chris-colinsky chris-colinsky commented May 29, 2026

Summary

A turnkey Langfuse-backed PromptBackend so users can fetch prompts from Langfuse's prompt registry through OA's PromptManager out of the box, instead of writing their own.

  • LangfusePromptBackend(client) takes a caller-supplied Langfuse client, so it shares one connection (one pool, one flush thread) with a LangfuseObserver on the same client. Behind the [langfuse] extra.
  • fetch(name, label) maps a Langfuse text prompt to OA's Prompt (template, version, label, sampling lifted from the prompt config, full config preserved in metadata) and sets observability_entities['langfuse_prompt'] so the Generation -> Prompt link (observability §8.4.4, shipped in v0.10.0) fires with no caller wiring.
  • Chat prompts raise PromptNotFound: OA's render produces a single user message today, so multi-message (chat) prompt support is deferred. The render-contract change is being drafted spec-side, targeted for v0.12.0.
  • Documents the LANGFUSE_* env vars next to the LLM_* ones in the examples config (docs landing page + examples/README).

Test plan

  • uv run pytest tests/unit/test_prompts_langfuse.py -q (8 pass)
  • full suite, ruff, pyright clean locally
  • CI

Follow-ups (not in this PR)

  • The Langfuse prompt docs page (lands on this branch).
  • A runnable Langfuse-prompts example, arriving with chat-prompt support in v0.12.0 (so it shows text and chat together).
  • Live validation against a real Langfuse account.

LangfusePromptBackend fetches prompts from Langfuse's prompt registry
through PromptManager, behind the [langfuse] extra. It takes a
caller-supplied Langfuse client so it shares one connection with a
LangfuseObserver on the same client. A text prompt maps to Prompt
(template, version, label, sampling lifted from config) and sets
observability_entities['langfuse_prompt'] so the Generation-to-Prompt
link fires with no caller wiring.

Chat prompts raise PromptNotFound: OA's render produces a single user
message today, so multi-message support is deferred (tracked for a
later release).

Also document the LANGFUSE_* env vars next to the LLM_* ones in the
examples config sections.
Copilot AI review requested due to automatic review settings May 29, 2026 03:14
Comment thread src/openarmature/prompts/backends/langfuse.py Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Langfuse-backed prompt backend for fetching text prompts through PromptManager, plus unit coverage and example documentation for Langfuse environment configuration.

Changes:

  • Introduces LangfusePromptBackend for mapping Langfuse text prompts into OA Prompt objects.
  • Adds unit tests for prompt mapping, labels, chat prompt rejection, errors, sampling config, and rendering.
  • Documents Langfuse environment variables in examples docs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/openarmature/prompts/backends/langfuse.py Adds the Langfuse prompt backend implementation.
tests/unit/test_prompts_langfuse.py Adds unit tests for the Langfuse prompt backend.
examples/README.md Adds Langfuse env var documentation for examples.
docs/examples/index.md Adds Langfuse env var documentation to docs landing page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/openarmature/prompts/backends/langfuse.py Outdated
Comment thread examples/README.md
Comment thread docs/examples/index.md
From PR #93 review:

- Map httpx.TransportError (connect/read/timeout/network) to
  PromptStoreUnavailable in LangfusePromptBackend, alongside 503s, so
  PromptManager falls back on transport failures per the PromptBackend
  contract. Adds a transport-timeout unit test.
- Align the opt-in Langfuse integration test's host resolution to the
  SDK's precedence (LANGFUSE_BASE_URL before LANGFUSE_HOST); it had
  framed LANGFUSE_HOST as canonical with the opposite precedence.
Comment thread src/openarmature/prompts/backends/langfuse.py
@chris-colinsky chris-colinsky merged commit 5c4e999 into main May 29, 2026
6 checks passed
@chris-colinsky chris-colinsky deleted the feature/langfuse-prompt-backend branch May 29, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants