Add Langfuse prompt backend (text prompts)#93
Merged
Conversation
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.
There was a problem hiding this comment.
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
LangfusePromptBackendfor mapping Langfuse text prompts into OAPromptobjects. - 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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A turnkey Langfuse-backed
PromptBackendso users can fetch prompts from Langfuse's prompt registry through OA'sPromptManagerout of the box, instead of writing their own.LangfusePromptBackend(client)takes a caller-suppliedLangfuseclient, so it shares one connection (one pool, one flush thread) with aLangfuseObserveron the same client. Behind the[langfuse]extra.fetch(name, label)maps a Langfuse text prompt to OA'sPrompt(template, version, label, sampling lifted from the prompt config, full config preserved inmetadata) and setsobservability_entities['langfuse_prompt']so the Generation -> Prompt link (observability §8.4.4, shipped in v0.10.0) fires with no caller wiring.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.LANGFUSE_*env vars next to theLLM_*ones in the examples config (docs landing page +examples/README).Test plan
uv run pytest tests/unit/test_prompts_langfuse.py -q(8 pass)Follow-ups (not in this PR)