langsmith-trace
Original:🇺🇸 English
Translated
LangSmith tracing and trace debugging for AgentSeek templates. Covers CLI installation, adding tracing to LangGraph apps, querying traces, and inspecting run IO. Use when debugging agent backends, investigating slow traces, or adding observability to a template.
16installs
Sourceob-labs/agentseek
Added on
NPX Install
npx skill4agent add ob-labs/agentseek langsmith-traceTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →LangSmith Trace
Add tracing to your agent and query traces for debugging. Supports Python and TypeScript.
[!IMPORTANT] This skill is tuned for AgentSeek template backends (LangGraph + middleware stacks). For general LangSmith concepts, see the upstream langsmith-skills repo.
[!CAUTION] Never passas a CLI flag or expose API keys in shell commands / tool calls. The CLI reads--api-keyfrom the environment automatically. UsingLANGSMITH_API_KEYleaks secrets into shell history, process listings, and agent tool-call logs. Always rely on the environment variable set in your shell profile or--api-key <value>file..env
Installation & Setup
1. Install the CLI
bash
curl -sSL https://raw.githubusercontent.com/langchain-ai/langsmith-cli/main/scripts/install.sh | shThe binary installs to . If is not found after install, add to your shell profile:
~/.local/bin/langsmithlangsmithbash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc2. Set your API key (environment variable only)
Add to (or the template's file) — the user must fill in their own key:
~/.zshrc.envbash
export LANGSMITH_API_KEY=<your-key-here> # starts with lsv2_pt_Key format must start with . Get yours at https://smith.langchain.com/settings.
lsv2_pt_The CLI reads this env var automatically — never use flags. Do not echo, print, or pass the key value in any shell command or tool call argument.
--api-key3. Verify
bash
langsmith project listIf you see a JSON array of projects, you're set. Common failures:
- —
command not foundnot in PATH (see step 1)~/.local/bin - 401 Unauthorized — key is wrong or expired; regenerate at LangSmith settings
- Empty array — valid auth but no projects yet; create one in the UI or run a traced app
[]
Adding Tracing
LangGraph / LangChain apps (automatic)
Just set environment variables — no code changes needed:
bash
export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=<your-key-here> # must be set; do NOT pass via --api-key flag
export LANGSMITH_PROJECT=my-project # optional, defaults to "default"For serverless (Python): also set to ensure traces flush before function exit.
LANGCHAIN_CALLBACKS_BACKGROUND=falseNon-LangChain apps
Use the decorator (Python) or wrapper (TypeScript) and wrap your LLM client:
@traceabletraceable()python
from langsmith import traceable
from langsmith.wrappers import wrap_openai
from openai import OpenAI
client = wrap_openai(OpenAI())
@traceable
def my_pipeline(question: str) -> str:
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": question}],
)
return resp.choices[0].message.contenttypescript
import { traceable } from "langsmith/traceable";
import { wrapOpenAI } from "langsmith/wrappers";
import OpenAI from "openai";
const client = wrapOpenAI(new OpenAI());
const myPipeline = traceable(async (question: string) => {
const resp = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: question }],
});
return resp.choices[0].message.content || "";
}, { name: "my_pipeline" });Debugging a Trace (Step-by-Step)
This is the recommended workflow for investigating agent behavior:
Step 1: Find the right project
bash
langsmith project listLook at to find which project has recent activity. Don't assume — LangGraph apps default to the project, not a named one.
last_run_start_time"default"Step 2: List recent traces
bash
langsmith trace list --project default --limit 5
# Or with full hierarchy inline (combines steps 2+3):
langsmith trace list --project default --limit 5 --show-hierarchyStep 3: Get the trace hierarchy
bash
langsmith trace get <trace-id> --project <name>This returns the full run tree — use it to understand the agent's execution flow.
Step 4: Get IO for all runs in a trace
bash
langsmith run list --trace-ids <trace-id> --project <name> --include-ioThis gives you inputs and outputs for every run (LLM calls, tool calls, middleware).
Step 5: Drill into a specific run
bash
langsmith run get <run-id> --include-ioAgentSeek Trace Structure
Our templates produce traces with this typical hierarchy:
<agent_name> (root chain)
├── SkillsMiddleware.before_agent
├── PatchToolCallsMiddleware.before_agent
├── MemoryMiddleware.before_agent
├── model (chain) ← LLM turn
│ ├── TodoListMiddleware.awrap_model_call
│ ├── SkillsMiddleware.awrap_model_call
│ ├── FilesystemMiddleware.awrap_model_call
│ ├── SubAgentMiddleware.awrap_model_call
│ ├── SummarizationMiddleware.awrap_model_call
│ ├── AnthropicPromptCachingMiddleware.awrap_model_call
│ ├── MemoryMiddleware.awrap_model_call
│ └── ChatOpenAI (llm) ← actual LLM call (inputs/outputs here)
├── TodoListMiddleware.after_model
├── tools (chain) ← tool execution
│ ├── FilesystemMiddleware.awrap_tool_call
│ └── <tool_name> (tool) ← actual tool (inputs/outputs here)
├── model (chain) ← next LLM turn
│ └── ... (same middleware stack)
└── TodoListMiddleware.after_modelKey points:
- The actual LLM call is always the innermost run
ChatOpenAI - Tool results are in the run (e.g.,
<tool_name>,generate_cover)execute - Middleware wrappers are transparent — they add latency but the IO you care about is at the leaf nodes
Gotchas
--full
vs --include-io
on individual runs
--full--include-ioProblem: can return null for inputs/outputs, even though the data exists. Despite being documented as equivalent to , the underlying API behavior differs for individual run fetches in some CLI versions.
langsmith run get <id> --full--full--include-metadata --include-io --include-feedbackSolution: Always use explicitly when inspecting specific runs:
--include-iobash
# DO THIS
langsmith run get <run-id> --include-io
# NOT THIS (may return null IO despite docs saying it includes --include-io)
langsmith run get <run-id> --full--fulltrace exportrun listrun get--include-ioNull IO even with --include-io
--include-ioIf inputs/outputs come back null even with , the project has IO logging disabled. Check for these environment variables in the template's :
--include-io.envbash
LANGCHAIN_HIDE_INPUTS=true # hides inputs from traces
LANGCHAIN_HIDE_OUTPUTS=true # hides outputs from tracesRemove or set to to enable IO capture for debugging.
falseProject confusion
LangGraph apps trace to the project unless is explicitly set. Always run first and check to find where your traces actually landed.
"default"LANGSMITH_PROJECTlangsmith project listlast_run_start_timeTips
- Add for human-readable output during interactive debugging
--format pretty - Use env var if connecting to a self-hosted LangSmith instance
LANGSMITH_ENDPOINT - The middleware ordering in the trace tree is configurable — your template may differ slightly from the diagram above
CLI Reference
Full command reference: reference/cli-commands.md