Commit
·
5856cb0
1
Parent(s):
d0f2b93
+ observability of traces
Browse files- app.py +6 -2
- langraph_agent.py +6 -1
app.py
CHANGED
|
@@ -7,20 +7,24 @@ import pandas as pd
|
|
| 7 |
from langraph_agent import build_graph
|
| 8 |
import asyncio
|
| 9 |
import aiohttp
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# (Keep Constants as is)
|
| 12 |
# --- Constants ---
|
| 13 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 14 |
|
| 15 |
# --- Basic Agent Definition ---
|
| 16 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 17 |
class BasicAgent:
|
| 18 |
def __init__(self):
|
| 19 |
self.agent = build_graph()
|
| 20 |
print("BasicAgent initialized.")
|
| 21 |
async def aquery(self, question: str) -> str:
|
| 22 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 23 |
-
response = await self.agent.run_query(question)
|
| 24 |
print(f"Agent returning fixed answer: {response}")
|
| 25 |
return response
|
| 26 |
|
|
|
|
| 7 |
from langraph_agent import build_graph
|
| 8 |
import asyncio
|
| 9 |
import aiohttp
|
| 10 |
+
from langfuse.langchain import CallbackHandler
|
| 11 |
+
|
| 12 |
+
# Initialize Langfuse CallbackHandler for LangGraph/Langchain (tracing)
|
| 13 |
+
langfuse_handler = CallbackHandler()
|
| 14 |
|
| 15 |
# (Keep Constants as is)
|
| 16 |
# --- Constants ---
|
| 17 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 18 |
|
| 19 |
# --- Basic Agent Definition ---
|
| 20 |
+
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 21 |
class BasicAgent:
|
| 22 |
def __init__(self):
|
| 23 |
self.agent = build_graph()
|
| 24 |
print("BasicAgent initialized.")
|
| 25 |
async def aquery(self, question: str) -> str:
|
| 26 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 27 |
+
response = await self.agent.run_query(question, config={"callbacks": [langfuse_handler]})
|
| 28 |
print(f"Agent returning fixed answer: {response}")
|
| 29 |
return response
|
| 30 |
|
langraph_agent.py
CHANGED
|
@@ -16,6 +16,11 @@ from langchain_core.tools import tool
|
|
| 16 |
from langchain.tools.retriever import create_retriever_tool
|
| 17 |
from supabase.client import Client, create_client
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
load_dotenv()
|
| 20 |
|
| 21 |
@tool
|
|
@@ -209,6 +214,6 @@ if __name__ == "__main__":
|
|
| 209 |
graph = build_graph(provider="groq")
|
| 210 |
# Run the graph
|
| 211 |
messages = [HumanMessage(content=question)]
|
| 212 |
-
messages = graph.invoke({"messages": messages})
|
| 213 |
for m in messages["messages"]:
|
| 214 |
m.pretty_print()
|
|
|
|
| 16 |
from langchain.tools.retriever import create_retriever_tool
|
| 17 |
from supabase.client import Client, create_client
|
| 18 |
|
| 19 |
+
from langfuse.langchain import CallbackHandler
|
| 20 |
+
|
| 21 |
+
# Initialize Langfuse CallbackHandler for LangGraph/Langchain (tracing)
|
| 22 |
+
langfuse_handler = CallbackHandler()
|
| 23 |
+
|
| 24 |
load_dotenv()
|
| 25 |
|
| 26 |
@tool
|
|
|
|
| 214 |
graph = build_graph(provider="groq")
|
| 215 |
# Run the graph
|
| 216 |
messages = [HumanMessage(content=question)]
|
| 217 |
+
messages = graph.invoke({"messages": messages}, config={"callbacks": [langfuse_handler]})
|
| 218 |
for m in messages["messages"]:
|
| 219 |
m.pretty_print()
|