chore: simplify langfuse module + multi-step coordinator#43
Merged
iskakaushik merged 1 commit intomainfrom May 1, 2026
Merged
Conversation
Langfuse module (`include/ai/langfuse.h`, `src/langfuse/tracer.cpp`):
- Single Trace::to_iso8601(time_point) helper replaces three
duplicated gmtime_r/snprintf blocks (now_iso8601 plus two inline
lambdas in finish_generation / build_trace_event).
- Capture timestamp once per record_tool_call_{start,finish} event
(previously two clock reads per span event).
- Anonymous-namespace constants for event type discriminators
(trace-create / span-create / span-update / generation-create) and
level / unit strings, replacing scattered magic strings.
- Extract make_span_create + wrap_event helpers; the orphan-span
fallback in record_tool_call_finish reuses them instead of inlining
20+ lines of duplicated body construction.
- Drop the over-engineered ParsedHost/parse_host: httplib::Client's
URL constructor handles scheme/host/port already; we only need a
base-path extractor for Langfuse instances served under a sub-path.
- Cache httplib::Client + Basic-auth headers on the Tracer (lazily
constructed under mu_) so repeat send_batch calls reuse the
connection / TLS session instead of paying a fresh handshake.
- Replace 6-arg `start_trace(name, input, user, session, metadata,
tags)` sprawl with `start_trace(name, TraceOptions{})` to match the
rest of the SDK's struct-of-options style.
- Default Config::error_policy = ErrorPolicy::kStrict (was
best_effort=true) so misconfigurations surface at integration time
instead of being silently swallowed.
- Reject post-end mutations: set_*/instrument/finish_generation/record_*
bail out if Trace::end() has fired.
- Replace hand-rolled UUID v4 with stduuid (vendored under
third_party/stduuid-header-only/).
Multi-step coordinator (`src/tools/multi_step_coordinator.cpp`):
- Avoid re-copying initial_messages every loop iteration. step_messages
is grown in place: erase back to the immutable prefix + insert the
running response_messages accumulator, instead of `step_options =
initial_options; step_options.messages = initial_messages;
step_options.messages.insert(...)` per step.
- Remove the dead create_next_step_options stub from header + impl
(not part of any external ABI; was only kept as scaffolding during
the refactor).
- Trim narrating comment that referenced an external repo path.
Vendoring:
- Add third_party/stduuid-header-only/ (uuid.h + LICENSE) and
third_party/stduuid-cmake/ wrapper exposing a stduuid::stduuid
INTERFACE target. Wired into ai-sdk-cpp-langfuse via PRIVATE link.
Verified: full ctest suite (221/227 pass; 6 failing are
ClickHouseIntegrationTest cases that need a local ClickHouse server,
unchanged from main). End-to-end Langfuse example produces the
expected trace with 1 generation + N tool spans nested correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cleanup pass over the langfuse + multi-step coordinator code that just landed (#40, #42). No behaviour changes for the public API; simplifications and dependency hygiene.
Langfuse module
Trace::to_iso8601(time_point)) replaces three duplicated `gmtime_r`/`snprintf` blocks (the named static plus two inline lambdas in `finish_generation` / `build_trace_event`).Multi-step coordinator
Test plan