Skip to content

Commit 525c6b9

Browse files
Prefer Langfuse public API trace exports
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e038896 commit 525c6b9

6 files changed

Lines changed: 25 additions & 13 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ PYTHONPATH=src uv run context-profiler analyze tests/fixtures/cursor_transcript.
5151

5252
## Product Boundaries
5353

54-
Do not add provider-specific fetch clients to core. Agents can use Langfuse CLI, SDKs, Hugging Face tooling, or local transcript discovery to obtain data, then pass files or stdin to `context-profiler`.
54+
Do not add provider-specific fetch clients to core. Agents can use Langfuse public API exports via `curl`, SDKs, Hugging Face tooling, or local transcript discovery to obtain data, then pass files or stdin to `context-profiler`. Prefer direct Langfuse public API exports over `langfuse-cli` for trace analysis because the CLI can omit fields needed for nested observations and generations.
5555

5656
Do not make Toolathlon a first-class multi-turn demo. Prefer genuinely multi-turn datasets such as `pagarsky/agent-trace`, `cx-cmu/agent_trajectories`, and SWE-agent trajectories for future research examples.
5757

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,25 @@ context-profiler diagnose trace.json --format langfuse --json
9090
context-profiler analyze trace.json --format langfuse --html report.html
9191
```
9292

93-
Analyze a Langfuse trace fetched by Langfuse CLI:
93+
Fetch a Langfuse trace through the public API, then analyze it:
9494

9595
```bash
96-
npx langfuse-cli api traces get <trace-id> --fields core,io,observations --json \
97-
| context-profiler diagnose - --format langfuse --json
96+
TRACE_ID="<trace-id>"
97+
HOST="${LANGFUSE_HOST%/}"
98+
OUT="/tmp/langfuse-trace-${TRACE_ID}"
99+
mkdir -p "$OUT"
100+
101+
curl -fsS \
102+
-u "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" \
103+
"$HOST/api/public/traces/$TRACE_ID" \
104+
-o "$OUT/trace.json"
105+
106+
curl -fsS \
107+
-u "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" \
108+
"$HOST/api/public/observations?traceId=$TRACE_ID&limit=100&page=1" \
109+
-o "$OUT/observations-page-1.json"
110+
111+
context-profiler diagnose "$OUT/trace.json" --format langfuse --json
98112
```
99113

100114
Analyze a public academic agent trajectory:
@@ -129,8 +143,6 @@ context-profiler normalize trace.json --from auto --json
129143

130144
# Diagnose for agent consumption; '-' reads JSON/JSONL from stdin
131145
context-profiler diagnose trace.json --format auto --json
132-
npx langfuse-cli api traces get <trace-id> --fields core,io,observations --json \
133-
| context-profiler diagnose - --format langfuse --json
134146
```
135147

136148
If validation fails, the JSON response includes `errors[].agent_action` and `next_steps` so the agent can convert the trace into `ContextTrace`.
@@ -139,7 +151,7 @@ If validation fails, the JSON response includes `errors[].agent_action` and `nex
139151

140152
This repository ships an `analyze-agent-context` skill for Cursor, Claude Code, and other Agent Skills / Open Plugins compatible tools.
141153

142-
The skill does not make `context-profiler` fetch traces itself. It teaches agents to use Langfuse tooling to fetch Langfuse trace ids, then route the fetched JSON into `context-profiler` for diagnosis whenever the user asks to analyze a trace, loop, transcript, agent run, context growth, stale context, or tool bloat.
154+
The skill does not make `context-profiler` fetch traces itself. It teaches agents to fetch Langfuse trace ids with the Langfuse public API via `curl`, then route the fetched JSON into `context-profiler` for diagnosis whenever the user asks to analyze a trace, loop, transcript, agent run, context growth, stale context, or tool bloat. It intentionally avoids `langfuse-cli` for trace fetching because the CLI may omit fields needed for complete analysis.
143155

144156
Canonical skill:
145157

docs/design/cli-harness.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The CLI is designed for two users at once:
1313

1414
Good upstream sources include:
1515

16-
- Langfuse CLI or API exports
16+
- Langfuse public API exports
1717
- OpenTelemetry / OpenInference span exports
1818
- raw OpenAI or Anthropic request logs
1919
- Cursor or Claude Code local transcripts
@@ -41,7 +41,7 @@ context-profiler analyze <file|-> --format auto --html report.html
4141

4242
The style is inspired by mature agent-friendly CLIs:
4343

44-
- Langfuse CLI: schema-driven API access
44+
- Langfuse API: observability trace access
4545
- kubectl: resource discovery and explainability
4646
- Terraform: validate/plan-style machine output
4747
- GitHub CLI: human commands plus machine-readable JSON

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ context-profiler diagnose trace.json --format langfuse --json
7373
context-profiler analyze trace.json --format langfuse --html /tmp/context-profiler-langfuse.html
7474
```
7575

76-
`context-profiler` does not fetch Langfuse data. Use Langfuse's own CLI/API or any other tool to obtain the trace first.
76+
`context-profiler` does not fetch Langfuse data. Use the Langfuse public API via `curl` or another external tool to obtain the trace first. Prefer the public API for complete trace analysis because CLI output can omit fields needed to inspect nested observations and generations.
7777

7878
## Academic AgentTrace
7979

skills/analyze-agent-context/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: analyze-agent-context
3-
description: Analyze LLM agent traces, loops, transcripts, Langfuse exports, OpenTelemetry spans, or raw provider requests with context-profiler. Use when the user asks to analyze/debug/explain a trace, agent run, context growth, stale context, tool bloat, or a recently fetched trace from another CLI.
3+
description: Analyze LLM agent traces, loops, transcripts, Langfuse exports, OpenTelemetry spans, or raw provider requests with context-profiler. Use when the user asks to analyze/debug/explain a trace, agent run, context growth, stale context, tool bloat, or recently fetched trace JSON.
44
---
55

66
# Analyze Agent Context

src/context_profiler/formats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ def to_dict(self) -> dict[str, Any]:
6969
"observations[]",
7070
"GENERATION observations with input.messages, input {role, content}, or string input",
7171
],
72-
common_sources=["Langfuse UI export", "Langfuse API", "langfuse-cli"],
72+
common_sources=["Langfuse UI export", "Langfuse public API"],
7373
analysis_scope=[
7474
"Per-generation context growth",
7575
"Visible generation input messages",
7676
"Tool input/output if captured in generation inputs",
7777
],
7878
limitations=["Only GENERATION observations with analyzable input content are profiled in the current adapter."],
79-
agent_conversion_guidance="Use langfuse-cli or API to fetch traces/observations, then pass the exported trace JSON directly.",
79+
agent_conversion_guidance="Use the Langfuse public API via curl to fetch traces/observations, then pass the exported trace JSON directly. Avoid langfuse-cli for trace analysis because it may omit nested observation or generation fields.",
8080
notes=["Current adapter extracts generation inputs and delegates to OpenAI parsing."],
8181
),
8282
"cursor-jsonl": FormatSpec(

0 commit comments

Comments
 (0)