Skip to content

Fix/langfuse tracing UI format - #3

Merged
iamMashel merged 7 commits into
mainfrom
fix/langfuse-tracing-ui-format
Apr 18, 2026
Merged

iamMashel merged 7 commits into
mainfrom
fix/langfuse-tracing-ui-format

Conversation

@iamMashel

@iamMashel iamMashel commented Apr 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Changes

Type of change

  • Bug fix (fix/)
  • New feature (feature/)
  • Refactor / chore (chore/)
  • Documentation
  • CI / infra

Checklist

  • Tests pass locally (just test)
  • Lint + format pass (just lint && just format-check)
  • Type checks pass (just typecheck)
  • New tests added for any new behaviour
  • .env.example updated if new env vars were introduced
  • Documentation updated if needed

Notes for reviewer

iamMashel and others added 7 commits April 17, 2026 15:53
Replace broken LangChain callback (incompatible with langchain 1.x) with
Langfuse SDK direct trace API — no LangChain dependency, works reliably
with Langfuse server v2.

Add marked@15 to web app and render agent messages as proper HTML so bold
(**text**), lists, code blocks, and headers display correctly instead of
showing raw *** symbols.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Display the active session ID as a monospace badge at the top of the chat
so users can correlate conversations with Langfuse traces. Add a "New chat"
button that resets the message list and generates a fresh session ID.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Planner: rewrite prompt to output exactly one token — eliminates verbose
LLM output that contained the word "tools" in prose, which was tripping
the old `"tool" in next_step` router into always calling search.

Router: tighten check to `startswith("tool:")` so natural language in
next_step can never accidentally match.

Synthesizer: make it the sole owner of message history — planner no longer
adds the user message, so synth adds the User+Assistant pair together at
end of each turn. Fixes the bug where current user message appeared twice
in the synthesizer's context, confusing the LLM about what was history vs
the current question.

Frontend: persist session ID in localStorage so memory survives page
refreshes instead of generating a new ID on every load.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace ainvoke with astream_events so every LangGraph event is captured.
Build a structured Langfuse trace hierarchy in real time:

  Trace (agent-workflow)
  ├── Span: planner      — node input/output + decision made
  │   └── Generation     — exact prompt, model, response, token counts, latency
  ├── Span: tool:search  — query input, raw results, errors  [if triggered]
  └── Span: synth        — node input/output
      └── Generation     — exact prompt, model, response, token counts, latency

Nodes now accept RunnableConfig and pass it to llm.invoke()/tool.invoke()
so LangGraph propagates the astream_events callback manager into LLM and
tool calls, making them surface as on_chat_model_* and on_tool_* events.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Server (docker-compose.yml):
- langfuse/langfuse:2 → langfuse/langfuse:3 (web)
- Add langfuse/langfuse-worker:3 (async job processor)
- Add clickhouse/clickhouse-server:24.12 (trace/span storage)
- Add minio + minio-init (S3-compatible blob storage + bucket setup)
- Redis is now shared between agent platform and Langfuse worker queue
- LANGFUSE_HOST updated to http://langfuse-web:3000 inside compose network
- ENCRYPTION_KEY added (placeholder — generate with: openssl rand -hex 32)

SDK (pyproject.toml + agent.py):
- langfuse>=2.0.0,<3.0.0 → langfuse>=3.14.6,<4.0.0
- Replace manual astream_events trace builder (80 lines) with
  LangfuseCallbackHandler (v3 fixed langchain_core import compat) attached
  to invoke_config["callbacks"]
- Wrap invocation in start_as_current_observation() so user_id, session_id,
  tags, and metadata are set on the root trace via update_current_trace()
- Graceful fallback to plain ainvoke when Langfuse is not configured

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…, Alembic

Core fixes:
- Truncate history sent to LLM at 10 turns; full history stays in Postgres checkpoint
- Wrap all LLM calls with exponential backoff retry (3 attempts, jitter)
- Split planner model from synthesizer via PLANNER_MODEL env var
- Replace create_tables() with Alembic migrations; exclude LangGraph tables from autogenerate

Tracing:
- Fix Langfuse v3: use sync context manager, create CallbackHandler inside active span
  so node observations nest correctly under the root trace

Tooling:
- Fix duckduckgo_search -> ddgs (package renamed)
- Fix agentdb port conflict: map 5433:5432
- Fix frontend: 120s AbortSignal timeout + improved error messages with URL

Tests:
- Fix integration tests: use TestClient as context manager so FastAPI lifespan fires
- Fix mock LLM to accept **kwargs (LangGraph passes config= through)
- Add 13 unit tests covering all four fixes

Docs:
- Update README features, env vars table (PLANNER_MODEL), repo structure, tech stack

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The test connects to a live DB, which doesn't exist in the unit CI job.
Skip gracefully via pytest.skip() on OperationalError so unit tests pass
in both local (DB available) and CI (no DB) environments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@iamMashel
iamMashel merged commit cf980a4 into main Apr 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant