Skip to content

Commit 1dfa77b

Browse files
committed
support Langfuse
1 parent e0caf0e commit 1dfa77b

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

.env.template

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
## Project Settings
66
PROJECT_NAME=template-langgraph
77

8+
# ---------
9+
# Observability
10+
# ---------
11+
812
## LangSmith Settings
913
LANGSMITH_TRACING="false" # Options: "true", "false"
1014
LANGSMITH_API_KEY="lsv2_xxx"
1115

16+
## Langfuse Settings
17+
LANGFUSE_PUBLIC_KEY="pk-lf-..."
18+
LANGFUSE_SECRET_KEY="sk-lf-..."
19+
LANGFUSE_HOST="https://cloud.langfuse.com"
20+
1221
# ---------
1322
# LLMs
1423
# ---------

docs/references.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,7 @@
106106
### [LiteLLM](https://docs.litellm.ai/)
107107

108108
- [Azure OpenAI](https://docs.litellm.ai/docs/providers/azure/)
109+
110+
### [Langfuse](https://langfuse.com/)
111+
112+
- [Cookbook: LangGraph Integration](https://langfuse.com/guides/cookbook/integration_langgraph)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies = [
2525
"langchain-ollama>=0.3.6",
2626
"langchain-openai>=0.3.28",
2727
"langchain-text-splitters>=0.3.9",
28+
"langfuse>=3.6.2",
2829
"langgraph>=0.6.2",
2930
"langgraph-supervisor>=0.0.29",
3031
"mlflow>=3.4.0",

scripts/agent_operator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import typer
55
from dotenv import load_dotenv
66
from langchain_core.runnables.config import RunnableConfig
7+
from langfuse.langchain import CallbackHandler
78

89
from template_langgraph.agents.chat_with_tools_agent.agent import graph as chat_with_tools_agent_graph
910
from template_langgraph.agents.image_classifier_agent.agent import graph as image_classifier_agent_graph
@@ -126,6 +127,9 @@ def run(
126127
},
127128
config=RunnableConfig(
128129
recursion_limit=recursion_limit,
130+
callbacks=[
131+
CallbackHandler(),
132+
],
129133
),
130134
):
131135
logger.info("-" * 20)
@@ -181,6 +185,9 @@ def news_summarizer_agent(
181185
),
182186
config=RunnableConfig(
183187
recursion_limit=recursion_limit,
188+
callbacks=[
189+
CallbackHandler(),
190+
],
184191
),
185192
):
186193
logger.info("-" * 20)
@@ -242,6 +249,9 @@ def image_classifier_agent(
242249
),
243250
config=RunnableConfig(
244251
recursion_limit=recursion_limit,
252+
callbacks=[
253+
CallbackHandler(),
254+
],
245255
),
246256
):
247257
logger.info("-" * 20)

template_langgraph/services/streamlits/pages/chat_with_tools_agent.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from langchain_community.callbacks.streamlit import (
99
StreamlitCallbackHandler,
1010
)
11+
from langfuse.langchain import CallbackHandler
1112

1213
from template_langgraph.agents.chat_with_tools_agent.agent import (
1314
AgentState,
@@ -296,7 +297,12 @@ def build_graph_messages() -> list:
296297
def invoke_agent(graph_messages: list) -> AgentState:
297298
return st.session_state["graph"].invoke(
298299
{"messages": graph_messages},
299-
{"callbacks": [StreamlitCallbackHandler(st.container())]},
300+
{
301+
"callbacks": [
302+
StreamlitCallbackHandler(st.container()),
303+
CallbackHandler(),
304+
]
305+
},
300306
)
301307

302308

uv.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)