Skip to content
8 changes: 8 additions & 0 deletions libs/acl/langfuse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Langfuse ACL Extension

This module provides the Langfuse adapter used by Eino for event and prompt management against the Langfuse public API.

- `prompt.go` implements the prompt client, including typed request/response models and helpers to list, fetch, and create prompts.
- A minimal usage sample lives in `examples/prompt/main.go`, showing how to initialize a Langfuse client and load a prompt by name.

Run `go test ./...` before submitting changes to ensure the package continues to build and the existing suites pass.
46 changes: 46 additions & 0 deletions libs/acl/langfuse/examples/prompt/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2025 CloudWeGo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package examples

import (
"context"
"fmt"
"log"

"github.com/cloudwego/eino-ext/libs/acl/langfuse"
)

func main() {
ctx := context.Background()

lf := langfuse.NewLangfuse(
"https://cloud.your-langfuse-instance.com",
"your-public-key",
"your-secret-key",
)

promptClient := lf.Prompt()

prompt, err := promptClient.GetPrompt(ctx, langfuse.GetParams{
Name: "welcome-message",
})
if err != nil {
log.Fatalf("failed to fetch prompt: %v", err)
}

fmt.Printf("Loaded prompt %q version %d\n", prompt.Name, prompt.Version)
}
17 changes: 14 additions & 3 deletions libs/acl/langfuse/langfuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Langfuse interface {
EndGeneration(body *GenerationEventBody) error
CreateEvent(body *EventEventBody) (string, error)
Flush()
Prompt() *PromptClient
}

// NewLangfuse creates a Langfuse client instance
Expand Down Expand Up @@ -68,9 +69,10 @@ func NewLangfuse(
opt(o)
}

httpCli := &http.Client{Timeout: o.timeout}
tm := newTaskManager(
o.threads,
&http.Client{Timeout: o.timeout},
httpCli,
host,
o.maxTaskQueueSize,
o.flushAt,
Expand All @@ -85,11 +87,14 @@ func NewLangfuse(
secretKey,
o.maxRetry,
)
return &langfuseIns{tm: tm}
langfuseCli := newClient(httpCli, host, publicKey, secretKey, sdkVersion)
promptCli := &PromptClient{cli: langfuseCli}
return &langfuseIns{tm: tm, promptCli: promptCli}
}

type langfuseIns struct {
tm *taskManager
tm *taskManager
promptCli *PromptClient
}

// CreateTrace creates a new trace in Langfuse
Expand Down Expand Up @@ -215,3 +220,9 @@ func (l *langfuseIns) CreateEvent(body *EventEventBody) (string, error) {
func (l *langfuseIns) Flush() {
l.tm.flush()
}

// Prompt provides access to the prompt client for managing prompts.
// Use the returned PromptClient to create, retrieve and list prompts.
func (l *langfuseIns) Prompt() *PromptClient {
return l.promptCli
}
14 changes: 14 additions & 0 deletions libs/acl/langfuse/mock/langfuse_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading