Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ async def invoke_chatbot(state):
async def _process_query_async(self, messages: List[Dict[str, str]]) -> str:
if not self.tools:
self.load_tools()
self.graph = self._build_graph()
if self.graph is None:
self.graph = self._build_graph()

langchain_messages: List[BaseMessage] = []
for msg in messages:
Expand All @@ -144,7 +145,7 @@ async def _process_query_async(self, messages: List[Dict[str, str]]) -> str:
splunk_ao_context.set_session(self.session_id)

# One callback per request keeps each user turn in its own trace.
callback = SplunkAOAsyncCallback()
callback = SplunkAOAsyncCallback(flush_on_chain_end=True)
run_config = {**self.langgraph_config, "callbacks": [callback]}

result = await self.graph.ainvoke(
Expand Down
12 changes: 5 additions & 7 deletions examples/agent/healthcare-assistant/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _load_instrumented_agent():
)
from rag import get_rag_system
from setup_env import setup_environment
from splunk_ao import splunk_ao_context

_APP_DIR = os.path.dirname(os.path.abspath(__file__))
load_dotenv(os.path.join(_APP_DIR, ".env"))
Expand Down Expand Up @@ -104,7 +105,9 @@ def process_input(user_input: str | None):
elif isinstance(message, AIMessage):
conversation_messages.append({"role": "assistant", "content": message.content})

response = st.session_state.agent.process_query(conversation_messages)
# Pass only the latest user message to keep each trace clean (single input/output pair).
latest_user = [m for m in conversation_messages if m["role"] == "user"][-1:]
response = st.session_state.agent.process_query(latest_user)
st.session_state.messages.append(
{"message": AIMessage(content=response), "agent": "assistant"}
)
Expand Down Expand Up @@ -147,14 +150,9 @@ def render_sidebar(app_config: dict) -> str:
)
if st.button("Log Hallucination", key="log_hallucination"):
with st.spinner("Logging hallucination to Splunk Agent Observability..."):
existing_logger = (
st.session_state.get("splunk_ao_logger")
if st.session_state.get("splunk_ao_session_started", False)
else None
)
success = log_demo_hallucination(
config=app_config,
existing_logger=existing_logger,
existing_logger=splunk_ao_context,
session_id=st.session_state.get("session_id"),
)
if success:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def log_hallucination(
logger.info("Creating new Splunk AO session for hallucination demo")
splunk_ao_logger = SplunkAOLogger(project=project_name, agent_stream=agent_stream)

if external_session_id:
splunk_ao_logger.set_session(external_session_id)

splunk_ao_logger.start_trace(
input=question,
name="Hallucination Demo",
Expand Down
2 changes: 1 addition & 1 deletion examples/agent/healthcare-assistant/k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: healthcare-assistant
image: ghcr.io/splunk/healthcare-assistant:app-with-instrumentation
image: ghcr.io/splunk/healthcare-assistant-sao:0.3.0
imagePullPolicy: Always
ports:
- containerPort: 8501
Expand Down
2 changes: 1 addition & 1 deletion examples/agent/healthcare-assistant/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ langchain-classic
pyyaml
toml
pandas
splunk-ao
splunk-ao>=0.3.0
Loading