Skip to content

Commit 2d5f591

Browse files
committed
Integrating with langfuse
1 parent c282716 commit 2d5f591

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

plot_agent/langgraph_plot_agent/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
logger = logging.getLogger(__name__)
2222
# Set logging level to DEBUG for more detailed logs
2323
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
24-
24+
from langfuse.callback import CallbackHandler
2525
from dotenv import load_dotenv
2626

2727
load_dotenv('.env')
2828

29+
langfuse_handler = CallbackHandler()
30+
2931
# Create plots directory if it doesn't exist
3032
PLOTS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "plots")
3133
os.makedirs(PLOTS_DIR, exist_ok=True)
@@ -165,7 +167,7 @@ async def process_query(job_id: str, query: str):
165167

166168
try:
167169
# Invoke the agent to get final output
168-
final_result = agent.invoke({"messages": messages})
170+
final_result = agent.invoke({"messages": messages}, config={"callbacks": [langfuse_handler]})
169171

170172
logger.debug(f"Agent invocation complete. Processing final result messages...")
171173

plot_agent/langgraph_plot_agent/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ typing-extensions
1919
traceloop-sdk
2020
fastapi
2121
langchain_community
22+
langfuse

plot_agent/langgraph_plot_agent/requirements.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ anyio==4.9.0
1818
# via
1919
# anthropic
2020
# httpx
21+
# langfuse
2122
# openai
2223
# starlette
2324
attrs==25.3.0
@@ -26,7 +27,9 @@ attrs==25.3.0
2627
# jsonschema
2728
# referencing
2829
backoff==2.2.1
29-
# via posthog
30+
# via
31+
# langfuse
32+
# posthog
3033
blinker==1.9.0
3134
# via streamlit
3235
cachetools==5.5.2
@@ -100,6 +103,7 @@ httpcore==1.0.9
100103
httpx==0.28.1
101104
# via
102105
# anthropic
106+
# langfuse
103107
# langgraph-sdk
104108
# langsmith
105109
# openai
@@ -111,6 +115,7 @@ idna==3.10
111115
# via
112116
# anyio
113117
# httpx
118+
# langfuse
114119
# requests
115120
# yarl
116121
importlib-metadata==8.6.1
@@ -156,6 +161,8 @@ langchain-openai==0.3.16
156161
# via -r requirements.in
157162
langchain-text-splitters==0.3.8
158163
# via langchain
164+
langfuse==2.60.4
165+
# via -r requirements.in
159166
langgraph==0.4.3
160167
# via -r requirements.in
161168
langgraph-checkpoint==2.0.25
@@ -439,6 +446,7 @@ packaging==24.2
439446
# altair
440447
# huggingface-hub
441448
# langchain-core
449+
# langfuse
442450
# langsmith
443451
# marshmallow
444452
# matplotlib
@@ -475,6 +483,7 @@ pydantic==2.11.4
475483
# fastapi
476484
# langchain
477485
# langchain-core
486+
# langfuse
478487
# langgraph
479488
# langsmith
480489
# openai
@@ -521,6 +530,7 @@ requests==2.32.3
521530
# huggingface-hub
522531
# langchain
523532
# langchain-community
533+
# langfuse
524534
# langsmith
525535
# opentelemetry-exporter-otlp-proto-http
526536
# posthog
@@ -611,6 +621,7 @@ uvicorn==0.34.2
611621
wrapt==1.17.2
612622
# via
613623
# deprecated
624+
# langfuse
614625
# opentelemetry-instrumentation
615626
# opentelemetry-instrumentation-sqlalchemy
616627
# opentelemetry-instrumentation-threading

0 commit comments

Comments
 (0)