diff --git a/.deepagents/skills/docs-code-samples/SKILL.md b/.deepagents/skills/docs-code-samples/SKILL.md index e315e88fd..199b0444c 100644 --- a/.deepagents/skills/docs-code-samples/SKILL.md +++ b/.deepagents/skills/docs-code-samples/SKILL.md @@ -114,7 +114,28 @@ public class Example { // :snippet-end: ``` -Choose a unique `snippet-name` in kebab-case. All snippet names must include a language suffix: `-py` for Python files, `-js` for TypeScript/JavaScript files, `-java` for Java files, and `-kt` for Kotlin files (for example, `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt`). This becomes the base of the output filename. +**Go:** +```go +// :snippet-start: snippet-name-go +package main + +import "fmt" + +func main() { + fmt.Println("hello") +} +// :snippet-end: +``` + +**Bash (cURL):** +```bash +# :snippet-start: snippet-name-sh +curl "https://api.smith.langchain.com/api/v1/runs" \ + -H "x-api-key: $LANGSMITH_API_KEY" +# :snippet-end: +``` + +Choose a unique `snippet-name` in kebab-case. All snippet names must include a language suffix: `-py` for Python files, `-js` for TypeScript/JavaScript files, `-java` for Java files, `-kt` for Kotlin files, `-go` for Go files, and `-sh` for bash/cURL files (for example, `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt`, `traceable-pipeline-go`, `traceable-pipeline-sh`). This becomes the base of the output filename. ### 3. Add runnable test code in remove blocks @@ -169,6 +190,10 @@ Java files (`.java`) under `src/code-samples/` are run using `jbang`. To keep CI `make test-code-samples` runs every `.java` file under `src/code-samples/` in **lexical path order** (after all Python and TypeScript samples). That order is unrelated to section order in the docs. If one sample must run before another (for example creating a hub prompt before pulling it), name the source files so they sort correctly. For example, `manage-prompts-pull.java` runs before `manage-prompts-push.java` because `pull` sorts before `push`; use prefixes such as `manage-prompts-0-push.java` and `manage-prompts-1-pull.java` when you need push to run first. +Go files (`.go`) under `src/code-samples/` are run with `go run` from `src/code-samples/`, which shares a single `go.mod`/`go.sum` at that directory (add new dependencies there with `go get`, then `go mod tidy`, similar to how `.ts` samples share `src/code-samples/package.json`). `go run .go` only compiles that one file, not its sibling files in the same directory, so — like Kotlin — put each snippet variant in its own file (`topic-before.go`, `topic-after.go`) rather than multiple snippets sharing one file: two files in the same package cannot both declare `func main()`. Go samples do not guard on missing keys — let the SDK call fail fast (matching Python's behavior) rather than skipping with a printed message. `make test-code-samples` runs `.go` files last, after Kotlin, in lexical path order. + +Bash/cURL files (`.sh`) under `src/code-samples/` are run with `bash .sh` from `src/code-samples/`. Like Go, put each snippet variant in its own file (`topic-before.sh`, `topic-after.sh`) rather than sharing one file. Hide test-only setup (`#!/usr/bin/env bash`, `set -euo pipefail`, resolving a real ID/value for a `` shown in the docs) in `# :remove-start:`/`# :remove-end:` blocks so the visible snippet is exactly the illustrative curl command a reader would copy — including no shebang or `set -e` line. `curl` does not exit non-zero on an HTTP error status by itself, so when a script pipes a response into `jq` to extract a value used by a later request (for example resolving a project ID), add a hidden check that the resolved value is non-empty and not the literal string `null` before continuing, so a bad API response fails the test loudly instead of silently propagating into later requests. `make test-code-samples` runs `.sh` files last, after Go, in lexical path order. + Check formatting with: ```bash @@ -230,8 +255,8 @@ Replace the inline code blocks with the snippet components: | Element | Convention | Example | |--------|-------------|---------| -| Code file | Descriptive, kebab-case | `return-a-string.py`, `return-a-string.ts`, `traceable-pipeline.java`, `traceable-pipeline.kt` | -| Snippet name | Kebab-case with language suffix: `-py` for Python, `-js` for JS/TS, `-java` for Java, `-kt` for Kotlin | `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt` | +| Code file | Descriptive, kebab-case | `return-a-string.py`, `return-a-string.ts`, `traceable-pipeline.java`, `traceable-pipeline.kt`, `traceable-pipeline.go`, `traceable-pipeline.sh` | +| Snippet name | Kebab-case with language suffix: `-py` for Python, `-js` for JS/TS, `-java` for Java, `-kt` for Kotlin, `-go` for Go, `-sh` for bash/cURL | `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt`, `traceable-pipeline-go`, `traceable-pipeline-sh` | | MDX snippet (Python) | `{snippet-name}.mdx` (snippet name ends in `-py`) | `tool-return-values-py.mdx` | | MDX snippet (JS) | `{snippet-name}.mdx` (snippet name ends in `-js`) | `tool-return-values-js.mdx` | | Component name | PascalCase | `ToolReturnValuesPy`, `ToolReturnValuesJs` | diff --git a/.github/workflows/test-code-samples.yml b/.github/workflows/test-code-samples.yml index ce498e95f..60a0fed64 100644 --- a/.github/workflows/test-code-samples.yml +++ b/.github/workflows/test-code-samples.yml @@ -62,14 +62,14 @@ jobs: fi FILES=$(git diff --name-only "$BASE" HEAD -- src/code-samples/ \ - | grep -E '\.(py|ts|java|kt)$' \ + | grep -E '\.(py|ts|java|kt|go|sh)$' \ | tr '\n' ' ' || true) { echo "files<> "$GITHUB_OUTPUT" if [[ -n "$FILES" ]]; then echo "Modified code samples: $FILES" else - echo "No modified .py, .ts, .java, or .kt files in src/code-samples/" + echo "No modified .py, .ts, .java, .kt, .go, or .sh files in src/code-samples/" fi fi @@ -95,6 +95,11 @@ jobs: - name: Install JBang uses: jbangdev/setup-jbang@v0.1.1 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: src/code-samples/go.mod + - name: Wait for PostgreSQL run: | for i in $(seq 1 30); do diff --git a/pyproject.toml b/pyproject.toml index b3a732a08..4876fa5c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ dependencies = [ "langchain-quickjs>=0.3.2", "langgraph>=1.2.5", "langgraph-checkpoint-sqlite>=3.1.0", + "langsmith>=0.9.6", ] diff --git a/scripts/extract_code_snippets.py b/scripts/extract_code_snippets.py index 57af07ee2..065d9925d 100644 --- a/scripts/extract_code_snippets.py +++ b/scripts/extract_code_snippets.py @@ -11,8 +11,10 @@ Supported markers (same as this repo's Bluehawk usage): - ``# :snippet-start: `` / ``# :snippet-end:`` (Python) - ``// :snippet-start: `` / ``// :snippet-end:`` (TypeScript, Java) - ``// :snippet-start: `` / ``// :snippet-end:`` (Kotlin) -- ``# :remove-start:`` / ``# :remove-end:`` inside Python snippet bodies -- ``// :remove-start:`` / ``// :remove-end:`` inside TypeScript/Java snippet bodies +- ``// :snippet-start: `` / ``// :snippet-end:`` (Go) +- ``# :snippet-start: `` / ``# :snippet-end:`` (bash) +- ``# :remove-start:`` / ``# :remove-end:`` inside Python/bash snippet bodies +- ``// :remove-start:`` / ``// :remove-end:`` inside TypeScript/Java/Kotlin/Go snippet bodies Output files match Bluehawk: ``.snippet..`` in ``src/code-samples-generated/``. @@ -23,7 +25,7 @@ or via ``make code-snippets``. Optional environment variable: - ``CODE_SNIPPET_SOURCES``: space-separated repo-relative paths under ``src/code-samples/`` - (``.py``, ``.ts``, ``.java``, ``.kt``). When set, only those files are extracted; existing + (``.py``, ``.ts``, ``.java``, ``.kt``, ``.go``, ``.sh``). When set, only those files are extracted; existing generated snippet files for those stems are replaced. Other stems in ``src/code-samples-generated/`` are left unchanged. Use ``make code-snippets-langsmith`` for the LangSmith JVM subset. @@ -81,10 +83,10 @@ def extract_snippets( language: str, ) -> list[tuple[str, str]]: """Return (snippet_id, body) for each ``:snippet-start:`` block in *text*.""" - if language == "python": + if language in ("python", "bash", "shell", "sh"): start_re, end_re = _RE_SNIP_START_PY, _RE_SNIP_END_PY rs, re_ = _RE_REMOVE_START_PY, _RE_REMOVE_END_PY - elif language in ("ts", "typescript", "javascript", "java", "kotlin"): + elif language in ("ts", "typescript", "javascript", "java", "kotlin", "go"): start_re, end_re = _RE_SNIP_START_TS, _RE_SNIP_END_TS rs, re_ = _RE_REMOVE_START_TS, _RE_REMOVE_END_TS else: @@ -138,6 +140,14 @@ def _iter_source_files(root: Path) -> list[Path]: if "node_modules" in path.parts: continue out.append(path) + for path in sorted(root.rglob("*.go")): + if "node_modules" in path.parts: + continue + out.append(path) + for path in sorted(root.rglob("*.sh")): + if "node_modules" in path.parts: + continue + out.append(path) return out @@ -150,7 +160,11 @@ def _language_for_path(path: Path) -> str: return "java" if path.suffix == ".kt": return "kotlin" - msg = f"expected .py, .ts, .java, or .kt, got {path.suffix!r}" + if path.suffix == ".go": + return "go" + if path.suffix == ".sh": + return "bash" + msg = f"expected .py, .ts, .java, .kt, .go, or .sh, got {path.suffix!r}" raise ValueError(msg) @@ -162,11 +176,13 @@ def _normalize_newlines(s: str) -> str: return s -def _delete_snippet_outputs_for_source(out_dir: Path, source_path: Path) -> None: +def _delete_snippet_outputs_for_source(out_dir: Path, source_path: Path, code_samples: Path) -> None: """Remove previously generated snippet files for one source file stem.""" stem = source_path.stem ext = source_path.suffix.lstrip(".") - for p in out_dir.glob(f"{stem}.snippet.*.{ext}"): + rel = source_path.relative_to(code_samples) + search_dir = out_dir / rel.parts[-2] if len(rel.parts) > 2 else out_dir + for p in search_dir.glob(f"{stem}.snippet.*.{ext}"): if p.is_file(): p.unlink() @@ -188,8 +204,8 @@ def _resolve_partial_sources(repo_root: Path, code_samples: Path) -> list[Path] except ValueError as e: msg = f"CODE_SNIPPET_SOURCES must be under {code_samples}: {part}" raise ValueError(msg) from e - if path.suffix not in (".py", ".ts", ".java", ".kt"): - msg = f"CODE_SNIPPET_SOURCES must be .py, .ts, .java, or .kt: {part}" + if path.suffix not in (".py", ".ts", ".java", ".kt", ".go", ".sh"): + msg = f"CODE_SNIPPET_SOURCES must be .py, .ts, .java, .kt, .go, or .sh: {part}" raise ValueError(msg) out.append(path) return out @@ -213,13 +229,13 @@ def main() -> int: return 1 if partial_sources is None: - for p in list(out_dir.iterdir()): - if p.suffix in (".py", ".ts", ".java", ".kt") and p.is_file(): + for p in out_dir.rglob("*"): + if p.suffix in (".py", ".ts", ".java", ".kt", ".go", ".sh") and p.is_file(): p.unlink() paths_to_process = _iter_source_files(code_samples) else: for src in partial_sources: - _delete_snippet_outputs_for_source(out_dir, src) + _delete_snippet_outputs_for_source(out_dir, src, code_samples) paths_to_process = partial_sources written: list[Path] = [] @@ -237,7 +253,10 @@ def main() -> int: return 1 for snippet_id, body in pairs: body = _normalize_newlines(body) - out_path = out_dir / f"{path.stem}.snippet.{snippet_id}.{path.suffix.lstrip('.')}" + rel = path.relative_to(code_samples) + out_subdir = out_dir / rel.parts[-2] if len(rel.parts) > 2 else out_dir + out_subdir.mkdir(parents=True, exist_ok=True) + out_path = out_subdir / f"{path.stem}.snippet.{snippet_id}.{path.suffix.lstrip('.')}" out_path.write_text(body, encoding="utf-8", newline="\n") written.append(out_path) diff --git a/scripts/generate_code_snippet_mdx.py b/scripts/generate_code_snippet_mdx.py index 3396b9692..d81d142dd 100644 --- a/scripts/generate_code_snippet_mdx.py +++ b/scripts/generate_code_snippet_mdx.py @@ -1,6 +1,6 @@ """Generate MDX snippet files from extracted code snippet files. -Reads .snippet.*.py, .snippet.*.ts, .snippet.*.java, and .snippet.*.kt files from src/code-samples-generated/ +Reads .snippet.*.py, .snippet.*.ts, .snippet.*.java, .snippet.*.kt, .snippet.*.go, and .snippet.*.sh files from src/code-samples-generated/ (produced by ``scripts/extract_code_snippets.py``, Bluehawk-compatible layout). and creates corresponding MDX files in src/snippets/code-samples/ for use in docs. @@ -255,12 +255,21 @@ def main() -> None: ("*.snippet.*.ts", "ts", "ts"), ("*.snippet.*.java", "java", "java"), ("*.snippet.*.kt", "kotlin", "kotlin"), + ("*.snippet.*.go", "go", "go"), + ("*.snippet.*.sh", "bash", "bash"), ] - lang_suffix = {"python": "-py", "ts": "-js", "java": "-java", "kotlin": "-kt"} + lang_suffix = { + "python": "-py", + "ts": "-js", + "java": "-java", + "kotlin": "-kt", + "go": "-go", + "bash": "-sh", + } for glob_pattern, language, fence_lang in snippet_configs: - for snippet_file in generated_dir.glob(glob_pattern): + for snippet_file in generated_dir.rglob(glob_pattern): snippet_name = ".".join(snippet_file.stem.split(".")[2:]) expected_suffix = lang_suffix[language] if not snippet_name.endswith(expected_suffix): @@ -270,7 +279,10 @@ def main() -> None: mdx_content = format_snippet_mdx( content, language=language, fence_lang=fence_lang ) - mdx_path = snippets_dir / f"{snippet_name}.mdx" + rel_parent = snippet_file.parent.relative_to(generated_dir) + out_subdir = snippets_dir / rel_parent + out_subdir.mkdir(parents=True, exist_ok=True) + mdx_path = out_subdir / f"{snippet_name}.mdx" mdx_path.write_text(mdx_content, encoding="utf-8") print(f"Generated {mdx_path.relative_to(repo_root)}") diff --git a/scripts/test_code_samples.py b/scripts/test_code_samples.py index 5113d7552..f49974da7 100644 --- a/scripts/test_code_samples.py +++ b/scripts/test_code_samples.py @@ -54,8 +54,10 @@ def collect_files_to_test( if not path.exists(): print(f"Warning: {path} not found, skipping") continue - if path.suffix not in (".py", ".ts", ".java", ".kt"): - print(f"Warning: {path} not .py, .ts, .java, or .kt, skipping") + if path.suffix not in (".py", ".ts", ".java", ".kt", ".go", ".sh"): + print( + f"Warning: {path} not .py, .ts, .java, .kt, .go, or .sh, skipping" + ) continue if code_samples_dir.resolve() not in path.parents: print(f"Warning: {path} not under src/code-samples/, skipping") @@ -66,8 +68,12 @@ def collect_files_to_test( lang = "ts" elif path.suffix == ".java": lang = "java" - else: + elif path.suffix == ".kt": lang = "kotlin" + elif path.suffix == ".go": + lang = "go" + else: + lang = "bash" result.append((path, lang)) return result @@ -92,11 +98,23 @@ def collect_files_to_test( for p in code_samples_dir.rglob("*.kt") if is_valid_sample(p, code_samples_dir) ) + go_files = sorted( + p + for p in code_samples_dir.rglob("*.go") + if is_valid_sample(p, code_samples_dir) + ) + sh_files = sorted( + p + for p in code_samples_dir.rglob("*.sh") + if is_valid_sample(p, code_samples_dir) + ) return ( [(p, "python") for p in py_files] + [(p, "ts") for p in ts_files] + [(p, "java") for p in java_files] + [(p, "kotlin") for p in kt_files] + + [(p, "go") for p in go_files] + + [(p, "bash") for p in sh_files] ) @@ -114,7 +132,7 @@ def main() -> int: if total == 0: if os.environ.get("FILES"): print( - "No valid files to test. Check that paths exist under src/code-samples/ and use .py or .ts" + "No valid files to test. Check that paths exist under src/code-samples/ and use .py, .ts, .java, .kt, .go, or .sh" ) else: print("No code samples found in src/code-samples/") @@ -161,6 +179,34 @@ def main() -> int: success = result.returncode == 0 stdout = result.stdout or "" stderr = result.stderr or "" + elif lang == "go": + # Go: run from code-samples dir so the shared go.mod resolves deps + result = subprocess.run( + ["go", "run", str(file_path.relative_to(code_samples_dir))], + check=False, + cwd=str(code_samples_dir), + capture_output=True, + text=True, + timeout=TIMEOUT_SECONDS, + env=env, + ) + success = result.returncode == 0 + stdout = result.stdout or "" + stderr = result.stderr or "" + elif lang == "bash": + # Shell/cURL samples: run from code-samples dir for consistency with ts/go + result = subprocess.run( + ["bash", str(file_path.relative_to(code_samples_dir))], + check=False, + cwd=str(code_samples_dir), + capture_output=True, + text=True, + timeout=TIMEOUT_SECONDS, + env=env, + ) + success = result.returncode == 0 + stdout = result.stdout or "" + stderr = result.stderr or "" else: # Java/Kotlin via JBang (single-file scripts). # diff --git a/src/code-samples/go.mod b/src/code-samples/go.mod new file mode 100644 index 000000000..b4d254167 --- /dev/null +++ b/src/code-samples/go.mod @@ -0,0 +1,34 @@ +module github.com/langchain-ai/docs-code-samples + +go 1.25.0 + +require github.com/langchain-ai/langsmith-go v0.17.0 + +require ( + github.com/cenkalti/backoff/v5 v5.0.3 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/go-logr/logr v1.4.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect + github.com/klauspost/compress v1.19.0 // indirect + github.com/tidwall/gjson v1.19.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.1 // indirect + github.com/tidwall/sjson v1.2.5 // indirect + go.opentelemetry.io/auto/sdk v1.2.1 // indirect + go.opentelemetry.io/otel v1.44.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 // indirect + go.opentelemetry.io/otel/metric v1.44.0 // indirect + go.opentelemetry.io/otel/sdk v1.44.0 // indirect + go.opentelemetry.io/otel/trace v1.44.0 // indirect + go.opentelemetry.io/proto/otlp v1.10.0 // indirect + golang.org/x/net v0.55.0 // indirect + golang.org/x/sys v0.45.0 // indirect + golang.org/x/text v0.37.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect + google.golang.org/grpc v1.81.1 // indirect + google.golang.org/protobuf v1.36.11 // indirect +) diff --git a/src/code-samples/go.sum b/src/code-samples/go.sum new file mode 100644 index 000000000..661641a94 --- /dev/null +++ b/src/code-samples/go.sum @@ -0,0 +1,75 @@ +github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= +github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs= +github.com/klauspost/compress v1.19.0 h1:sXLILfc9jV2QYWkzFOPWStmcUVH2RHEB1JCdY2oVvCQ= +github.com/klauspost/compress v1.19.0/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/langchain-ai/langsmith-go v0.17.0 h1:fZWO0tm/hB9CiaG+e8CQR2wPTZnsuZZrWKrC/14OCcE= +github.com/langchain-ai/langsmith-go v0.17.0/go.mod h1:2NXq2u8YbQkpP9BaKG7RKs0g0ZoCeqVzAZsBu7nr58Y= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.19.0 h1:xwxm7n691Uf3u5OFjzngavjGTh55KX5q/9w9xHW88JU= +github.com/tidwall/gjson v1.19.0/go.mod h1:V37/opeE/JbLUOfH0QTXiNez2l0RUjYUhpT4szFQAfc= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= +github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= +go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU= +go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 h1:4YsVu3B8+3qtWYYrsUYgn0OG78pN0rnNPRGX4SbokQI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0/go.mod h1:+wnlSn0mD1ADVMe3v9Z/WIaiz6q6gL2J/ejaAmdmv80= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 h1:lgh3PiVrRUWMLOVSkQicxzZll5NjF1r+AtsX1XRIHw0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0/go.mod h1:5Cnhth3m/AgOeTgE3ex12pPmiu/gGtZit03kSzx9X7s= +go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc= +go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo= +go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58= +go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0= +go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI= +go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA= +go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk= +go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= +go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g= +go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= +golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= +golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= +golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= +golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= +gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= +gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= +google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa h1:Kjn0N0tCrDgiAFW+lGO4JZ3ck44CehvJQMAwj9QF0G8= +google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:q4lMZS6kskjT5HvCPrnnypcDPVJqT/f4nfxmkE7gryY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ= +google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.go new file mode 100644 index 000000000..bb86a0b28 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.go @@ -0,0 +1,43 @@ +// :snippet-start: runs-query-boolean-filters-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +filterStr := `and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))` +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.kt new file mode 100644 index 000000000..9712acf2f --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.kt @@ -0,0 +1,35 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-boolean-filters-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-boolean-filters-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(gt(start_time, \"2023-07-15T12:34:56Z\")," + + " or(neq(status, \"error\")," + + " and(eq(feedback_key, \"Correctness\"), eq(feedback_score, 0.0))))" +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).filter(filterStr).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.sh new file mode 100644 index 000000000..1c91ee793 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-boolean-filters-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +FILTER='and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"project_ids": [$pid], "filter": $f}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.ts new file mode 100644 index 000000000..aa7dfb16e --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-after.ts @@ -0,0 +1,18 @@ + +// :snippet-start: runs-query-boolean-filters-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + + ' or(neq(status, "error"),' + + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'; +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + filter: filterStr, +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.go new file mode 100644 index 000000000..b7ca3479b --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.go @@ -0,0 +1,43 @@ +// :snippet-start: runs-query-boolean-filters-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +filterStr := `and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))` +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.kt new file mode 100644 index 000000000..30c03e1bc --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.kt @@ -0,0 +1,35 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-boolean-filters-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-boolean-filters-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(gt(start_time, \"2023-07-15T12:34:56Z\")," + + " or(neq(status, \"error\")," + + " and(eq(feedback_key, \"Correctness\"), eq(feedback_score, 0.0))))" +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).filter(filterStr).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.sh new file mode 100644 index 000000000..d9d5e795e --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-boolean-filters-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +FILTER='and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"session": [$pid], "filter": $f}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.ts new file mode 100644 index 000000000..67f826dc0 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters-before.ts @@ -0,0 +1,12 @@ + +// :snippet-start: runs-query-boolean-filters-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + + ' or(neq(status, "error"),' + + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'; +const runs = client.listRuns({ projectName: "default", filter: filterStr }); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters.py b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters.py new file mode 100644 index 000000000..10511d5a5 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-boolean-filters.py @@ -0,0 +1,35 @@ + +# :snippet-start: runs-query-boolean-filters-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +filter_str = ( + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + ' or(neq(status, "error"),' + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' +) +runs = client.list_runs(project_name="default", filter=filter_str) +# :snippet-end: + +# :snippet-start: runs-query-boolean-filters-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + filter_str = ( + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + ' or(neq(status, "error"),' + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' + ) + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], filter=filter_str) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.go new file mode 100644 index 000000000..2bcdc490d --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.go @@ -0,0 +1,55 @@ +// :snippet-start: runs-query-fetch-by-id-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runID1 := "" +runID2 := "" +// :remove-start: +found, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + PageSize: langsmith.F(int64(2)), +}) +if err != nil { + panic(err.Error()) +} +runID1 = found.Items[0].ID +runID2 = found.Items[1].ID +// :remove-end: +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + IDs: langsmith.F([]string{runID1, runID2}), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.kt new file mode 100644 index 000000000..0869ca921 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.kt @@ -0,0 +1,36 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-fetch-by-id-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-fetch-by-id-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .addId("") + .addId("") + .build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.sh new file mode 100644 index 000000000..e15feb157 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-fetch-by-id-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +RUN_ID_1="" +RUN_ID_2="" +# :remove-start: +FOUND=$(curl -s -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "page_size": 2}')") +RUN_ID_1=$(echo "$FOUND" | jq -r '.items[0].id') +RUN_ID_2=$(echo "$FOUND" | jq -r '.items[1].id') +[ -n "$RUN_ID_1" ] && [ "$RUN_ID_1" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +[ -n "$RUN_ID_2" ] && [ "$RUN_ID_2" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg r1 "$RUN_ID_1" --arg r2 "$RUN_ID_2" '{"project_ids": [$pid], "ids": [$r1, $r2]}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.ts new file mode 100644 index 000000000..ef90dd6c8 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-after.ts @@ -0,0 +1,14 @@ + +// :snippet-start: runs-query-fetch-by-id-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + ids: ["", ""], +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.go new file mode 100644 index 000000000..6486765b0 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.go @@ -0,0 +1,55 @@ +// :snippet-start: runs-query-fetch-by-id-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runID1 := "" +runID2 := "" +// :remove-start: +found, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Limit: langsmith.F(int64(2)), +}) +if err != nil { + panic(err.Error()) +} +runID1 = found.Runs[0].ID +runID2 = found.Runs[1].ID +// :remove-end: +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + ID: langsmith.F([]string{runID1, runID2}), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.kt new file mode 100644 index 000000000..1804d9d45 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.kt @@ -0,0 +1,45 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-fetch-by-id-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-fetch-by-id-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +var runId1 = "" +var runId2 = "" +// :remove-start: +val foundRuns = client.runs().query( + RunQueryParams.builder().addSession(project.id()).limit(2L).build() +).items() +runId1 = foundRuns[0].id() +runId2 = foundRuns[1].id() +// :remove-end: +val runs = client.runs().query( + RunQueryParams.builder() + .addSession(project.id()) + .addId(runId1) + .addId(runId2) + .build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.sh new file mode 100644 index 000000000..ebb4e50a2 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-fetch-by-id-before-sh +RUN_ID_1="" +RUN_ID_2="" +# :remove-start: +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +FOUND=$(curl -s -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "limit": 2}')") +RUN_ID_1=$(echo "$FOUND" | jq -r '.runs[0].id') +RUN_ID_2=$(echo "$FOUND" | jq -r '.runs[1].id') +[ -n "$RUN_ID_1" ] && [ "$RUN_ID_1" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +[ -n "$RUN_ID_2" ] && [ "$RUN_ID_2" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg r1 "$RUN_ID_1" --arg r2 "$RUN_ID_2" '{"id": [$r1, $r2]}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.ts new file mode 100644 index 000000000..1077b2eee --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id-before.ts @@ -0,0 +1,8 @@ + +// :snippet-start: runs-query-fetch-by-id-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ id: ["", ""] }); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id.py b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id.py new file mode 100644 index 000000000..6eac78524 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-fetch-by-id.py @@ -0,0 +1,28 @@ + +# :snippet-start: runs-query-fetch-by-id-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +runs = client.list_runs(id=["", ""]) +# :snippet-end: + +# :snippet-start: runs-query-fetch-by-id-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query( + project_ids=[str(project.id)], + ids=["", ""], + ) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.go new file mode 100644 index 000000000..23283ba19 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.go @@ -0,0 +1,42 @@ +// :snippet-start: runs-query-filter-errors-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + HasError: langsmith.F(true), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.kt new file mode 100644 index 000000000..827a7f89d --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.kt @@ -0,0 +1,32 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-errors-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-errors-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).hasError(true).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.sh new file mode 100644 index 000000000..55174119a --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-errors-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "has_error": true}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.ts new file mode 100644 index 000000000..4a271a713 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-after.ts @@ -0,0 +1,14 @@ + +// :snippet-start: runs-query-filter-errors-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + has_error: true, +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.go new file mode 100644 index 000000000..118ceb9c4 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.go @@ -0,0 +1,42 @@ +// :snippet-start: runs-query-filter-errors-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Error: langsmith.F(true), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.kt new file mode 100644 index 000000000..075fa8962 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.kt @@ -0,0 +1,32 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-errors-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-errors-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).error(true).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.sh new file mode 100644 index 000000000..9c42c7a16 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-errors-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "error": true}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.ts new file mode 100644 index 000000000..05525f04a --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors-before.ts @@ -0,0 +1,8 @@ + +// :snippet-start: runs-query-filter-errors-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ projectName: "default", error: true }); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors.py b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors.py new file mode 100644 index 000000000..2ea723546 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-errors.py @@ -0,0 +1,25 @@ + +# :snippet-start: runs-query-filter-errors-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default", error=True) +# :snippet-end: + +# :snippet-start: runs-query-filter-errors-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], has_error=True) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.go new file mode 100644 index 000000000..b4a505ace --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.go @@ -0,0 +1,43 @@ +// :snippet-start: runs-query-filter-metadata-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +filterStr := `and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))` +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.kt new file mode 100644 index 000000000..e1b9a7b1d --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.kt @@ -0,0 +1,33 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-metadata-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-metadata-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(eq(metadata_key, \"user_id\"), eq(metadata_value, \"u_123\"))" +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).filter(filterStr).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.sh new file mode 100644 index 000000000..5d022a18d --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-metadata-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +FILTER='and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"project_ids": [$pid], "filter": $f}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.ts new file mode 100644 index 000000000..c77486114 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-after.ts @@ -0,0 +1,15 @@ + +// :snippet-start: runs-query-filter-metadata-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'; +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + filter: filterStr, +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.go new file mode 100644 index 000000000..be2a0b9d0 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.go @@ -0,0 +1,43 @@ +// :snippet-start: runs-query-filter-metadata-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +filterStr := `and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))` +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.kt new file mode 100644 index 000000000..4d12312c1 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.kt @@ -0,0 +1,33 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-metadata-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-metadata-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(eq(metadata_key, \"user_id\"), eq(metadata_value, \"u_123\"))" +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).filter(filterStr).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.sh new file mode 100644 index 000000000..4c9051234 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-metadata-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +FILTER='and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"session": [$pid], "filter": $f}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.ts new file mode 100644 index 000000000..0b689647c --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata-before.ts @@ -0,0 +1,9 @@ + +// :snippet-start: runs-query-filter-metadata-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'; +const runs = client.listRuns({ projectName: "default", filter: filterStr }); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata.py b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata.py new file mode 100644 index 000000000..27113dc62 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-metadata.py @@ -0,0 +1,27 @@ + +# :snippet-start: runs-query-filter-metadata-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +filter_str = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' +runs = client.list_runs(project_name="default", filter=filter_str) +# :snippet-end: + +# :snippet-start: runs-query-filter-metadata-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + filter_str = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], filter=filter_str) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.go new file mode 100644 index 000000000..bbe5fffdd --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.go @@ -0,0 +1,42 @@ +// :snippet-start: runs-query-filter-root-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + IsRoot: langsmith.F(true), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.kt new file mode 100644 index 000000000..b5299b667 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.kt @@ -0,0 +1,32 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-root-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-root-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).isRoot(true).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.sh new file mode 100644 index 000000000..ed2ef079a --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-root-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "is_root": true}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.ts new file mode 100644 index 000000000..b170fb3b7 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-after.ts @@ -0,0 +1,14 @@ + +// :snippet-start: runs-query-filter-root-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + is_root: true, +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.go new file mode 100644 index 000000000..bb039f355 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.go @@ -0,0 +1,42 @@ +// :snippet-start: runs-query-filter-root-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + IsRoot: langsmith.F(true), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.kt new file mode 100644 index 000000000..73b631164 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.kt @@ -0,0 +1,32 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-root-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-root-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).isRoot(true).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.sh new file mode 100644 index 000000000..a46992631 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-root-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "is_root": true}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.ts new file mode 100644 index 000000000..2873b57f3 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root-before.ts @@ -0,0 +1,8 @@ + +// :snippet-start: runs-query-filter-root-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ projectName: "default", isRoot: true }); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root.py b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root.py new file mode 100644 index 000000000..786b5b485 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-root.py @@ -0,0 +1,25 @@ + +# :snippet-start: runs-query-filter-root-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default", is_root=True) +# :snippet-end: + +# :snippet-start: runs-query-filter-root-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], is_root=True) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.go new file mode 100644 index 000000000..68053c85b --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.go @@ -0,0 +1,44 @@ +// :snippet-start: runs-query-filter-time-range-after-go +// :codegroup-tab: After +package main + +import ( + "context" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + MinStartTime: langsmith.F(time.Now().Add(-24 * time.Hour)), + RunType: langsmith.F(langsmith.RunQueryV2ParamsRunTypeLlm), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.kt new file mode 100644 index 000000000..557767bbd --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.kt @@ -0,0 +1,38 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-time-range-after-kt +// :codegroup-tab: After +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-time-range-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .minStartTime(OffsetDateTime.now().minusDays(1)) + .runType(RunQueryV2Params.RunType.LLM) + .build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.sh new file mode 100644 index 000000000..7ef6716c1 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-time-range-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "run_type": "LLM", "min_start_time": "2025-01-01T00:00:00Z"}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.ts new file mode 100644 index 000000000..ae1308c24 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-after.ts @@ -0,0 +1,16 @@ + +// :snippet-start: runs-query-filter-time-range-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000); +const runs = client.runs.query({ + project_ids: [project.id], + min_start_time: oneDayAgo.toISOString(), + run_type: "LLM", +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.go new file mode 100644 index 000000000..b2cfe06b1 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.go @@ -0,0 +1,44 @@ +// :snippet-start: runs-query-filter-time-range-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + StartTime: langsmith.F(time.Now().Add(-24 * time.Hour)), + RunType: langsmith.F(langsmith.RunTypeEnumLlm), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.kt new file mode 100644 index 000000000..7d2c222a1 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.kt @@ -0,0 +1,39 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-filter-time-range-before-kt +// :codegroup-tab: Before +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.runs.RunTypeEnum +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-filter-time-range-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder() + .addSession(project.id()) + .startTime(OffsetDateTime.now().minusDays(1)) + .runType(RunTypeEnum.LLM) + .build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.sh new file mode 100644 index 000000000..6ab133033 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-filter-time-range-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "run_type": "llm", "start_time": "2025-01-01T00:00:00Z"}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.ts new file mode 100644 index 000000000..f32d7de40 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range-before.ts @@ -0,0 +1,12 @@ + +// :snippet-start: runs-query-filter-time-range-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ + projectName: "default", + startTime: new Date(Date.now() - 24 * 60 * 60 * 1000), + runType: "llm", +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range.py b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range.py new file mode 100644 index 000000000..3a36f0e0b --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-filter-time-range.py @@ -0,0 +1,36 @@ + +# :snippet-start: runs-query-filter-time-range-before-py +# :codegroup-tab: Before +from datetime import datetime, timedelta + +from langsmith import Client + +client = Client() +runs = client.list_runs( + project_name="default", + start_time=datetime.now() - timedelta(days=1), + run_type="llm", +) +# :snippet-end: + +# :snippet-start: runs-query-filter-time-range-after-py +# :codegroup-tab: After +import asyncio +from datetime import datetime, timedelta + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query( + project_ids=[str(project.id)], + min_start_time=datetime.now() - timedelta(days=1), + run_type="LLM", + ) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.go new file mode 100644 index 000000000..7aaf1b080 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.go @@ -0,0 +1,41 @@ +// :snippet-start: runs-query-list-all-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.kt new file mode 100644 index 000000000..3a3c77e1e --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.kt @@ -0,0 +1,32 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-list-all-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-list-all-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.sh new file mode 100644 index 000000000..61069c39e --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-list-all-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid]}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.ts new file mode 100644 index 000000000..36318fb35 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-after.ts @@ -0,0 +1,11 @@ + +// :snippet-start: runs-query-list-all-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ project_ids: [project.id] }); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.go new file mode 100644 index 000000000..251c86957 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.go @@ -0,0 +1,41 @@ +// :snippet-start: runs-query-list-all-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.kt new file mode 100644 index 000000000..fab546667 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.kt @@ -0,0 +1,32 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-list-all-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-list-all-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.sh new file mode 100644 index 000000000..f7be60679 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-list-all-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid]}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.ts new file mode 100644 index 000000000..a75ec582a --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all-before.ts @@ -0,0 +1,8 @@ + +// :snippet-start: runs-query-list-all-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ projectName: "default" }); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-list-all.py b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all.py new file mode 100644 index 000000000..90ac00b83 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-list-all.py @@ -0,0 +1,25 @@ + +# :snippet-start: runs-query-list-all-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default") +# :snippet-end: + +# :snippet-start: runs-query-list-all-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)]) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.go new file mode 100644 index 000000000..71f860706 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.go @@ -0,0 +1,47 @@ +// :snippet-start: runs-query-pagination-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs := []langsmith.Run{} +iter := client.Runs.QueryV2AutoPaging(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), +}) +for iter.Next() { + runs = append(runs, iter.Current()) + if len(runs) >= 150 { + break + } +} +// :remove-start: +if iter.Err() != nil { + panic(iter.Err().Error()) +} +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.kt new file mode 100644 index 000000000..10cc1c935 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.kt @@ -0,0 +1,36 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-pagination-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-pagination-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = mutableListOf() +for (run in client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).build() +).autoPager()) { + runs.add(run) + if (runs.size >= 150) break +} +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.sh new file mode 100644 index 000000000..f3c7cc8b0 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-pagination-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +# Fetch pages, passing the cursor from each response's next_cursor field +# to fetch the next page, until 150 runs are collected or pages run out. +TOTAL=0 +CURSOR="" +while :; do + BODY=$(jq -n --arg pid "$PROJECT_ID" --arg cursor "$CURSOR" \ + 'if $cursor == "" then {"project_ids": [$pid]} else {"project_ids": [$pid], "cursor": $cursor} end') + RESPONSE=$(curl -s -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$BODY") + TOTAL=$((TOTAL + $(echo "$RESPONSE" | jq '.items | length'))) + CURSOR=$(echo "$RESPONSE" | jq -r '.next_cursor // empty') + [ "$TOTAL" -lt 150 ] && [ -n "$CURSOR" ] || break +done +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.ts new file mode 100644 index 000000000..c3dc8b34d --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-after.ts @@ -0,0 +1,17 @@ + +// :snippet-start: runs-query-pagination-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs: unknown[] = []; +for await (const run of client.runs.query({ + project_ids: [project.id], +})) { + runs.push(run); + if (runs.length >= 150) break; +} +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.go new file mode 100644 index 000000000..a047210cb --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.go @@ -0,0 +1,47 @@ +// :snippet-start: runs-query-pagination-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs := []langsmith.RunSchema{} +iter := client.Runs.QueryAutoPaging(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), +}) +for iter.Next() { + runs = append(runs, iter.Current()) + if len(runs) >= 150 { + break + } +} +// :remove-start: +if iter.Err() != nil { + panic(iter.Err().Error()) +} +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.kt new file mode 100644 index 000000000..f19052c02 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.kt @@ -0,0 +1,36 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-pagination-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-pagination-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = mutableListOf() +for (run in client.runs().query( + RunQueryParams.builder().addSession(project.id()).build() +).autoPager()) { + runs.add(run) + if (runs.size >= 150) break +} +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.sh new file mode 100644 index 000000000..a9bd31c6b --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-pagination-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "limit": 150}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.ts new file mode 100644 index 000000000..09b89731a --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination-before.ts @@ -0,0 +1,12 @@ + +// :snippet-start: runs-query-pagination-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs: unknown[] = []; +for await (const run of client.listRuns({ projectName: "default" })) { + runs.push(run); + if (runs.length >= 150) break; +} +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-pagination.py b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination.py new file mode 100644 index 000000000..7baafe3d4 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-pagination.py @@ -0,0 +1,31 @@ + +# :snippet-start: runs-query-pagination-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default", limit=150) +# :snippet-end: + +# :snippet-start: runs-query-pagination-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = [] + async for run in client.runs.query( + project_ids=[str(project.id)], + ): + runs.append(run) + if len(runs) >= 150: + break + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.go new file mode 100644 index 000000000..1ad5ecfc7 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.go @@ -0,0 +1,44 @@ +// :snippet-start: runs-query-scoped-filters-after-go +// :codegroup-tab: After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Filter: langsmith.F(`eq(name, "RetrieveDocs")`), + TraceFilter: langsmith.F(`and(eq(feedback_key, "user_score"), eq(feedback_score, 1))`), + TreeFilter: langsmith.F(`eq(name, "ExpandQuery")`), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.kt new file mode 100644 index 000000000..6cf7513ba --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.kt @@ -0,0 +1,37 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-scoped-filters-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-scoped-filters-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .filter("eq(name, \"RetrieveDocs\")") + .traceFilter("and(eq(feedback_key, \"user_score\"), eq(feedback_score, 1))") + .treeFilter("eq(name, \"ExpandQuery\")") + .build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.sh new file mode 100644 index 000000000..287548f32 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-scoped-filters-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +FILTER='eq(name, "RetrieveDocs")' +TRACE_FILTER='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))' +TREE_FILTER='eq(name, "ExpandQuery")' + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n \ + --arg pid "$PROJECT_ID" \ + --arg f "$FILTER" \ + --arg tf "$TRACE_FILTER" \ + --arg treef "$TREE_FILTER" \ + '{"project_ids": [$pid], "filter": $f, "trace_filter": $tf, "tree_filter": $treef}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.ts new file mode 100644 index 000000000..90454d8e8 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-after.ts @@ -0,0 +1,16 @@ + +// :snippet-start: runs-query-scoped-filters-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + filter: 'eq(name, "RetrieveDocs")', + trace_filter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + tree_filter: 'eq(name, "ExpandQuery")', +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.go new file mode 100644 index 000000000..de63d9e35 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.go @@ -0,0 +1,44 @@ +// :snippet-start: runs-query-scoped-filters-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Filter: langsmith.F(`eq(name, "RetrieveDocs")`), + TraceFilter: langsmith.F(`and(eq(feedback_key, "user_score"), eq(feedback_score, 1))`), + TreeFilter: langsmith.F(`eq(name, "ExpandQuery")`), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +_ = runs +// :remove-end: +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.kt new file mode 100644 index 000000000..4915216a4 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.kt @@ -0,0 +1,37 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-scoped-filters-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-scoped-filters-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder() + .addSession(project.id()) + .filter("eq(name, \"RetrieveDocs\")") + .traceFilter("and(eq(feedback_key, \"user_score\"), eq(feedback_score, 1))") + .treeFilter("eq(name, \"ExpandQuery\")") + .build() +).items() +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.sh new file mode 100644 index 000000000..6b8810f64 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-scoped-filters-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +FILTER='eq(name, "RetrieveDocs")' +TRACE_FILTER='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))' +TREE_FILTER='eq(name, "ExpandQuery")' + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n \ + --arg pid "$PROJECT_ID" \ + --arg f "$FILTER" \ + --arg tf "$TRACE_FILTER" \ + --arg treef "$TREE_FILTER" \ + '{"session": [$pid], "filter": $f, "trace_filter": $tf, "tree_filter": $treef}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.ts new file mode 100644 index 000000000..90a96d826 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters-before.ts @@ -0,0 +1,13 @@ + +// :snippet-start: runs-query-scoped-filters-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ + projectName: "default", + filter: 'eq(name, "RetrieveDocs")', + traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + treeFilter: 'eq(name, "ExpandQuery")', +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters.py b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters.py new file mode 100644 index 000000000..9dc3a6763 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-scoped-filters.py @@ -0,0 +1,35 @@ + +# :snippet-start: runs-query-scoped-filters-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +runs = client.list_runs( + project_name="default", + filter='eq(name, "RetrieveDocs")', + trace_filter='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + tree_filter='eq(name, "ExpandQuery")', +) +# :snippet-end: + +# :snippet-start: runs-query-scoped-filters-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query( + project_ids=[str(project.id)], + filter='eq(name, "RetrieveDocs")', + trace_filter='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + tree_filter='eq(name, "ExpandQuery")', + ) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.go b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.go new file mode 100644 index 000000000..882766f77 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.go @@ -0,0 +1,57 @@ +// :snippet-start: runs-query-selecting-fields-after-go +// :codegroup-tab: After +package main + +import ( + "context" + "fmt" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +// must explicitly list every field needed; default returns only id +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Selects: langsmith.F([]langsmith.RunQueryV2ParamsSelect{ + langsmith.RunQueryV2ParamsSelectID, + langsmith.RunQueryV2ParamsSelectName, + langsmith.RunQueryV2ParamsSelectRunType, + langsmith.RunQueryV2ParamsSelectStatus, + langsmith.RunQueryV2ParamsSelectStartTime, + langsmith.RunQueryV2ParamsSelectInputs, + langsmith.RunQueryV2ParamsSelectError, + }), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +for _, run := range runs.Items { + fmt.Println(run.ID, run.Name, run.RunType, run.Status, run.StartTime, run.Inputs, run.Error) + // :remove-start: + break + // :remove-end: +} +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.kt new file mode 100644 index 000000000..ce6cd6aa0 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.kt @@ -0,0 +1,48 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-selecting-fields-after-kt +// :codegroup-tab: After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-selecting-fields-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +// must explicitly list every field needed; default returns only id +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .addSelect(RunQueryV2Params.Select.ID) + .addSelect(RunQueryV2Params.Select.NAME) + .addSelect(RunQueryV2Params.Select.RUN_TYPE) + .addSelect(RunQueryV2Params.Select.STATUS) + .addSelect(RunQueryV2Params.Select.START_TIME) + .addSelect(RunQueryV2Params.Select.INPUTS) + .addSelect(RunQueryV2Params.Select.ERROR) + .build() +).items() +for (run in runs) { + println("${run.id()} ${run.name()} ${run.runType()} ${run.status()} ${run.startTime()} ${run.inputs()} ${run.error()}") + // :remove-start: + break + // :remove-end: +} +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.sh new file mode 100644 index 000000000..ca14d8d1e --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-selecting-fields-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "selects": ["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"]}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.ts new file mode 100644 index 000000000..54d1154cd --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-after.ts @@ -0,0 +1,20 @@ + +// :snippet-start: runs-query-selecting-fields-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +// must explicitly list every field needed; default returns only id +for await (const run of client.runs.query({ + project_ids: [project.id], + selects: ["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"], +})) { + console.log(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error); + // :remove-start: + break; + // :remove-end: +} +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.go b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.go new file mode 100644 index 000000000..ece3886c7 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.go @@ -0,0 +1,48 @@ +// :snippet-start: runs-query-selecting-fields-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + "fmt" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +project := sessions.Items[0] + +// returns a default set of fields; no explicit selection needed +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +for _, run := range runs.Runs { + fmt.Println(run.ID, run.Name, run.RunType, run.Status, run.StartTime, run.Inputs, run.Error) + // :remove-start: + break + // :remove-end: +} +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.kt new file mode 100644 index 000000000..b481aa382 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.kt @@ -0,0 +1,39 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-query-selecting-fields-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-query-selecting-fields-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +// returns a default set of fields; no explicit selection needed +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).build() +).items() +for (run in runs) { + println("${run.id()} ${run.name()} ${run.runType()} ${run.status()} ${run.startTime()} ${run.inputs()} ${run.error()}") + // :remove-start: + break + // :remove-end: +} +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.sh new file mode 100644 index 000000000..5320d78d2 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-query-selecting-fields-before-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid]}')" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.ts new file mode 100644 index 000000000..ba4705ce8 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields-before.ts @@ -0,0 +1,15 @@ + +// :snippet-start: runs-query-selecting-fields-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +// returns a default set of fields; no explicit selection needed +const runs = client.listRuns({ projectName: "default" }); +for await (const run of runs) { + console.log(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error); + // :remove-start: + break; + // :remove-end: +} +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields.py b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields.py new file mode 100644 index 000000000..5a5c9b829 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-query-selecting-fields.py @@ -0,0 +1,39 @@ + +# :snippet-start: runs-query-selecting-fields-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +# returns a default set of fields; no explicit selection needed +runs = client.list_runs(project_name="default") +for run in runs: + print(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error) + # :remove-start: + break + # :remove-end: +# :snippet-end: + +# :snippet-start: runs-query-selecting-fields-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + # must explicitly list every field needed; default returns only id + async for run in client.runs.query( + project_ids=[str(project.id)], + selects=["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"], + ): + print(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error) + # :remove-start: + break + # :remove-end: + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.go b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.go new file mode 100644 index 000000000..2f36eb5db --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.go @@ -0,0 +1,64 @@ +// :snippet-start: runs-retrieve-basic-after-go +// :codegroup-tab: After +package main + +import ( + "context" + "fmt" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +startTime := time.Date(2026, 6, 1, 12, 0, 0, 0, time.UTC) +projectID := "" +// :remove-start: +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +projectID = sessions.Items[0].ID +found, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{projectID}), + Selects: langsmith.F([]langsmith.RunQueryV2ParamsSelect{ + langsmith.RunQueryV2ParamsSelectID, + langsmith.RunQueryV2ParamsSelectStartTime, + }), + PageSize: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +runID = found.Items[0].ID +startTime = found.Items[0].StartTime +// :remove-end: +run, err := client.Runs.GetV2(ctx, runID, langsmith.RunGetV2Params{ + ProjectID: langsmith.F(projectID), + StartTime: langsmith.F(startTime), + Selects: langsmith.F([]langsmith.RunGetV2ParamsSelect{ + langsmith.RunGetV2ParamsSelectName, + langsmith.RunGetV2ParamsSelectStatus, + langsmith.RunGetV2ParamsSelectTotalTokens, + }), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +fmt.Println(run.Name, run.Status, run.TotalTokens) +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.kt new file mode 100644 index 000000000..59820350d --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.kt @@ -0,0 +1,60 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-retrieve-basic-after-kt +// :codegroup-tab: After +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunRetrieveV2Params +import com.langchain.smith.models.sessions.SessionListParams +// :remove-start: +import com.langchain.smith.models.runs.RunQueryV2Params +// :remove-end: + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-retrieve-basic-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() + +var runId = "" +var startTime = "" +// :remove-start: +val foundRun = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .addSelect(RunQueryV2Params.Select.ID) + .addSelect(RunQueryV2Params.Select.START_TIME) + .pageSize(1L) + .build() +).items().first() +runId = foundRun.id().get() +startTime = foundRun.startTime().get().toString() +// :remove-end: +val run = client.runs().retrieveV2( + runId, + RunRetrieveV2Params.builder() + .projectId(project.id()) + .startTime(OffsetDateTime.parse(startTime)) + .addSelect(RunRetrieveV2Params.Select.NAME) + .addSelect(RunRetrieveV2Params.Select.STATUS) + .addSelect(RunRetrieveV2Params.Select.TOTAL_TOKENS) + .build() +) +println("${run.name()} ${run.status()} ${run.totalTokens()}") +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.sh new file mode 100644 index 000000000..39e912a4d --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-retrieve-basic-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +RUN_ID="" +START_TIME="2026-06-01T12:00:00Z" +# :remove-start: +FOUND=$(curl -s -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "selects": ["ID", "START_TIME"], "page_size": 1}')") +RUN_ID=$(echo "$FOUND" | jq -r '.items[0].id') +START_TIME=$(echo "$FOUND" | jq -r '.items[0].start_time') +[ -n "$RUN_ID" ] && [ "$RUN_ID" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +# :remove-end: + +curl "https://api.smith.langchain.com/v2/runs/$RUN_ID?project_id=$PROJECT_ID&start_time=$START_TIME&selects=NAME&selects=STATUS&selects=TOTAL_TOKENS" \ + -H "x-api-key: $LANGSMITH_API_KEY" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.ts new file mode 100644 index 000000000..64c37aecd --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-after.ts @@ -0,0 +1,38 @@ +import { Client } from "langsmith"; + +async function findRun(projectId: string) { + const client = new Client(); + for await (const run of client.runs.query({ project_ids: [projectId], selects: ["ID", "START_TIME"] })) { + return run; + } + return null; +} + +async function getProjectId() { + const client = new Client(); + const page = await client.projects.list({ name: "default", limit: 1 }); + const projects = page.getPaginatedItems(); + return projects[0]?.id; +} + +// :snippet-start: runs-retrieve-basic-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +let runId = ""; +let startTime = "2026-06-01T12:00:00Z"; +let projectId = ""; +// :remove-start: +projectId = await getProjectId(); +const run = await findRun(projectId); +runId = run.id; +startTime = run.start_time; +// :remove-end: +const retrievedRun = await client.runs.retrieve(runId, { + project_id: projectId, + start_time: startTime, + selects: ["NAME", "STATUS", "TOTAL_TOKENS"], +}); +console.log(retrievedRun.name, retrievedRun.status, retrievedRun.total_tokens); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.go b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.go new file mode 100644 index 000000000..19278d30b --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.go @@ -0,0 +1,47 @@ +// :snippet-start: runs-retrieve-basic-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + "fmt" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +// :remove-start: +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +found, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{sessions.Items[0].ID}), + Limit: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +runID = found.Runs[0].ID +// :remove-end: +run, err := client.Runs.Get(ctx, runID, langsmith.RunGetParams{}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +fmt.Println(run.Name, run.Status, run.TotalTokens) +// :remove-start: +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.kt new file mode 100644 index 000000000..e96551480 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.kt @@ -0,0 +1,40 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-retrieve-basic-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +// :remove-start: +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams +// :remove-end: + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-retrieve-basic-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +var runId = "" +// :remove-start: +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val foundRun = client.runs().query( + RunQueryParams.builder().addSession(project.id()).limit(1L).build() +).items().first() +runId = foundRun.id() +// :remove-end: +val run = client.runs().retrieve(runId) +println("${run.name()} ${run.status()} ${run.totalTokens()}") +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.sh new file mode 100644 index 000000000..327022beb --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-retrieve-basic-before-sh +RUN_ID="" +# :remove-start: +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +FOUND=$(curl -s -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "limit": 1}')") +RUN_ID=$(echo "$FOUND" | jq -r '.runs[0].id') +[ -n "$RUN_ID" ] && [ "$RUN_ID" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +# :remove-end: + +curl "https://api.smith.langchain.com/api/v1/runs/$RUN_ID" \ + -H "x-api-key: $LANGSMITH_API_KEY" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.ts new file mode 100644 index 000000000..7523df77b --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic-before.ts @@ -0,0 +1,31 @@ +import { Client } from "langsmith"; + +async function findRun(projectId: string) { + const client = new Client(); + for await (const run of client.runs.query({ project_ids: [projectId], selects: ["ID", "START_TIME"] })) { + return run; + } + return null; +} + +async function getProjectId() { + const client = new Client(); + const page = await client.projects.list({ name: "default", limit: 1 }); + const projects = page.getPaginatedItems(); + return projects[0]?.id; +} + +// :snippet-start: runs-retrieve-basic-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +let runId = ""; +// :remove-start: +const projectId = await getProjectId(); +const run = await findRun(projectId); +runId = run.id; +// :remove-end: +const retrievedRun = await client.readRun(runId); +console.log(retrievedRun.name, retrievedRun.status, retrievedRun.total_tokens); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic.py b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic.py new file mode 100644 index 000000000..13654bfae --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-basic.py @@ -0,0 +1,59 @@ + +import asyncio + +async def find_run(project_id: str): + client = Client() + async for run in client.runs.query(project_ids=[project_id], selects=["ID", "START_TIME"]): + return run + return None + +async def get_project_id(): + from langsmith import Client as AsyncClient + client = AsyncClient() + async for project in client.projects.list(name="default", limit=1): + return project.id + return None + +# :snippet-start: runs-retrieve-basic-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +run_id = "" +# :remove-start: +project_id = asyncio.run(get_project_id()) +run_id = asyncio.run(find_run(project_id)).id +# :remove-end: +run = client.read_run(run_id=run_id) +print(run.name, run.status, run.total_tokens) +# :snippet-end: + +# :snippet-start: runs-retrieve-basic-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + run_id = "" + start_time = "2026-06-01T12:00:00Z" + # :remove-start: + run = await find_run(project.id) + run_id = run.id + start_time = run.start_time + # :remove-end: + run = await client.runs.retrieve( + run_id=run_id, + project_id=str(project.id), + start_time=start_time, + selects=["NAME", "STATUS", "TOTAL_TOKENS"], + ) + print(run.name, run.status, run.total_tokens) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.go b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.go new file mode 100644 index 000000000..214afeb85 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.go @@ -0,0 +1,58 @@ +// :snippet-start: runs-retrieve-by-id-after-go +// :codegroup-tab: After +package main + +import ( + "context" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +startTime := time.Date(2026, 6, 1, 12, 0, 0, 0, time.UTC) +projectID := "" +// :remove-start: +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +projectID = sessions.Items[0].ID +found, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{projectID}), + Selects: langsmith.F([]langsmith.RunQueryV2ParamsSelect{ + langsmith.RunQueryV2ParamsSelectID, + langsmith.RunQueryV2ParamsSelectStartTime, + }), + PageSize: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +runID = found.Items[0].ID +startTime = found.Items[0].StartTime +// :remove-end: +run, err := client.Runs.GetV2(ctx, runID, langsmith.RunGetV2Params{ + ProjectID: langsmith.F(projectID), + StartTime: langsmith.F(startTime), +}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +// :remove-start: +_ = run +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.kt b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.kt new file mode 100644 index 000000000..b636332e9 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.kt @@ -0,0 +1,56 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-retrieve-by-id-after-kt +// :codegroup-tab: After +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunRetrieveV2Params +import com.langchain.smith.models.sessions.SessionListParams +// :remove-start: +import com.langchain.smith.models.runs.RunQueryV2Params +// :remove-end: + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-retrieve-by-id-after] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() + +var runId = "" +var startTime = "" +// :remove-start: +val foundRun = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .addSelect(RunQueryV2Params.Select.ID) + .addSelect(RunQueryV2Params.Select.START_TIME) + .pageSize(1L) + .build() +).items().first() +runId = foundRun.id().get() +startTime = foundRun.startTime().get().toString() +// :remove-end: +client.runs().retrieveV2( + runId, + RunRetrieveV2Params.builder() + .projectId(project.id()) + .startTime(OffsetDateTime.parse(startTime)) + .build() +) +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.sh b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.sh new file mode 100644 index 000000000..36e09e7c0 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-retrieve-by-id-after-sh +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +# :remove-start: +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +# :remove-end: + +RUN_ID="" +START_TIME="2025-01-01T12:00:00Z" +# :remove-start: +FOUND=$(curl -s -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "selects": ["ID", "START_TIME"], "page_size": 1}')") +RUN_ID=$(echo "$FOUND" | jq -r '.items[0].id') +START_TIME=$(echo "$FOUND" | jq -r '.items[0].start_time') +[ -n "$RUN_ID" ] && [ "$RUN_ID" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +# :remove-end: + +curl "https://api.smith.langchain.com/v2/runs/$RUN_ID?project_id=$PROJECT_ID&start_time=$START_TIME" \ + -H "x-api-key: $LANGSMITH_API_KEY" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.ts b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.ts new file mode 100644 index 000000000..04be067bf --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-after.ts @@ -0,0 +1,29 @@ +import { Client } from "langsmith"; + +async function findRun(projectId: string) { + const client = new Client(); + for await (const run of client.runs.query({ project_ids: [projectId], selects: ["ID", "START_TIME"] })) { + return run; + } + return null; +} + +// :snippet-start: runs-retrieve-by-id-after-js +// :codegroup-tab: After +import { Client } from "langsmith"; + +const client = new Client(); +const projectPage = await client.projects.list({ name: "default", limit: 1 }); +const project = projectPage.getPaginatedItems()[0]; +let runId = ""; +let startTime = "2026-06-01T12:00:00Z"; +// :remove-start: +const run = await findRun(project.id); +runId = run.id; +startTime = run.start_time; +// :remove-end: +await client.runs.retrieve(runId, { + project_id: project.id, + start_time: startTime, +}); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.go b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.go new file mode 100644 index 000000000..8ca7beb7c --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.go @@ -0,0 +1,46 @@ +// :snippet-start: runs-retrieve-by-id-before-go +// :codegroup-tab: Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +// :remove-start: +func main() { +// :remove-end: +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +// :remove-start: +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +found, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{sessions.Items[0].ID}), + Limit: langsmith.F(int64(1)), +}) +if err != nil { + panic(err.Error()) +} +runID = found.Runs[0].ID +// :remove-end: +run, err := client.Runs.Get(ctx, runID, langsmith.RunGetParams{}) +// :remove-start: +if err != nil { + panic(err.Error()) +} +// :remove-end: +// :remove-start: +_ = run +} + +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.kt b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.kt new file mode 100644 index 000000000..f463c6f50 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.kt @@ -0,0 +1,39 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +//JAVA 21 +//KOTLIN 2.2.0 +//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11 + +// :snippet-start: runs-retrieve-by-id-before-kt +// :codegroup-tab: Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +// :remove-start: +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams +// :remove-end: + +// :remove-start: +fun main() { + if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) { + println("[smithdb-runs-retrieve-by-id-before] Skipping (LANGSMITH_API_KEY is not set).") + return + } + +// :remove-end: +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +var runId = "" +// :remove-start: +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val foundRun = client.runs().query( + RunQueryParams.builder().addSession(project.id()).limit(1L).build() +).items().first() +runId = foundRun.id() +// :remove-end: +client.runs().retrieve(runId) +// :remove-start: +} +// :remove-end: +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.sh b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.sh new file mode 100644 index 000000000..fde1118b4 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail + +# :snippet-start: runs-retrieve-by-id-before-sh +RUN_ID="" +# :remove-start: +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') +[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; } +FOUND=$(curl -s -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "limit": 1}')") +RUN_ID=$(echo "$FOUND" | jq -r '.runs[0].id') +[ -n "$RUN_ID" ] && [ "$RUN_ID" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; } +# :remove-end: + +curl "https://api.smith.langchain.com/api/v1/runs/$RUN_ID" \ + -H "x-api-key: $LANGSMITH_API_KEY" +# :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.ts b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.ts new file mode 100644 index 000000000..32b2323a0 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id-before.ts @@ -0,0 +1,30 @@ +import { Client } from "langsmith"; + +async function findRun(projectId: string) { + const client = new Client(); + for await (const run of client.runs.query({ project_ids: [projectId], selects: ["ID", "START_TIME"] })) { + return run; + } + return null; +} + +async function getProjectId() { + const client = new Client(); + const page = await client.projects.list({ name: "default", limit: 1 }); + const projects = page.getPaginatedItems(); + return projects[0]?.id; +} + +// :snippet-start: runs-retrieve-by-id-before-js +// :codegroup-tab: Before +import { Client } from "langsmith"; + +const client = new Client(); +let runId = ""; +// :remove-start: +const projectId = await getProjectId(); +const run = await findRun(projectId); +runId = run.id; +// :remove-end: +await client.readRun(runId); +// :snippet-end: diff --git a/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id.py b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id.py new file mode 100644 index 000000000..afd9d6b48 --- /dev/null +++ b/src/code-samples/langsmith/smithdb-migration/runs-retrieve-by-id.py @@ -0,0 +1,56 @@ + +import asyncio + +async def find_run(project_id: str): + client = Client() + async for run in client.runs.query(project_ids=[project_id], selects=["ID", "START_TIME"]): + return run + return None + +async def get_project_id(): + from langsmith import Client as AsyncClient + client = AsyncClient() + async for project in client.projects.list(name="default", limit=1): + return project.id + return None + +# :snippet-start: runs-retrieve-by-id-before-py +# :codegroup-tab: Before +from langsmith import Client + +client = Client() +run_id = "" +# :remove-start: +project_id = asyncio.run(get_project_id()) +run_id = asyncio.run(find_run(project_id)).id +# :remove-end: +run = client.read_run(run_id) +# :snippet-end: + +# :snippet-start: runs-retrieve-by-id-after-py +# :codegroup-tab: After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + run_id = "" + start_time="2026-06-01T12:00:00Z" + # :remove-start: + run = await find_run(project.id) + run_id = run.id + start_time = run.start_time + # :remove-end: + run = await client.runs.retrieve( + run_id=run_id, + project_id=str(project.id), + start_time=start_time, + ) + + +asyncio.run(main()) +# :snippet-end: diff --git a/src/code-samples/package-lock.json b/src/code-samples/package-lock.json index 51718e4ae..c71ec7124 100644 --- a/src/code-samples/package-lock.json +++ b/src/code-samples/package-lock.json @@ -23,7 +23,7 @@ "cheerio": "^1.0.0", "deepagents": "^1.10.5", "langchain": "^1.4.5", - "langsmith": "^0.7.0", + "langsmith": "0.7.15", "sqlite3": "^6.0.1", "zod": "^3.23.0" }, @@ -4749,9 +4749,9 @@ } }, "node_modules/langsmith": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.7.3.tgz", - "integrity": "sha512-Gg+IeRGoF1/aStu80aEnIXJCu+N6+4NoV4tAVFS51ZPRBsRa2KG0LkS7K7/ryZ/yES7O9xdqah5QuuWMIeMjQw==", + "version": "0.7.15", + "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.7.15.tgz", + "integrity": "sha512-huRfzLKcREE+ABkqKEriXK8Ax9V+xuV3d3x4PINEGi+hi4qyTvB4Nc2dpLSyfW/Ioj6+6d7T8majjWCe7mXc8A==", "license": "MIT", "peer": true, "dependencies": { diff --git a/src/code-samples/package.json b/src/code-samples/package.json index e08f11ff0..97b57769d 100644 --- a/src/code-samples/package.json +++ b/src/code-samples/package.json @@ -24,7 +24,7 @@ "cheerio": "^1.0.0", "deepagents": "^1.10.5", "langchain": "^1.4.5", - "langsmith": "^0.7.0", + "langsmith": "0.7.15", "sqlite3": "^6.0.1", "zod": "^3.23.0" }, diff --git a/src/langsmith/smithdb-sdk-migration.mdx b/src/langsmith/smithdb-sdk-migration.mdx new file mode 100644 index 000000000..b26f8bf20 --- /dev/null +++ b/src/langsmith/smithdb-sdk-migration.mdx @@ -0,0 +1,26 @@ +--- +title: Migrate to SmithDB-backed SDK methods +description: Migrate your existing LangSmith SDK methods to their SmithDB-backed equivalents for faster agent observability. +noindex: true +--- + +import SmithdbMigrationRunsQuery from '/snippets/langsmith/smithdb-migration/runs-query.mdx'; +import SmithdbMigrationRunsRetrieve from '/snippets/langsmith/smithdb-migration/runs-retrieve.mdx'; + +## Context + +In May 2026, we released [SmithDB](https://www.langchain.com/blog/introducing-smithdb?utm_source=docs), a new observability database built for modern AI agents. Agent traces have grown dramatically in complexity: hundreds of nested spans, multi-modal content, and spans that remain open for hours. General-purpose databases were never designed to handle these patterns at scale. SmithDB addresses this directly, built in Rust on Apache DataFusion and Vortex with purpose-built support for the query patterns that matter most for agent observability: random access, interactive filtering, full-text search, and tree-aware trace reconstruction. + +SmithDB-powered methods are now available to all SDK users. + +## Deployment support + +| Deployment | Status | +|---|---| +| US SaaS | Available. Methods are fully SmithDB-backed. | +| EU and other SaaS regions | Methods are available but not yet backed by SmithDB. | +| Self-hosted | Supported starting with self-hosted version 0.16.0. | + + + + diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-go.mdx new file mode 100644 index 000000000..528f02fdb --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-go.mdx @@ -0,0 +1,24 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +filterStr := `and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))` +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-js.mdx new file mode 100644 index 000000000..745a25c2b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-js.mdx @@ -0,0 +1,16 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + + ' or(neq(status, "error"),' + + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'; +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + filter: filterStr, +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-kt.mdx new file mode 100644 index 000000000..fdec2ec80 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-kt.mdx @@ -0,0 +1,18 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(gt(start_time, \"2023-07-15T12:34:56Z\")," + + " or(neq(status, \"error\")," + + " and(eq(feedback_key, \"Correctness\"), eq(feedback_score, 0.0))))" +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).filter(filterStr).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-py.mdx new file mode 100644 index 000000000..c22d1c454 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-py.mdx @@ -0,0 +1,20 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + filter_str = ( + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + ' or(neq(status, "error"),' + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' + ) + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], filter=filter_str) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-sh.mdx new file mode 100644 index 000000000..974e7b1fd --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-sh.mdx @@ -0,0 +1,11 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +FILTER='and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"project_ids": [$pid], "filter": $f}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-go.mdx new file mode 100644 index 000000000..48adb5dcc --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-go.mdx @@ -0,0 +1,24 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +filterStr := `and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))` +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-js.mdx new file mode 100644 index 000000000..fd5a8cc07 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-js.mdx @@ -0,0 +1,10 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + + ' or(neq(status, "error"),' + + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'; +const runs = client.listRuns({ projectName: "default", filter: filterStr }); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-kt.mdx new file mode 100644 index 000000000..c9636c78d --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-kt.mdx @@ -0,0 +1,18 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(gt(start_time, \"2023-07-15T12:34:56Z\")," + + " or(neq(status, \"error\")," + + " and(eq(feedback_key, \"Correctness\"), eq(feedback_score, 0.0))))" +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).filter(filterStr).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-py.mdx new file mode 100644 index 000000000..e4e5e7a64 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-py.mdx @@ -0,0 +1,11 @@ +```python Before +from langsmith import Client + +client = Client() +filter_str = ( + 'and(gt(start_time, "2023-07-15T12:34:56Z"),' + ' or(neq(status, "error"),' + ' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' +) +runs = client.list_runs(project_name="default", filter=filter_str) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-sh.mdx new file mode 100644 index 000000000..cabb23a20 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-sh.mdx @@ -0,0 +1,11 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +FILTER='and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))' + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"session": [$pid], "filter": $f}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-go.mdx new file mode 100644 index 000000000..dd5fa8a7b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-go.mdx @@ -0,0 +1,25 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runID1 := "" +runID2 := "" +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + IDs: langsmith.F([]string{runID1, runID2}), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-js.mdx new file mode 100644 index 000000000..c15ef9c02 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-js.mdx @@ -0,0 +1,12 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + ids: ["", ""], +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-kt.mdx new file mode 100644 index 000000000..deb6da032 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-kt.mdx @@ -0,0 +1,19 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .addId("") + .addId("") + .build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-py.mdx new file mode 100644 index 000000000..a3cfd7f55 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-py.mdx @@ -0,0 +1,18 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query( + project_ids=[str(project.id)], + ids=["", ""], + ) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-sh.mdx new file mode 100644 index 000000000..42526d97b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-sh.mdx @@ -0,0 +1,12 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +RUN_ID_1="" +RUN_ID_2="" + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg r1 "$RUN_ID_1" --arg r2 "$RUN_ID_2" '{"project_ids": [$pid], "ids": [$r1, $r2]}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-go.mdx new file mode 100644 index 000000000..f98357ed8 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-go.mdx @@ -0,0 +1,25 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runID1 := "" +runID2 := "" +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + ID: langsmith.F([]string{runID1, runID2}), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-js.mdx new file mode 100644 index 000000000..45b3fab27 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-js.mdx @@ -0,0 +1,6 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ id: ["", ""] }); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-kt.mdx new file mode 100644 index 000000000..88e4aa8c2 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-kt.mdx @@ -0,0 +1,21 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +var runId1 = "" +var runId2 = "" +val runs = client.runs().query( + RunQueryParams.builder() + .addSession(project.id()) + .addId(runId1) + .addId(runId2) + .build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-py.mdx new file mode 100644 index 000000000..9c923fbcf --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-py.mdx @@ -0,0 +1,6 @@ +```python Before +from langsmith import Client + +client = Client() +runs = client.list_runs(id=["", ""]) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-sh.mdx new file mode 100644 index 000000000..4a2124d01 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-sh.mdx @@ -0,0 +1,9 @@ +```bash +RUN_ID_1="" +RUN_ID_2="" + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg r1 "$RUN_ID_1" --arg r2 "$RUN_ID_2" '{"id": [$r1, $r2]}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-go.mdx new file mode 100644 index 000000000..6a5390a8d --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-go.mdx @@ -0,0 +1,23 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + HasError: langsmith.F(true), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-js.mdx new file mode 100644 index 000000000..5515bc38a --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-js.mdx @@ -0,0 +1,12 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + has_error: true, +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-kt.mdx new file mode 100644 index 000000000..f88ac30c7 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-kt.mdx @@ -0,0 +1,15 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).hasError(true).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-py.mdx new file mode 100644 index 000000000..e40bccc68 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-py.mdx @@ -0,0 +1,15 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], has_error=True) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-sh.mdx new file mode 100644 index 000000000..f39f8e145 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "has_error": true}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-go.mdx new file mode 100644 index 000000000..419cf773f --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-go.mdx @@ -0,0 +1,23 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Error: langsmith.F(true), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-js.mdx new file mode 100644 index 000000000..604af2c51 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-js.mdx @@ -0,0 +1,6 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ projectName: "default", error: true }); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-kt.mdx new file mode 100644 index 000000000..1a77683b1 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-kt.mdx @@ -0,0 +1,15 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).error(true).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-py.mdx new file mode 100644 index 000000000..1aa0e2d8b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-py.mdx @@ -0,0 +1,6 @@ +```python Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default", error=True) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-sh.mdx new file mode 100644 index 000000000..56af4d291 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "error": true}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-go.mdx new file mode 100644 index 000000000..3e50b40dd --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-go.mdx @@ -0,0 +1,24 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +filterStr := `and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))` +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-js.mdx new file mode 100644 index 000000000..3184f06fd --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-js.mdx @@ -0,0 +1,13 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'; +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + filter: filterStr, +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-kt.mdx new file mode 100644 index 000000000..7a453614c --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-kt.mdx @@ -0,0 +1,16 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(eq(metadata_key, \"user_id\"), eq(metadata_value, \"u_123\"))" +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).filter(filterStr).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-py.mdx new file mode 100644 index 000000000..5a61bdd3b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-py.mdx @@ -0,0 +1,16 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + filter_str = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], filter=filter_str) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-sh.mdx new file mode 100644 index 000000000..39898e4b2 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-sh.mdx @@ -0,0 +1,11 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +FILTER='and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"project_ids": [$pid], "filter": $f}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-go.mdx new file mode 100644 index 000000000..e6fd744b1 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-go.mdx @@ -0,0 +1,24 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +filterStr := `and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))` +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Filter: langsmith.F(filterStr), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-js.mdx new file mode 100644 index 000000000..6e02587f0 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-js.mdx @@ -0,0 +1,7 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const filterStr = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'; +const runs = client.listRuns({ projectName: "default", filter: filterStr }); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-kt.mdx new file mode 100644 index 000000000..962e79817 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-kt.mdx @@ -0,0 +1,16 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val filterStr = "and(eq(metadata_key, \"user_id\"), eq(metadata_value, \"u_123\"))" +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).filter(filterStr).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-py.mdx new file mode 100644 index 000000000..a1f1b5c95 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-py.mdx @@ -0,0 +1,7 @@ +```python Before +from langsmith import Client + +client = Client() +filter_str = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' +runs = client.list_runs(project_name="default", filter=filter_str) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-sh.mdx new file mode 100644 index 000000000..e68c8e0ec --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-sh.mdx @@ -0,0 +1,11 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +FILTER='and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))' + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"session": [$pid], "filter": $f}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-go.mdx new file mode 100644 index 000000000..afa9d395d --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-go.mdx @@ -0,0 +1,23 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + IsRoot: langsmith.F(true), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-js.mdx new file mode 100644 index 000000000..162302d9c --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-js.mdx @@ -0,0 +1,12 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + is_root: true, +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-kt.mdx new file mode 100644 index 000000000..f4e1bc322 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-kt.mdx @@ -0,0 +1,15 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).isRoot(true).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-py.mdx new file mode 100644 index 000000000..ca4a1b41c --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-py.mdx @@ -0,0 +1,15 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)], is_root=True) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-sh.mdx new file mode 100644 index 000000000..83790dcc8 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "is_root": true}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-go.mdx new file mode 100644 index 000000000..f1f9bf664 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-go.mdx @@ -0,0 +1,23 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + IsRoot: langsmith.F(true), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-js.mdx new file mode 100644 index 000000000..d551d6331 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-js.mdx @@ -0,0 +1,6 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ projectName: "default", isRoot: true }); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-kt.mdx new file mode 100644 index 000000000..91133dc3b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-kt.mdx @@ -0,0 +1,15 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).isRoot(true).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-py.mdx new file mode 100644 index 000000000..599c76ee3 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-py.mdx @@ -0,0 +1,6 @@ +```python Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default", is_root=True) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-sh.mdx new file mode 100644 index 000000000..3c2926db2 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "is_root": true}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-go.mdx new file mode 100644 index 000000000..99a088fe6 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-go.mdx @@ -0,0 +1,25 @@ +```go After +package main + +import ( + "context" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + MinStartTime: langsmith.F(time.Now().Add(-24 * time.Hour)), + RunType: langsmith.F(langsmith.RunQueryV2ParamsRunTypeLlm), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-js.mdx new file mode 100644 index 000000000..fc617259d --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-js.mdx @@ -0,0 +1,14 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000); +const runs = client.runs.query({ + project_ids: [project.id], + min_start_time: oneDayAgo.toISOString(), + run_type: "LLM", +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-kt.mdx new file mode 100644 index 000000000..8e2eec766 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-kt.mdx @@ -0,0 +1,21 @@ +```kotlin After +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .minStartTime(OffsetDateTime.now().minusDays(1)) + .runType(RunQueryV2Params.RunType.LLM) + .build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-py.mdx new file mode 100644 index 000000000..f7bdd25f3 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-py.mdx @@ -0,0 +1,20 @@ +```python After +import asyncio +from datetime import datetime, timedelta + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query( + project_ids=[str(project.id)], + min_start_time=datetime.now() - timedelta(days=1), + run_type="LLM", + ) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-sh.mdx new file mode 100644 index 000000000..d1fa117c3 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "run_type": "LLM", "min_start_time": "2025-01-01T00:00:00Z"}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-go.mdx new file mode 100644 index 000000000..e9a5bff15 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-go.mdx @@ -0,0 +1,25 @@ +```go Before +package main + +import ( + "context" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + StartTime: langsmith.F(time.Now().Add(-24 * time.Hour)), + RunType: langsmith.F(langsmith.RunTypeEnumLlm), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-js.mdx new file mode 100644 index 000000000..750d69d4a --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-js.mdx @@ -0,0 +1,10 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ + projectName: "default", + startTime: new Date(Date.now() - 24 * 60 * 60 * 1000), + runType: "llm", +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-kt.mdx new file mode 100644 index 000000000..c759dd15a --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-kt.mdx @@ -0,0 +1,22 @@ +```kotlin Before +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.runs.RunTypeEnum +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder() + .addSession(project.id()) + .startTime(OffsetDateTime.now().minusDays(1)) + .runType(RunTypeEnum.LLM) + .build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-py.mdx new file mode 100644 index 000000000..172393b94 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-py.mdx @@ -0,0 +1,12 @@ +```python Before +from datetime import datetime, timedelta + +from langsmith import Client + +client = Client() +runs = client.list_runs( + project_name="default", + start_time=datetime.now() - timedelta(days=1), + run_type="llm", +) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-sh.mdx new file mode 100644 index 000000000..957edc90f --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "run_type": "llm", "start_time": "2025-01-01T00:00:00Z"}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-go.mdx new file mode 100644 index 000000000..bda6172ef --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-go.mdx @@ -0,0 +1,22 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-js.mdx new file mode 100644 index 000000000..e7779cd1c --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-js.mdx @@ -0,0 +1,9 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ project_ids: [project.id] }); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-kt.mdx new file mode 100644 index 000000000..4feb1596b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-kt.mdx @@ -0,0 +1,15 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-py.mdx new file mode 100644 index 000000000..c3280aaa8 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-py.mdx @@ -0,0 +1,15 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query(project_ids=[str(project.id)]) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-sh.mdx new file mode 100644 index 000000000..6b244916e --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-after-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid]}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-go.mdx new file mode 100644 index 000000000..d3e97fdc3 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-go.mdx @@ -0,0 +1,22 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-js.mdx new file mode 100644 index 000000000..4deedcab1 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-js.mdx @@ -0,0 +1,6 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ projectName: "default" }); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-kt.mdx new file mode 100644 index 000000000..aba93fde4 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-kt.mdx @@ -0,0 +1,15 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-py.mdx new file mode 100644 index 000000000..82c548707 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-py.mdx @@ -0,0 +1,6 @@ +```python Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default") +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-sh.mdx new file mode 100644 index 000000000..0f5308554 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-list-all-before-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid]}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-go.mdx new file mode 100644 index 000000000..760f2d456 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-go.mdx @@ -0,0 +1,29 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs := []langsmith.Run{} +iter := client.Runs.QueryV2AutoPaging(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), +}) +for iter.Next() { + runs = append(runs, iter.Current()) + if len(runs) >= 150 { + break + } +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-js.mdx new file mode 100644 index 000000000..c94f818a1 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-js.mdx @@ -0,0 +1,15 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs: unknown[] = []; +for await (const run of client.runs.query({ + project_ids: [project.id], +})) { + runs.push(run); + if (runs.length >= 150) break; +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-kt.mdx new file mode 100644 index 000000000..961bb1f0c --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-kt.mdx @@ -0,0 +1,19 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = mutableListOf() +for (run in client.runs().queryV2( + RunQueryV2Params.builder().addProjectId(project.id()).build() +).autoPager()) { + runs.add(run) + if (runs.size >= 150) break +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-py.mdx new file mode 100644 index 000000000..8cf68014a --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-py.mdx @@ -0,0 +1,21 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = [] + async for run in client.runs.query( + project_ids=[str(project.id)], + ): + runs.append(run) + if len(runs) >= 150: + break + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-sh.mdx new file mode 100644 index 000000000..e87b4f657 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-after-sh.mdx @@ -0,0 +1,20 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +# Fetch pages, passing the cursor from each response's next_cursor field +# to fetch the next page, until 150 runs are collected or pages run out. +TOTAL=0 +CURSOR="" +while :; do + BODY=$(jq -n --arg pid "$PROJECT_ID" --arg cursor "$CURSOR" \ + 'if $cursor == "" then {"project_ids": [$pid]} else {"project_ids": [$pid], "cursor": $cursor} end') + RESPONSE=$(curl -s -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$BODY") + TOTAL=$((TOTAL + $(echo "$RESPONSE" | jq '.items | length'))) + CURSOR=$(echo "$RESPONSE" | jq -r '.next_cursor // empty') + [ "$TOTAL" -lt 150 ] && [ -n "$CURSOR" ] || break +done +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-go.mdx new file mode 100644 index 000000000..a665946cc --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-go.mdx @@ -0,0 +1,29 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs := []langsmith.RunSchema{} +iter := client.Runs.QueryAutoPaging(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), +}) +for iter.Next() { + runs = append(runs, iter.Current()) + if len(runs) >= 150 { + break + } +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-js.mdx new file mode 100644 index 000000000..b7f6ab179 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-js.mdx @@ -0,0 +1,10 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs: unknown[] = []; +for await (const run of client.listRuns({ projectName: "default" })) { + runs.push(run); + if (runs.length >= 150) break; +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-kt.mdx new file mode 100644 index 000000000..44883f63d --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-kt.mdx @@ -0,0 +1,19 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = mutableListOf() +for (run in client.runs().query( + RunQueryParams.builder().addSession(project.id()).build() +).autoPager()) { + runs.add(run) + if (runs.size >= 150) break +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-py.mdx new file mode 100644 index 000000000..6ff276dae --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-py.mdx @@ -0,0 +1,6 @@ +```python Before +from langsmith import Client + +client = Client() +runs = client.list_runs(project_name="default", limit=150) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-sh.mdx new file mode 100644 index 000000000..016d2d7e8 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-pagination-before-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "limit": 150}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-go.mdx new file mode 100644 index 000000000..660147109 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-go.mdx @@ -0,0 +1,25 @@ +```go After +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Filter: langsmith.F(`eq(name, "RetrieveDocs")`), + TraceFilter: langsmith.F(`and(eq(feedback_key, "user_score"), eq(feedback_score, 1))`), + TreeFilter: langsmith.F(`eq(name, "ExpandQuery")`), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-js.mdx new file mode 100644 index 000000000..4d954545b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-js.mdx @@ -0,0 +1,14 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +const runs = client.runs.query({ + project_ids: [project.id], + filter: 'eq(name, "RetrieveDocs")', + trace_filter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + tree_filter: 'eq(name, "ExpandQuery")', +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-kt.mdx new file mode 100644 index 000000000..8268828d5 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-kt.mdx @@ -0,0 +1,20 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .filter("eq(name, \"RetrieveDocs\")") + .traceFilter("and(eq(feedback_key, \"user_score\"), eq(feedback_score, 1))") + .treeFilter("eq(name, \"ExpandQuery\")") + .build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-py.mdx new file mode 100644 index 000000000..3a55fa111 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-py.mdx @@ -0,0 +1,20 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + runs = client.runs.query( + project_ids=[str(project.id)], + filter='eq(name, "RetrieveDocs")', + trace_filter='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + tree_filter='eq(name, "ExpandQuery")', + ) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-sh.mdx new file mode 100644 index 000000000..25e49888b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-sh.mdx @@ -0,0 +1,18 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +FILTER='eq(name, "RetrieveDocs")' +TRACE_FILTER='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))' +TREE_FILTER='eq(name, "ExpandQuery")' + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n \ + --arg pid "$PROJECT_ID" \ + --arg f "$FILTER" \ + --arg tf "$TRACE_FILTER" \ + --arg treef "$TREE_FILTER" \ + '{"project_ids": [$pid], "filter": $f, "trace_filter": $tf, "tree_filter": $treef}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-go.mdx new file mode 100644 index 000000000..40aad42d1 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-go.mdx @@ -0,0 +1,25 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), + Filter: langsmith.F(`eq(name, "RetrieveDocs")`), + TraceFilter: langsmith.F(`and(eq(feedback_key, "user_score"), eq(feedback_score, 1))`), + TreeFilter: langsmith.F(`eq(name, "ExpandQuery")`), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-js.mdx new file mode 100644 index 000000000..1c110a2b7 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-js.mdx @@ -0,0 +1,11 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +const runs = client.listRuns({ + projectName: "default", + filter: 'eq(name, "RetrieveDocs")', + traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + treeFilter: 'eq(name, "ExpandQuery")', +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-kt.mdx new file mode 100644 index 000000000..a6837f0cb --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-kt.mdx @@ -0,0 +1,20 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +val runs = client.runs().query( + RunQueryParams.builder() + .addSession(project.id()) + .filter("eq(name, \"RetrieveDocs\")") + .traceFilter("and(eq(feedback_key, \"user_score\"), eq(feedback_score, 1))") + .treeFilter("eq(name, \"ExpandQuery\")") + .build() +).items() +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-py.mdx new file mode 100644 index 000000000..358859729 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-py.mdx @@ -0,0 +1,11 @@ +```python Before +from langsmith import Client + +client = Client() +runs = client.list_runs( + project_name="default", + filter='eq(name, "RetrieveDocs")', + trace_filter='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))', + tree_filter='eq(name, "ExpandQuery")', +) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-sh.mdx new file mode 100644 index 000000000..efb5977ef --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-sh.mdx @@ -0,0 +1,18 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +FILTER='eq(name, "RetrieveDocs")' +TRACE_FILTER='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))' +TREE_FILTER='eq(name, "ExpandQuery")' + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n \ + --arg pid "$PROJECT_ID" \ + --arg f "$FILTER" \ + --arg tf "$TRACE_FILTER" \ + --arg treef "$TREE_FILTER" \ + '{"session": [$pid], "filter": $f, "trace_filter": $tf, "tree_filter": $treef}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-go.mdx new file mode 100644 index 000000000..b019c630e --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-go.mdx @@ -0,0 +1,36 @@ +```go After +package main + +import ( + "context" + "fmt" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +// must explicitly list every field needed; default returns only id +runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{ + ProjectIDs: langsmith.F([]string{project.ID}), + Selects: langsmith.F([]langsmith.RunQueryV2ParamsSelect{ + langsmith.RunQueryV2ParamsSelectID, + langsmith.RunQueryV2ParamsSelectName, + langsmith.RunQueryV2ParamsSelectRunType, + langsmith.RunQueryV2ParamsSelectStatus, + langsmith.RunQueryV2ParamsSelectStartTime, + langsmith.RunQueryV2ParamsSelectInputs, + langsmith.RunQueryV2ParamsSelectError, + }), +}) +for _, run := range runs.Items { + fmt.Println(run.ID, run.Name, run.RunType, run.Status, run.StartTime, run.Inputs, run.Error) +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-js.mdx new file mode 100644 index 000000000..60dda9222 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-js.mdx @@ -0,0 +1,15 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const project = await client.projects + .list({ name: "default", limit: 1 }) + .then((page) => page.getPaginatedItems()[0]); +// must explicitly list every field needed; default returns only id +for await (const run of client.runs.query({ + project_ids: [project.id], + selects: ["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"], +})) { + console.log(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error); +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-kt.mdx new file mode 100644 index 000000000..0245f5531 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-kt.mdx @@ -0,0 +1,28 @@ +```kotlin After +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +// must explicitly list every field needed; default returns only id +val runs = client.runs().queryV2( + RunQueryV2Params.builder() + .addProjectId(project.id()) + .addSelect(RunQueryV2Params.Select.ID) + .addSelect(RunQueryV2Params.Select.NAME) + .addSelect(RunQueryV2Params.Select.RUN_TYPE) + .addSelect(RunQueryV2Params.Select.STATUS) + .addSelect(RunQueryV2Params.Select.START_TIME) + .addSelect(RunQueryV2Params.Select.INPUTS) + .addSelect(RunQueryV2Params.Select.ERROR) + .build() +).items() +for (run in runs) { + println("${run.id()} ${run.name()} ${run.runType()} ${run.status()} ${run.startTime()} ${run.inputs()} ${run.error()}") +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-py.mdx new file mode 100644 index 000000000..0fca9d0f6 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-py.mdx @@ -0,0 +1,20 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + # must explicitly list every field needed; default returns only id + async for run in client.runs.query( + project_ids=[str(project.id)], + selects=["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"], + ): + print(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-sh.mdx new file mode 100644 index 000000000..ae0ec6535 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/v2/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "selects": ["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"]}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-go.mdx new file mode 100644 index 000000000..311dad686 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-go.mdx @@ -0,0 +1,27 @@ +```go Before +package main + +import ( + "context" + "fmt" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{ + Name: langsmith.F("default"), + Limit: langsmith.F(int64(1)), +}) +project := sessions.Items[0] + +// returns a default set of fields; no explicit selection needed +runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{ + Session: langsmith.F([]string{project.ID}), +}) +for _, run := range runs.Runs { + fmt.Println(run.ID, run.Name, run.RunType, run.Status, run.StartTime, run.Inputs, run.Error) +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-js.mdx new file mode 100644 index 000000000..db34e7f1a --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-js.mdx @@ -0,0 +1,10 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +// returns a default set of fields; no explicit selection needed +const runs = client.listRuns({ projectName: "default" }); +for await (const run of runs) { + console.log(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error); +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-kt.mdx new file mode 100644 index 000000000..8eefccd77 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-kt.mdx @@ -0,0 +1,19 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunQueryParams +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() +// returns a default set of fields; no explicit selection needed +val runs = client.runs().query( + RunQueryParams.builder().addSession(project.id()).build() +).items() +for (run in runs) { + println("${run.id()} ${run.name()} ${run.runType()} ${run.status()} ${run.startTime()} ${run.inputs()} ${run.error()}") +} +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-py.mdx new file mode 100644 index 000000000..0045632ed --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-py.mdx @@ -0,0 +1,9 @@ +```python Before +from langsmith import Client + +client = Client() +# returns a default set of fields; no explicit selection needed +runs = client.list_runs(project_name="default") +for run in runs: + print(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-sh.mdx new file mode 100644 index 000000000..0f5308554 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-sh.mdx @@ -0,0 +1,9 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \ + -H "x-api-key: $LANGSMITH_API_KEY" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid]}')" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-go.mdx new file mode 100644 index 000000000..dd8c9d4c3 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-go.mdx @@ -0,0 +1,28 @@ +```go After +package main + +import ( + "context" + "fmt" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +startTime := time.Date(2026, 6, 1, 12, 0, 0, 0, time.UTC) +projectID := "" +run, err := client.Runs.GetV2(ctx, runID, langsmith.RunGetV2Params{ + ProjectID: langsmith.F(projectID), + StartTime: langsmith.F(startTime), + Selects: langsmith.F([]langsmith.RunGetV2ParamsSelect{ + langsmith.RunGetV2ParamsSelectName, + langsmith.RunGetV2ParamsSelectStatus, + langsmith.RunGetV2ParamsSelectTotalTokens, + }), +}) +fmt.Println(run.Name, run.Status, run.TotalTokens) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-js.mdx new file mode 100644 index 000000000..8c675d3b3 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-js.mdx @@ -0,0 +1,14 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +let runId = ""; +let startTime = "2026-06-01T12:00:00Z"; +let projectId = ""; +const retrievedRun = await client.runs.retrieve(runId, { + project_id: projectId, + start_time: startTime, + selects: ["NAME", "STATUS", "TOTAL_TOKENS"], +}); +console.log(retrievedRun.name, retrievedRun.status, retrievedRun.total_tokens); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-kt.mdx new file mode 100644 index 000000000..1c192a66b --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-kt.mdx @@ -0,0 +1,28 @@ +```kotlin After +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunRetrieveV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() + +var runId = "" +var startTime = "" +val run = client.runs().retrieveV2( + runId, + RunRetrieveV2Params.builder() + .projectId(project.id()) + .startTime(OffsetDateTime.parse(startTime)) + .addSelect(RunRetrieveV2Params.Select.NAME) + .addSelect(RunRetrieveV2Params.Select.STATUS) + .addSelect(RunRetrieveV2Params.Select.TOTAL_TOKENS) + .build() +) +println("${run.name()} ${run.status()} ${run.totalTokens()}") +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-py.mdx new file mode 100644 index 000000000..3b1b71d6c --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-py.mdx @@ -0,0 +1,23 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + run_id = "" + start_time = "2026-06-01T12:00:00Z" + run = await client.runs.retrieve( + run_id=run_id, + project_id=str(project.id), + start_time=start_time, + selects=["NAME", "STATUS", "TOTAL_TOKENS"], + ) + print(run.name, run.status, run.total_tokens) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-sh.mdx new file mode 100644 index 000000000..83cff86db --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-sh.mdx @@ -0,0 +1,10 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +RUN_ID="" +START_TIME="2026-06-01T12:00:00Z" + +curl "https://api.smith.langchain.com/v2/runs/$RUN_ID?project_id=$PROJECT_ID&start_time=$START_TIME&selects=NAME&selects=STATUS&selects=TOTAL_TOKENS" \ + -H "x-api-key: $LANGSMITH_API_KEY" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-go.mdx new file mode 100644 index 000000000..a50beeb9f --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-go.mdx @@ -0,0 +1,17 @@ +```go Before +package main + +import ( + "context" + "fmt" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +run, err := client.Runs.Get(ctx, runID, langsmith.RunGetParams{}) +fmt.Println(run.Name, run.Status, run.TotalTokens) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-js.mdx new file mode 100644 index 000000000..28f599910 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-js.mdx @@ -0,0 +1,8 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +let runId = ""; +const retrievedRun = await client.readRun(runId); +console.log(retrievedRun.name, retrievedRun.status, retrievedRun.total_tokens); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-kt.mdx new file mode 100644 index 000000000..7b858fb2a --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-kt.mdx @@ -0,0 +1,10 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +var runId = "" +val run = client.runs().retrieve(runId) +println("${run.name()} ${run.status()} ${run.totalTokens()}") +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-py.mdx new file mode 100644 index 000000000..0c608e686 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-py.mdx @@ -0,0 +1,8 @@ +```python Before +from langsmith import Client + +client = Client() +run_id = "" +run = client.read_run(run_id=run_id) +print(run.name, run.status, run.total_tokens) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-sh.mdx new file mode 100644 index 000000000..2615432e9 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-sh.mdx @@ -0,0 +1,6 @@ +```bash +RUN_ID="" + +curl "https://api.smith.langchain.com/api/v1/runs/$RUN_ID" \ + -H "x-api-key: $LANGSMITH_API_KEY" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-go.mdx new file mode 100644 index 000000000..1d10db68e --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-go.mdx @@ -0,0 +1,21 @@ +```go After +package main + +import ( + "context" + "time" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +startTime := time.Date(2026, 6, 1, 12, 0, 0, 0, time.UTC) +projectID := "" +run, err := client.Runs.GetV2(ctx, runID, langsmith.RunGetV2Params{ + ProjectID: langsmith.F(projectID), + StartTime: langsmith.F(startTime), +}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-js.mdx new file mode 100644 index 000000000..13c26490e --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-js.mdx @@ -0,0 +1,13 @@ +```ts After +import { Client } from "langsmith"; + +const client = new Client(); +const projectPage = await client.projects.list({ name: "default", limit: 1 }); +const project = projectPage.getPaginatedItems()[0]; +let runId = ""; +let startTime = "2026-06-01T12:00:00Z"; +await client.runs.retrieve(runId, { + project_id: project.id, + start_time: startTime, +}); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-kt.mdx new file mode 100644 index 000000000..92f3d4f3c --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-kt.mdx @@ -0,0 +1,24 @@ +```kotlin After +import java.time.OffsetDateTime + +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient +import com.langchain.smith.models.runs.RunRetrieveV2Params +import com.langchain.smith.models.sessions.SessionListParams + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +val project = client.sessions().list( + SessionListParams.builder().name("default").limit(1L).build() +).items().first() + +var runId = "" +var startTime = "" +client.runs().retrieveV2( + runId, + RunRetrieveV2Params.builder() + .projectId(project.id()) + .startTime(OffsetDateTime.parse(startTime)) + .build() +) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-py.mdx new file mode 100644 index 000000000..7f80773d2 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-py.mdx @@ -0,0 +1,21 @@ +```python After +import asyncio + +from langsmith import Client + + +async def main(): + client = Client() + async for project in client.projects.list(name="default", limit=1): + break + run_id = "" + start_time="2026-06-01T12:00:00Z" + run = await client.runs.retrieve( + run_id=run_id, + project_id=str(project.id), + start_time=start_time, + ) + + +asyncio.run(main()) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-sh.mdx new file mode 100644 index 000000000..9b5e7c6fb --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-sh.mdx @@ -0,0 +1,10 @@ +```bash +PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \ + -H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id') + +RUN_ID="" +START_TIME="2025-01-01T12:00:00Z" + +curl "https://api.smith.langchain.com/v2/runs/$RUN_ID?project_id=$PROJECT_ID&start_time=$START_TIME" \ + -H "x-api-key: $LANGSMITH_API_KEY" +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-go.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-go.mdx new file mode 100644 index 000000000..c5b1b3824 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-go.mdx @@ -0,0 +1,15 @@ +```go Before +package main + +import ( + "context" + + "github.com/langchain-ai/langsmith-go" +) + +ctx := context.Background() +client := langsmith.NewClient() + +runID := "" +run, err := client.Runs.Get(ctx, runID, langsmith.RunGetParams{}) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-js.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-js.mdx new file mode 100644 index 000000000..31d2cb270 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-js.mdx @@ -0,0 +1,7 @@ +```ts Before +import { Client } from "langsmith"; + +const client = new Client(); +let runId = ""; +await client.readRun(runId); +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-kt.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-kt.mdx new file mode 100644 index 000000000..d52168923 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-kt.mdx @@ -0,0 +1,9 @@ +```kotlin Before +import com.langchain.smith.client.LangsmithClient +import com.langchain.smith.client.okhttp.LangsmithOkHttpClient + +val client: LangsmithClient = LangsmithOkHttpClient.fromEnv() + +var runId = "" +client.runs().retrieve(runId) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-py.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-py.mdx new file mode 100644 index 000000000..c98928ed4 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-py.mdx @@ -0,0 +1,7 @@ +```python Before +from langsmith import Client + +client = Client() +run_id = "" +run = client.read_run(run_id) +``` diff --git a/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-sh.mdx b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-sh.mdx new file mode 100644 index 000000000..2615432e9 --- /dev/null +++ b/src/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-sh.mdx @@ -0,0 +1,6 @@ +```bash +RUN_ID="" + +curl "https://api.smith.langchain.com/api/v1/runs/$RUN_ID" \ + -H "x-api-key: $LANGSMITH_API_KEY" +``` diff --git a/src/snippets/langsmith/smithdb-migration/runs-query.mdx b/src/snippets/langsmith/smithdb-migration/runs-query.mdx new file mode 100644 index 000000000..a2729c12b --- /dev/null +++ b/src/snippets/langsmith/smithdb-migration/runs-query.mdx @@ -0,0 +1,1313 @@ +import SmithdbRunsQueryListAllBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-list-all-before-py.mdx'; +import SmithdbRunsQueryListAllAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-list-all-after-py.mdx'; +import SmithdbRunsQueryListAllBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-list-all-before-js.mdx'; +import SmithdbRunsQueryListAllAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-list-all-after-js.mdx'; +import SmithdbRunsQueryListAllBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-list-all-before-go.mdx'; +import SmithdbRunsQueryListAllAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-list-all-after-go.mdx'; +import SmithdbRunsQuerySelectingFieldsBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-py.mdx'; +import SmithdbRunsQuerySelectingFieldsAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-py.mdx'; +import SmithdbRunsQuerySelectingFieldsBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-js.mdx'; +import SmithdbRunsQuerySelectingFieldsAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-js.mdx'; +import SmithdbRunsQuerySelectingFieldsBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-go.mdx'; +import SmithdbRunsQuerySelectingFieldsAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-go.mdx'; +import SmithdbRunsQueryFilterTimeRangeBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-py.mdx'; +import SmithdbRunsQueryFilterTimeRangeAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-py.mdx'; +import SmithdbRunsQueryFilterTimeRangeBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-js.mdx'; +import SmithdbRunsQueryFilterTimeRangeAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-js.mdx'; +import SmithdbRunsQueryFilterTimeRangeBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-go.mdx'; +import SmithdbRunsQueryFilterTimeRangeAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-go.mdx'; +import SmithdbRunsQueryFilterRootBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-py.mdx'; +import SmithdbRunsQueryFilterRootAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-py.mdx'; +import SmithdbRunsQueryFilterRootBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-js.mdx'; +import SmithdbRunsQueryFilterRootAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-js.mdx'; +import SmithdbRunsQueryFilterRootBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-go.mdx'; +import SmithdbRunsQueryFilterRootAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-go.mdx'; +import SmithdbRunsQueryFetchByIdBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-py.mdx'; +import SmithdbRunsQueryFetchByIdAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-py.mdx'; +import SmithdbRunsQueryFetchByIdBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-js.mdx'; +import SmithdbRunsQueryFetchByIdAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-js.mdx'; +import SmithdbRunsQueryFetchByIdBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-go.mdx'; +import SmithdbRunsQueryFetchByIdAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-go.mdx'; +import SmithdbRunsQueryPaginationBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-pagination-before-py.mdx'; +import SmithdbRunsQueryPaginationAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-pagination-after-py.mdx'; +import SmithdbRunsQueryPaginationBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-pagination-before-js.mdx'; +import SmithdbRunsQueryPaginationAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-pagination-after-js.mdx'; +import SmithdbRunsQueryPaginationBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-pagination-before-go.mdx'; +import SmithdbRunsQueryPaginationAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-pagination-after-go.mdx'; +import SmithdbRunsQueryFilterErrorsBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-py.mdx'; +import SmithdbRunsQueryFilterErrorsAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-py.mdx'; +import SmithdbRunsQueryFilterErrorsBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-js.mdx'; +import SmithdbRunsQueryFilterErrorsAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-js.mdx'; +import SmithdbRunsQueryFilterErrorsBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-go.mdx'; +import SmithdbRunsQueryFilterErrorsAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-go.mdx'; +import SmithdbRunsQueryFilterMetadataBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-py.mdx'; +import SmithdbRunsQueryFilterMetadataAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-py.mdx'; +import SmithdbRunsQueryFilterMetadataBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-js.mdx'; +import SmithdbRunsQueryFilterMetadataAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-js.mdx'; +import SmithdbRunsQueryFilterMetadataBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-go.mdx'; +import SmithdbRunsQueryFilterMetadataAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-go.mdx'; +import SmithdbRunsQueryBooleanFiltersBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-py.mdx'; +import SmithdbRunsQueryBooleanFiltersAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-py.mdx'; +import SmithdbRunsQueryBooleanFiltersBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-js.mdx'; +import SmithdbRunsQueryBooleanFiltersAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-js.mdx'; +import SmithdbRunsQueryBooleanFiltersBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-go.mdx'; +import SmithdbRunsQueryBooleanFiltersAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-go.mdx'; +import SmithdbRunsQueryScopedFiltersBeforePy from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-py.mdx'; +import SmithdbRunsQueryScopedFiltersAfterPy from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-py.mdx'; +import SmithdbRunsQueryScopedFiltersBeforeJs from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-js.mdx'; +import SmithdbRunsQueryScopedFiltersAfterJs from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-js.mdx'; +import SmithdbRunsQueryScopedFiltersBeforeGo from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-go.mdx'; +import SmithdbRunsQueryScopedFiltersAfterGo from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-go.mdx'; +import SmithdbRunsQueryListAllBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-list-all-before-kt.mdx'; +import SmithdbRunsQueryListAllAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-list-all-after-kt.mdx'; +import SmithdbRunsQuerySelectingFieldsBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-kt.mdx'; +import SmithdbRunsQuerySelectingFieldsAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-kt.mdx'; +import SmithdbRunsQueryFilterTimeRangeBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-kt.mdx'; +import SmithdbRunsQueryFilterTimeRangeAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-kt.mdx'; +import SmithdbRunsQueryFilterRootBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-kt.mdx'; +import SmithdbRunsQueryFilterRootAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-kt.mdx'; +import SmithdbRunsQueryFetchByIdBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-kt.mdx'; +import SmithdbRunsQueryFetchByIdAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-kt.mdx'; +import SmithdbRunsQueryPaginationBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-pagination-before-kt.mdx'; +import SmithdbRunsQueryPaginationAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-pagination-after-kt.mdx'; +import SmithdbRunsQueryFilterErrorsBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-kt.mdx'; +import SmithdbRunsQueryFilterErrorsAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-kt.mdx'; +import SmithdbRunsQueryFilterMetadataBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-kt.mdx'; +import SmithdbRunsQueryFilterMetadataAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-kt.mdx'; +import SmithdbRunsQueryBooleanFiltersBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-kt.mdx'; +import SmithdbRunsQueryBooleanFiltersAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-kt.mdx'; +import SmithdbRunsQueryScopedFiltersBeforeKt from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-kt.mdx'; +import SmithdbRunsQueryScopedFiltersAfterKt from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-kt.mdx'; +import SmithdbRunsQueryListAllBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-list-all-before-sh.mdx'; +import SmithdbRunsQueryListAllAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-list-all-after-sh.mdx'; +import SmithdbRunsQuerySelectingFieldsBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-before-sh.mdx'; +import SmithdbRunsQuerySelectingFieldsAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-selecting-fields-after-sh.mdx'; +import SmithdbRunsQueryFilterTimeRangeBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-before-sh.mdx'; +import SmithdbRunsQueryFilterTimeRangeAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-time-range-after-sh.mdx'; +import SmithdbRunsQueryFilterRootBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-before-sh.mdx'; +import SmithdbRunsQueryFilterRootAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-root-after-sh.mdx'; +import SmithdbRunsQueryFetchByIdBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-before-sh.mdx'; +import SmithdbRunsQueryFetchByIdAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-fetch-by-id-after-sh.mdx'; +import SmithdbRunsQueryPaginationBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-pagination-before-sh.mdx'; +import SmithdbRunsQueryPaginationAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-pagination-after-sh.mdx'; +import SmithdbRunsQueryFilterErrorsBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-before-sh.mdx'; +import SmithdbRunsQueryFilterErrorsAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-errors-after-sh.mdx'; +import SmithdbRunsQueryFilterMetadataBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-before-sh.mdx'; +import SmithdbRunsQueryFilterMetadataAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-filter-metadata-after-sh.mdx'; +import SmithdbRunsQueryBooleanFiltersBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-before-sh.mdx'; +import SmithdbRunsQueryBooleanFiltersAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-boolean-filters-after-sh.mdx'; +import SmithdbRunsQueryScopedFiltersBeforeSh from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-before-sh.mdx'; +import SmithdbRunsQueryScopedFiltersAfterSh from '/snippets/code-samples/smithdb-migration/runs-query-scoped-filters-after-sh.mdx'; + +## Runs: query + +Query runs from a project with optional filtering and field projection. Returns a paginated result set. + +### Main changes + +#### Method name + + + + | Before | After | + |--------|-------| + | `client.list_runs()` | `client.runs.query()` | + + + | Before | After | + |--------|-------| + | `client.listRuns()` | `client.runs.query()` | + + + | Before | After | + |--------|-------| + | `client.runs().query()` | `client.runs().queryV2()` | + + + | Before | After | + |--------|-------| + | `client.Runs.Query()` | `client.Runs.QueryV2()` | + + + | Before | After | + |--------|-------| + | `POST /api/v1/runs/query` | `POST /v2/runs/query` | + + + +#### Query parameters + + + + + `project_name` is not supported in `runs.query`. Pass `project_ids` with the project UUID instead. To look up a UUID by name, use `client.projects.list(name="my-project", limit=1)`. + + + + `min_start_time` defaults to **1 day ago** when omitted. `list_runs` with no `start_time` returned all historical runs; `runs.query` without `min_start_time` silently scopes the query to the last 24 hours. Pass an explicit `min_start_time` if you need a wider window. + + + | Before (`list_runs`) | After (`runs.query`) | Notes | + |---|---|---| + | `project_name` | *(removed)* | Use `project_ids` with UUID(s)—see warning above | + | `project_id` | `project_ids` | Now takes a list; mutually exclusive with `reference_dataset_id` | + | `run_type` | `run_type` | Values must now be uppercase: `"LLM"`, `"CHAIN"`, `"TOOL"`, `"RETRIEVER"`, `"EMBEDDING"`, `"PROMPT"`, `"PARSER"` | + | `trace_id` | `trace_id` | Unchanged | + | `reference_example_id` | `reference_examples` | Now takes a list of UUIDs | + | `query` | *(removed)* | No equivalent | + | `filter` | `filter` | Syntax unchanged | + | `trace_filter` | `trace_filter` | Unchanged | + | `tree_filter` | `tree_filter` | Unchanged | + | `is_root` | `is_root` | Unchanged | + | `parent_run_id` | *(removed)* | No equivalent | + | `start_time` | `min_start_time` | Renamed; defaults to 1 day ago—see warning above | + | `error` | `has_error` | Renamed | + | `run_ids` | `ids` | Renamed | + | `select` | `selects` | Field names are now uppercase (`"NAME"`, `"STATUS"`, etc.) | + | `limit` | *(removed)* | Use `page_size` for per-request batch size | + | *(not available)* | `max_start_time` | Upper bound for `start_time`; defaults to now | + | *(not available)* | `page_size` | Per-request result count (default 100, max 1000) | + | *(not available)* | `reference_dataset_id` | Alternative to `project_ids`; mutually exclusive | + | *(not available)* | `cursor` | Pass `next_cursor` from previous response to fetch next page | + + + + `projectName` is not supported in `client.runs.query`. Pass `project_ids` with the project UUID instead. To look up a UUID by name, use `client.projects.list({ name: "my-project", limit: 1 })`. + + + + `min_start_time` defaults to **1 day ago** when omitted. `listRuns` with no `startTime` returned all historical runs; `client.runs.query` without `min_start_time` silently scopes the query to the last 24 hours. Pass an explicit `min_start_time` if you need a wider window. + + + | Before (`listRuns`) | After (`client.runs.query`) | Notes | + |---|---|---| + | `projectName` | *(removed)* | Use `project_ids` with UUID(s)—see warning above | + | `projectId` | `project_ids` | Renamed to `snake_case`; now takes a list; mutually exclusive with `reference_dataset_id` | + | `runType` | `run_type` | Renamed to `snake_case`; values must now be uppercase: `"LLM"`, `"CHAIN"`, `"TOOL"`, `"RETRIEVER"`, `"EMBEDDING"`, `"PROMPT"`, `"PARSER"` | + | `traceId` | `trace_id` | Renamed to `snake_case` | + | `referenceExampleId` | `reference_examples` | Renamed to `snake_case`; now takes a list of UUIDs | + | `query` | *(removed)* | No equivalent | + | `filter` | `filter` | Syntax unchanged | + | `traceFilter` | `trace_filter` | Renamed to `snake_case` | + | `treeFilter` | `tree_filter` | Renamed to `snake_case` | + | `isRoot` | `is_root` | Renamed to `snake_case` | + | `parentRunId` | *(removed)* | No equivalent | + | `startTime` | `min_start_time` | Renamed to `snake_case`; defaults to 1 day ago—see warning above | + | `error` | `has_error` | Renamed | + | `id` | `ids` | Renamed | + | `select` | `selects` | Field names are now uppercase (`"NAME"`, `"STATUS"`, etc.) | + | `limit` | *(removed)* | Use `page_size` for per-request batch size | + | `order` | *(removed)* | No equivalent | + | `executionOrder` | *(removed)* | No equivalent | + | *(not available)* | `max_start_time` | Upper bound for `start_time`; defaults to now | + | *(not available)* | `page_size` | Per-request result count (default 100, max 1000) | + | *(not available)* | `reference_dataset_id` | Alternative to `project_ids`; mutually exclusive | + | *(not available)* | `cursor` | Pass `next_cursor` from previous response to fetch next page | + + + + `minStartTime()` defaults to **1 day ago** when omitted. `query()` with no `startTime()` returned all historical runs; `queryV2()` without `minStartTime()` silently scopes the query to the last 24 hours. Pass an explicit `minStartTime()` if you need a wider window. + + + | Before (`RunQueryParams`) | After (`RunQueryV2Params`) | Notes | + |---|---|---| + | `session()` | `projectIds()` | Renamed; now takes explicit project UUIDs | + | `runType()` | `runType()` | Values must now be uppercase | + | `trace()` | `traceId()` | Renamed | + | `referenceExample()` | `referenceExamples()` | Renamed to plural | + | `query()` | *(removed)* | No equivalent | + | `filter()` | `filter()` | Syntax unchanged | + | `traceFilter()` | `traceFilter()` | Unchanged | + | `treeFilter()` | `treeFilter()` | Unchanged | + | `isRoot()` | `isRoot()` | Unchanged | + | `parentRun()` | *(removed)* | No equivalent | + | `startTime()` | `minStartTime()` | Renamed; defaults to 1 day ago—see warning above | + | `error()` | `hasError()` | Renamed | + | `id()` | `ids()` | Renamed | + | `select()` | `selects()` | Field names are now uppercase | + | `limit()` | *(removed)* | Use `pageSize()` | + | `order()` | *(removed)* | No equivalent | + | `executionOrder()` | *(removed)* | No equivalent | + | `cursor()` | `cursor()` | Unchanged | + | *(not available)* | `maxStartTime()` | Upper bound for start time; defaults to now | + | *(not available)* | `pageSize()` | Per-request result count (default 100, max 1000) | + | *(not available)* | `referenceDatasetId()` | Alternative to `projectIds()` | + + + + `MinStartTime` defaults to **1 day ago** when omitted. `Query()` with no `StartTime` returned all historical runs; `QueryV2()` without `MinStartTime` silently scopes the query to the last 24 hours. Pass an explicit `MinStartTime` if you need a wider window. + + + | Before (`RunQueryParams`) | After (`RunQueryV2Params`) | Notes | + |---|---|---| + | `Session` | `ProjectIDs` | Renamed; now takes explicit project UUIDs | + | `RunType` | `RunType` | Values must now be uppercase: `RunQueryV2ParamsRunTypeLLM`, `RunQueryV2ParamsRunTypeChain`, etc. | + | `Trace` | `TraceID` | Renamed | + | `ReferenceExample` | `ReferenceExamples` | Renamed to plural | + | `Query` | *(removed)* | No equivalent | + | `Filter` | `Filter` | Unchanged | + | `TraceFilter` | `TraceFilter` | Unchanged | + | `TreeFilter` | `TreeFilter` | Unchanged | + | `IsRoot` | `IsRoot` | Unchanged | + | `ParentRun` | *(removed)* | No equivalent | + | `StartTime` | `MinStartTime` | Renamed; defaults to 1 day ago—see warning above | + | `Error` | `HasError` | Renamed | + | `ID` | `IDs` | Renamed | + | `Select` | `Selects` | Field name constants are now uppercase (e.g., `RunQueryV2ParamsSelectName`) | + | `Limit` | *(removed)* | Use `PageSize` | + | `Order` | *(removed)* | No equivalent | + | `ExecutionOrder` | *(removed)* | No equivalent | + | `Cursor` | `Cursor` | Unchanged | + | *(not available)* | `MaxStartTime` | Upper bound for start time; defaults to now | + | *(not available)* | `PageSize` | Per-request result count (default 100, max 1000) | + | *(not available)* | `ReferenceDatasetID` | Alternative to `ProjectIDs` | + + + + + `min_start_time` defaults to **1 day ago** when omitted. `POST /api/v1/runs/query` with no `start_time` returned all historical runs; `POST /v2/runs/query` without `min_start_time` silently scopes the query to the last 24 hours. Pass an explicit `min_start_time` if you need a wider window. + + + | Before (v1 `POST /api/v1/runs/query` body field) | After (v2 `POST /v2/runs/query` body field) | Notes | + |---|---|---| + | `session` | `project_ids` | Renamed; both take an array of project UUIDs. `project_ids` is mutually exclusive with `reference_dataset_id` | + | `run_type` | `run_type` | Values must now be uppercase: `"LLM"`, `"CHAIN"`, `"TOOL"`, `"RETRIEVER"`, `"EMBEDDING"`, `"PROMPT"`, `"PARSER"` | + | `trace` | `trace_id` | Renamed | + | `reference_example` | `reference_examples` | Renamed to plural; now takes an array of UUIDs | + | `query` | *(removed)* | No equivalent | + | `filter` | `filter` | Syntax unchanged | + | `trace_filter` | `trace_filter` | Unchanged | + | `tree_filter` | `tree_filter` | Unchanged | + | `is_root` | `is_root` | Unchanged | + | `parent_run` | *(removed)* | No equivalent | + | `start_time` | `min_start_time` | Renamed; defaults to 1 day ago—see warning above | + | `error` | `has_error` | Renamed | + | `id` | `ids` | Renamed to plural | + | `select` | `selects` | Field names are now uppercase (`"NAME"`, `"STATUS"`, etc.) | + | `limit` | *(removed)* | Use `page_size` for per-request batch size | + | *(not available)* | `max_start_time` | Upper bound for `start_time`; defaults to now | + | *(not available)* | `page_size` | Per-request result count (default 100, max 1000) | + | *(not available)* | `reference_dataset_id` | Alternative to `project_ids`; mutually exclusive | + | *(not available)* | `cursor` | Pass `next_cursor` from previous response to fetch next page | + + + +#### Response fields + + + + Pass SCREAMING_SNAKE_CASE strings to `selects` (eg. `"ID"`, `"NAME"`, `"STATUS"`) to control which fields are populated on each `Run`; only selected fields are non-`None`. Default `selects` contains only `"ID"`. + + | Before (v1 `Run` attribute) | After (v2 `Run` attribute) | Notes | + |---|---|---| + | `run.id` | `run.id` | Unchanged; returned by default when `selects` is omitted | + | `run.name` | `run.name` | Unchanged | + | `run.run_type` | `run.run_type` | Values are now uppercase Literals: `"LLM"`, `"CHAIN"`, etc. | + | `run.status` | `run.status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.start_time` | `run.start_time` | Unchanged | + | `run.end_time` | `run.end_time` | Unchanged | + | `run.error` | `run.error` | Unchanged | + | `run.inputs` | `run.inputs` | Unchanged | + | `run.outputs` | `run.outputs` | Unchanged | + | `run.tags` | `run.tags` | Unchanged | + | `run.extra` | `run.extra` | Unchanged | + | `run.metadata` | `run.metadata` | Unchanged | + | `run.events` | `run.events` | Unchanged | + | `run.reference_example_id` | `run.reference_example_id` | Unchanged | + | `run.trace_id` | `run.trace_id` | Unchanged | + | `run.dotted_order` | `run.dotted_order` | Unchanged | + | `run.parent_run_id` | *(removed)* | Use `run.parent_run_ids` (list of all ancestor UUIDs, root first) | + | `run.parent_run_ids` | `run.parent_run_ids` | Unchanged | + | `run.session_id` | `run.project_id` | Renamed; `session_id` was the project UUID | + | `run.feedback_stats` | `run.feedback_stats` | Unchanged | + | `run.app_path` | `run.app_path` | Unchanged | + | `run.attachments` | `run.attachments` | v2 returns pre-signed download URLs instead of raw bytes | + | `run.total_tokens` | `run.total_tokens` | Unchanged | + | `run.prompt_tokens` | `run.prompt_tokens` | Unchanged | + | `run.completion_tokens` | `run.completion_tokens` | Unchanged | + | `run.total_cost` | `run.total_cost` | Unchanged | + | `run.prompt_cost` | `run.prompt_cost` | Unchanged | + | `run.completion_cost` | `run.completion_cost` | Unchanged | + | `run.first_token_time` | `run.first_token_time` | Unchanged | + | `run.latency` (property) | `run.latency_seconds` | Renamed; was a computed `timedelta` property, now a native `float` field | + | `run.in_dataset` | `run.is_in_dataset` | Renamed | + | `run.child_run_ids` | *(removed)* | No equivalent | + | `run.child_runs` | *(removed)* | No equivalent | + | `run.serialized` | *(removed)* | Use `run.manifest` | + | `run.manifest_id` | *(removed)* | Use `run.manifest` | + | *(not available)* | `run.is_root` | New | + | *(not available)* | `run.manifest` | New: full manifest object (replaces `serialized` and `manifest_id`) | + | *(not available)* | `run.error_preview` | New: truncated error snippet | + | *(not available)* | `run.inputs_preview` | New: truncated inputs preview | + | *(not available)* | `run.outputs_preview` | New: truncated outputs preview | + | *(not available)* | `run.thread_id` | New: conversation thread UUID | + | *(not available)* | `run.reference_dataset_id` | New: dataset UUID for the reference example | + | *(not available)* | `run.share_url` | New: public share URL (only set when the run has been shared) | + | `run.prompt_token_details` | `run.prompt_token_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, int]` (element type unchanged) | + | `run.completion_token_details` | `run.completion_token_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, int]` (element type unchanged) | + | `run.prompt_cost_details` | `run.prompt_cost_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, float]` (was `dict[str, Decimal]`) | + | `run.completion_cost_details` | `run.completion_cost_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, float]` (was `dict[str, Decimal]`) | + + + Pass SCREAMING_SNAKE_CASE strings to `selects` (eg. `"ID"`, `"NAME"`, `"STATUS"`) to control which fields are populated on each `Run`. Default `selects` contains only `"ID"`. + + | Before (v1 `Run` property) | After (v2 `Run` property) | Notes | + |---|---|---| + | `run.id` | `run.id` | Unchanged | + | `run.name` | `run.name` | Unchanged | + | `run.runType` | `run.run_type` | Renamed to `snake_case`; values are now uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `run.status` | `run.status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.startTime` | `run.start_time` | Renamed to `snake_case` | + | `run.endTime` | `run.end_time` | Renamed to `snake_case` | + | `run.error` | `run.error` | Unchanged | + | `run.inputs` | `run.inputs` | Unchanged | + | `run.outputs` | `run.outputs` | Unchanged | + | `run.tags` | `run.tags` | Unchanged | + | `run.extra` | `run.extra` | Unchanged | + | *(not available)* | `run.metadata` | New: previously accessed via `run.extra.metadata` | + | `run.events` | `run.events` | Unchanged | + | `run.referenceExampleId` | `run.reference_example_id` | Renamed to `snake_case` | + | `run.traceId` | `run.trace_id` | Renamed to `snake_case` | + | `run.dottedOrder` | `run.dotted_order` | Renamed to `snake_case` | + | `run.parentRunId` | *(removed)* | Use `run.parent_run_ids` (list of all ancestor UUIDs, root first) | + | `run.parentRunIds` | `run.parent_run_ids` | Renamed to `snake_case` | + | `run.sessionId` | `run.project_id` | Renamed; `sessionId` was the project UUID | + | `run.feedbackStats` | `run.feedback_stats` | Renamed to `snake_case` | + | `run.appPath` | `run.app_path` | Renamed to `snake_case` | + | `run.attachments` | `run.attachments` | v2 returns pre-signed download URLs instead of raw bytes | + | `run.totalTokens` | `run.total_tokens` | Renamed to `snake_case` | + | `run.promptTokens` | `run.prompt_tokens` | Renamed to `snake_case` | + | `run.completionTokens` | `run.completion_tokens` | Renamed to `snake_case` | + | `run.totalCost` | `run.total_cost` | Renamed to `snake_case` | + | `run.promptCost` | `run.prompt_cost` | Renamed to `snake_case` | + | `run.completionCost` | `run.completion_cost` | Renamed to `snake_case` | + | `run.firstTokenTime` | `run.first_token_time` | Renamed to `snake_case` | + | `run.latency` | `run.latency_seconds` | Renamed; was a computed property, now a native `number` field (seconds) | + | `run.inDataset` | `run.is_in_dataset` | Renamed | + | `run.childRunIds` | *(removed)* | No equivalent | + | `run.childRuns` | *(removed)* | No equivalent | + | `run.serialized` | *(removed)* | Use `run.manifest` | + | `run.manifestId` | *(removed)* | Use `run.manifest` | + | `run.shareToken` | *(removed)* | Use `run.share_url` (full URL, only set when the run has been shared) | + | *(not available)* | `run.is_root` | New | + | *(not available)* | `run.manifest` | New: full manifest object (replaces `serialized` and `manifestId`) | + | *(not available)* | `run.error_preview` | New: truncated error snippet | + | *(not available)* | `run.inputs_preview` | New: truncated inputs preview | + | *(not available)* | `run.outputs_preview` | New: truncated outputs preview | + | *(not available)* | `run.thread_id` | New: conversation thread UUID | + | *(not available)* | `run.reference_dataset_id` | New: dataset UUID for the reference example | + | *(not available)* | `run.share_url` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `run.prompt_token_details` | New: per-category prompt token breakdown | + | *(not available)* | `run.completion_token_details` | New: per-category completion token breakdown | + | *(not available)* | `run.prompt_cost_details` | New: per-category prompt cost breakdown | + | *(not available)* | `run.completion_cost_details` | New: per-category completion cost breakdown | + + + Add `RunQueryV2Params.Select` values (eg. `Select.NAME`, `Select.STATUS`) via `.addSelect(...)` to control which fields are populated; unselected fields return empty `Optional` values. `selects()` defaults to `ID` only. + + | Before (`RunSchema` method) | After (`Run` method) | Notes | + |---|---|---| + | `run.id()` | `run.id()` | Unchanged | + | `run.name()` | `run.name()` | Unchanged | + | `run.runType()` | `run.runType()` | Values are now uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `run.status()` | `run.status()` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.startTime()` | `run.startTime()` | Unchanged | + | `run.endTime()` | `run.endTime()` | Unchanged | + | `run.error()` | `run.error()` | Unchanged | + | `run.inputs()` | `run.inputs()` | Unchanged | + | `run.outputs()` | `run.outputs()` | Unchanged | + | `run.tags()` | `run.tags()` | Unchanged | + | `run.extra()` | `run.extra()` | Unchanged | + | `run.events()` | `run.events()` | Unchanged | + | `run.feedbackStats()` | `run.feedbackStats()` | Unchanged | + | `run.inputsPreview()` | `run.inputsPreview()` | Unchanged | + | `run.outputsPreview()` | `run.outputsPreview()` | Unchanged | + | `run.referenceExampleId()` | `run.referenceExampleId()` | Unchanged | + | `run.traceId()` | `run.traceId()` | Unchanged | + | `run.dottedOrder()` | `run.dottedOrder()` | Unchanged | + | `run.parentRunId()` | *(removed)* | Use `run.parentRunIds()` (list of all ancestor UUIDs, root first) | + | `run.parentRunIds()` | `run.parentRunIds()` | Unchanged | + | `run.sessionId()` | `run.projectId()` | Renamed; `sessionId()` returned the project UUID | + | `run.appPath()` | `run.appPath()` | Unchanged | + | `run.firstTokenTime()` | `run.firstTokenTime()` | Unchanged | + | `run.totalTokens()` | `run.totalTokens()` | Unchanged | + | `run.promptTokens()` | `run.promptTokens()` | Unchanged | + | `run.completionTokens()` | `run.completionTokens()` | Unchanged | + | `run.totalCost()` | `run.totalCost()` | Return type changed from `Optional` to `Optional` | + | `run.promptCost()` | `run.promptCost()` | Return type changed from `Optional` to `Optional` | + | `run.completionCost()` | `run.completionCost()` | Return type changed from `Optional` to `Optional` | + | `run.promptTokenDetails()` | `run.promptTokenDetails()` | Unchanged | + | `run.completionTokenDetails()` | `run.completionTokenDetails()` | Unchanged | + | `run.promptCostDetails()` | `run.promptCostDetails()` | Unchanged | + | `run.completionCostDetails()` | `run.completionCostDetails()` | Unchanged | + | `run.priceModelId()` | `run.priceModelId()` | Unchanged | + | `run.inDataset()` | `run.isInDataset()` | Renamed | + | `run.referenceDatasetId()` | `run.referenceDatasetId()` | Unchanged | + | `run.threadId()` | `run.threadId()` | Unchanged | + | `run.shareToken()` | *(removed)* | Use `run.shareUrl()` (full URL, only set when the run has been shared) | + | `run.childRunIds()` | *(removed)* | No equivalent | + | `run.directChildRunIds()` | *(removed)* | No equivalent | + | `run.serialized()` | *(removed)* | Use `run.manifest()` | + | `run.manifestId()` | *(removed)* | Use `run.manifest()` | + | `run.messages()` | *(removed)* | No equivalent | + | `run.executionOrder()` | *(removed)* | No equivalent | + | `run.lastQueuedAt()` | *(removed)* | No equivalent | + | `run.traceFirstReceivedAt()` | *(removed)* | No equivalent | + | `run.traceMaxStartTime()` | *(removed)* | No equivalent | + | `run.traceMinStartTime()` | *(removed)* | No equivalent | + | `run.traceTier()` | *(removed)* | No equivalent | + | `run.traceUpgrade()` | *(removed)* | No equivalent | + | `run.ttlSeconds()` | *(removed)* | No equivalent | + | *(not available)* | `run.attachments()` | New: pre-signed download URLs for attachments (replaces S3 URL fields) | + | *(not available)* | `run.latencySeconds()` | New: wall-clock duration in seconds | + | *(not available)* | `run.isRoot()` | New | + | *(not available)* | `run.errorPreview()` | New: truncated error snippet | + | *(not available)* | `run.manifest()` | New: full manifest, typed as `Optional` (replaces `serialized()` and `manifestId()`) | + | *(not available)* | `run.metadata()` | New: metadata, typed as `Optional` (was derived from `extra.metadata`) | + | *(not available)* | `run.shareUrl()` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `run.threadEvaluationTime()` | New | + + + Pass `RunQueryV2ParamsSelect` constants (eg. `RunQueryV2ParamsSelectName`, `RunQueryV2ParamsSelectStatus`) to `Selects` to control which fields are populated; unselected fields are zero-valued on the returned struct. `Selects` defaults to `ID` only. + + | Before (`RunSchema` field) | After (`Run` field) | Notes | + |---|---|---| + | `run.ID` | `run.ID` | Unchanged | + | `run.Name` | `run.Name` | Unchanged | + | `run.RunType` | `run.RunType` | Values changed to uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `run.Status` | `run.Status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.TraceID` | `run.TraceID` | Unchanged | + | `run.DottedOrder` | `run.DottedOrder` | Unchanged | + | `run.AppPath` | `run.AppPath` | Unchanged | + | `run.StartTime` | `run.StartTime` | Unchanged | + | `run.EndTime` | `run.EndTime` | Unchanged | + | `run.Error` | `run.Error` | Unchanged | + | `run.Events` | `run.Events` | Unchanged; element type is now `RunEvent` (was `map[string]interface{}`) | + | `run.Extra` | `run.Extra` | Unchanged; type is now `interface{}` (was `map[string]interface{}`) | + | `run.FeedbackStats` | `run.FeedbackStats` | Unchanged; element type is now `RunFeedbackStat` | + | `run.FirstTokenTime` | `run.FirstTokenTime` | Unchanged | + | `run.Inputs` | `run.Inputs` | Unchanged; type is now `interface{}` (was `map[string]interface{}`) | + | `run.InputsPreview` | `run.InputsPreview` | Unchanged | + | `run.Outputs` | `run.Outputs` | Unchanged; type is now `interface{}` (was `map[string]interface{}`) | + | `run.OutputsPreview` | `run.OutputsPreview` | Unchanged | + | `run.ParentRunIDs` | `run.ParentRunIDs` | Unchanged | + | `run.PriceModelID` | `run.PriceModelID` | Unchanged | + | `run.PromptCost` | `run.PromptCost` | Unchanged | + | `run.PromptCostDetails` | `run.PromptCostDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]float64` (was `map[string]string`) | + | `run.PromptTokenDetails` | `run.PromptTokenDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]int64` (element type unchanged) | + | `run.PromptTokens` | `run.PromptTokens` | Unchanged | + | `run.CompletionCost` | `run.CompletionCost` | Unchanged | + | `run.CompletionCostDetails` | `run.CompletionCostDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]float64` (was `map[string]string`) | + | `run.CompletionTokenDetails` | `run.CompletionTokenDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]int64` (element type unchanged) | + | `run.CompletionTokens` | `run.CompletionTokens` | Unchanged | + | `run.TotalCost` | `run.TotalCost` | Unchanged | + | `run.TotalTokens` | `run.TotalTokens` | Unchanged | + | `run.ReferenceDatasetID` | `run.ReferenceDatasetID` | Unchanged | + | `run.ReferenceExampleID` | `run.ReferenceExampleID` | Unchanged | + | `run.Tags` | `run.Tags` | Unchanged | + | `run.ThreadID` | `run.ThreadID` | Unchanged | + | `run.SessionID` | `run.ProjectID` | Renamed | + | `run.InDataset` | `run.IsInDataset` | Renamed | + | `run.ChildRunIDs` | *(removed)* | No equivalent | + | `run.DirectChildRunIDs` | *(removed)* | No equivalent | + | `run.ExecutionOrder` | *(removed)* | No equivalent | + | `run.InputsS3URLs` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.LastQueuedAt` | *(removed)* | No equivalent | + | `run.ManifestID` | *(removed)* | Use `run.Manifest` | + | `run.ManifestS3ID` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.Messages` | *(removed)* | No equivalent | + | `run.OutputsS3URLs` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.ParentRunID` | *(removed)* | Use `run.ParentRunIDs` | + | `run.S3URLs` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.Serialized` | *(removed)* | Use `run.Manifest` | + | `run.ShareToken` | *(removed)* | Use `run.ShareURL` | + | `run.TraceFirstReceivedAt` | *(removed)* | No equivalent | + | `run.TraceMaxStartTime` | *(removed)* | No equivalent | + | `run.TraceMinStartTime` | *(removed)* | No equivalent | + | `run.TraceTier` | *(removed)* | No equivalent | + | `run.TraceUpgrade` | *(removed)* | No equivalent | + | `run.TtlSeconds` | *(removed)* | No equivalent | + | *(not available)* | `run.Attachments` | New: maps attachment filename to pre-signed download URL | + | *(not available)* | `run.ErrorPreview` | New: truncated error snippet | + | *(not available)* | `run.IsRoot` | New | + | *(not available)* | `run.LatencySeconds` | New: wall-clock duration in seconds | + | *(not available)* | `run.Manifest` | New: full manifest object (replaces `Serialized` and `ManifestID`) | + | *(not available)* | `run.Metadata` | New: arbitrary user-defined JSON metadata | + | *(not available)* | `run.ShareURL` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `run.ThreadEvaluationTime` | New | + + + Field names in the JSON response match Python `snake_case`. + + Pass SCREAMING_SNAKE_CASE strings in the `selects` JSON array (eg. `"ID"`, `"NAME"`, `"STATUS"`) to control which fields are populated. Default `selects` contains only `"ID"`. + + | Before (v1 response field) | After (v2 response field) | Notes | + |---|---|---| + | `id` | `id` | Unchanged | + | `name` | `name` | Unchanged | + | `run_type` | `run_type` | Values changed to uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `status` | `status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `trace_id` | `trace_id` | Unchanged | + | `dotted_order` | `dotted_order` | Unchanged | + | `app_path` | `app_path` | Unchanged | + | `start_time` | `start_time` | Unchanged | + | `end_time` | `end_time` | Unchanged | + | `error` | `error` | Unchanged | + | `events` | `events` | Unchanged | + | `extra` | `extra` | Unchanged | + | `feedback_stats` | `feedback_stats` | Unchanged | + | `first_token_time` | `first_token_time` | Unchanged | + | `inputs` | `inputs` | Unchanged | + | `inputs_preview` | `inputs_preview` | Unchanged | + | `outputs` | `outputs` | Unchanged | + | `outputs_preview` | `outputs_preview` | Unchanged | + | `parent_run_ids` | `parent_run_ids` | Unchanged | + | `price_model_id` | `price_model_id` | Unchanged | + | `prompt_cost` | `prompt_cost` | Unchanged | + | `prompt_cost_details` | `prompt_cost_details.raw` | Field now wraps the object; read `.raw` for the same `{category: cost}` mapping, now with numeric values (was strings) | + | `prompt_token_details` | `prompt_token_details.raw` | Field now wraps the object; read `.raw` for the same `{category: count}` mapping (values unchanged) | + | `prompt_tokens` | `prompt_tokens` | Unchanged | + | `completion_cost` | `completion_cost` | Unchanged | + | `completion_cost_details` | `completion_cost_details.raw` | Field now wraps the object; read `.raw` for the same `{category: cost}` mapping, now with numeric values (was strings) | + | `completion_token_details` | `completion_token_details.raw` | Field now wraps the object; read `.raw` for the same `{category: count}` mapping (values unchanged) | + | `completion_tokens` | `completion_tokens` | Unchanged | + | `total_cost` | `total_cost` | Unchanged | + | `total_tokens` | `total_tokens` | Unchanged | + | `reference_dataset_id` | `reference_dataset_id` | Unchanged | + | `reference_example_id` | `reference_example_id` | Unchanged | + | `tags` | `tags` | Unchanged | + | `thread_id` | `thread_id` | Unchanged | + | `session_id` | `project_id` | Renamed | + | `in_dataset` | `is_in_dataset` | Renamed | + | `child_run_ids` | *(removed)* | No equivalent | + | `direct_child_run_ids` | *(removed)* | No equivalent | + | `execution_order` | *(removed)* | No equivalent | + | `inputs_s3_urls` | *(removed)* | Internal storage URL; not exposed in v2 | + | `last_queued_at` | *(removed)* | No equivalent | + | `manifest_id` | *(removed)* | Use `manifest` | + | `manifest_s3_id` | *(removed)* | Internal storage URL; not exposed in v2 | + | `messages` | *(removed)* | No equivalent | + | `outputs_s3_urls` | *(removed)* | Internal storage URL; not exposed in v2 | + | `parent_run_id` | *(removed)* | Use `parent_run_ids` | + | `s3_urls` | *(removed)* | Internal storage URL; not exposed in v2 | + | `serialized` | *(removed)* | Use `manifest` | + | `share_token` | *(removed)* | Use `share_url` | + | `trace_first_received_at` | *(removed)* | No equivalent | + | `trace_max_start_time` | *(removed)* | No equivalent | + | `trace_min_start_time` | *(removed)* | No equivalent | + | `trace_tier` | *(removed)* | No equivalent | + | `trace_upgrade` | *(removed)* | No equivalent | + | `ttl_seconds` | *(removed)* | No equivalent | + | *(not available)* | `attachments` | New: maps attachment filename to pre-signed download URL | + | *(not available)* | `error_preview` | New: truncated error snippet | + | *(not available)* | `is_root` | New | + | *(not available)* | `latency_seconds` | New: wall-clock duration in seconds | + | *(not available)* | `manifest` | New: full manifest object (replaces `serialized` and `manifest_id`) | + | *(not available)* | `metadata` | New: previously nested under `extra.metadata` | + | *(not available)* | `share_url` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `thread_evaluation_time` | New | + + + +### Examples + +#### List all runs in a project + + + + `runs.query` does not accept a project name directly. Resolve the project UUID with `client.projects.list()` first, then pass it as a string in `project_ids`. + + + + + + + + + + + + + `client.runs.query` does not accept a project name directly. Resolve the project UUID with `client.projects.list()` first, then pass it as a string in `project_ids`. + + + + + + + + + + + + + `queryV2()` does not accept a project name directly. Resolve the project UUID with `client.sessions().list()` first, then pass it as a string in `projectIds()`. + + + + + + + + + + + + + `QueryV2()` does not accept a project name directly. Resolve the project UUID with `client.Sessions.List()` first, then pass it as a string in `ProjectIDs`. + + + + + + + + + + + + + `POST /v2/runs/query` does not accept a project name directly. Resolve the project UUID with a `GET /api/v1/sessions` request first, then pass it as a string in `project_ids`. + + + + + + + + + + + + + +#### Selecting fields + + + + `list_runs` returns a default set of fields with no selection needed. `runs.query` returns only `id` by default—pass `selects=[...]` to request more. Field names are now uppercase (`"name"` → `"NAME"`). + + + + + + + + + + + + + `listRuns` returns a default set of fields with no selection needed. `client.runs.query` returns only `id` by default—pass `selects: [...]` to request more. Field names are now uppercase (`"name"` → `"NAME"`). + + + + + + + + + + + + + `query()` returns a default set of fields with no selection needed. `queryV2()` returns only `id` by default—call `.addSelect(RunQueryV2Params.Select.X)` for each field you need. + + + + + + + + + + + + + `Query` returns a default set of fields with no selection needed. `QueryV2` returns only `ID` by default—pass `Selects` with the uppercase field constants you need (e.g. `RunQueryV2ParamsSelectName`). + + + + + + + + + + + + + `POST /api/v1/runs/query` returns a default set of fields with no selection needed. `POST /v2/runs/query` returns only `id` by default—pass `selects` with the uppercase field names you need (e.g. `"NAME"`). + + + + + + + + + + + + + +#### Filter by run type and time range + + + + `start_time` is renamed to `min_start_time`, and `run_type` values are now uppercase (`"llm"` → `"LLM"`). + + + + + + + + + + + + + `startTime` (camelCase) becomes `min_start_time` (snake_case, matching the v2 request body), and `runType` values are now uppercase (`"llm"` → `"LLM"`). + + + + + + + + + + + + + `.startTime()` is renamed to `.minStartTime()`, and `.runType()` now takes the new `RunQueryV2Params.RunType` enum instead of `RunTypeEnum`. + + + + + + + + + + + + + `StartTime` is renamed to `MinStartTime`, and `RunType` now takes the new `RunQueryV2ParamsRunType` enum instead of `RunTypeEnum`. + + + + + + + + + + + + + `start_time` is renamed to `min_start_time`, and `run_type` values are now uppercase (`"llm"` → `"LLM"`). + + + + + + + + + + + + + +#### Filter root runs only + + + + `is_root` is unchanged. + + + + + + + + + + + + + `isRoot` (camelCase) becomes `is_root` (snake_case, matching the v2 request body). + + + + + + + + + + + + + `.isRoot()` is unchanged. + + + + + + + + + + + + + `IsRoot` is unchanged. + + + + + + + + + + + + + `is_root` is unchanged. + + + + + + + + + + + + + +#### Fetch runs by ID list + + + + `id=[...]` is renamed to `ids=[...]`. `project_ids` is now required even when filtering by run IDs—v1 allowed omitting the project context. + + + + + + + + + + + + + `id: [...]` is renamed to `ids: [...]`. `project_ids` is now required even when filtering by run IDs—v1 allowed omitting the project context. + + + + + + + + + + + + + `.addId(...)` is unchanged—call it once per run ID. `.addProjectId(...)` is now required even when filtering by run IDs—v1 allowed omitting the project context. + + + + + + + + + + + + + `ID: [...]` is renamed to `IDs: [...]`. `ProjectIDs` is now required even when filtering by run IDs—v1 allowed omitting the project context. + + + + + + + + + + + + + `id` is renamed to `ids`. `project_ids` is now required in the request body even when filtering by run IDs—v1 allowed omitting the project context. + + + + + + + + + + + + + +#### Iterate through runs + + + + `list_runs` auto-paginates transparently, fetching up to 100 runs per API call and stopping once `limit` results are returned. `runs.query` does not accept a total `limit`; iterate with `async for` and `break` once you have enough, or use the returned page's `has_next_page()`/`get_next_page()` for manual page-by-page control. + + + + + + + + + + + + + `listRuns` auto-paginates transparently. `client.runs.query` returns an async iterable of individual runs—use `for await` and `break` once you have enough. + + + + + + + + + + + + + `.autoPager()` is used the same way on both `query()` and `queryV2()`—break out of the loop once you have enough runs. + + + + + + + + + + + + + `QueryAutoPaging` is renamed to `QueryV2AutoPaging`; both use the same `iter.Next()`/`iter.Current()` pattern—break out of the loop once you have enough runs. + + + + + + + + + + + + + The v1 API returns all matching runs in one response with no cursor. The v2 API paginates—pass the `cursor` from a response's `next_cursor` field to fetch the next page. + + + + + + + + + + + + + +#### Filter runs with errors + + + + `error=True/False` is renamed to `has_error=True/False`. + + + + + + + + + + + + + `error: true/false` is renamed to `has_error: true/false`. + + + + + + + + + + + + + `.error(true/false)` is renamed to `.hasError(true/false)`. + + + + + + + + + + + + + `Error` is renamed to `HasError`. + + + + + + + + + + + + + `error` is renamed to `has_error`. + + + + + + + + + + + + + +#### Filter by metadata + + + + The `filter` string syntax is unchanged: `eq(metadata_key, ...)` checks for key presence, combined with `eq(metadata_value, ...)` to match a specific value. + + + + + + + + + + + + + The `filter` string syntax is unchanged: `eq(metadata_key, ...)` checks for key presence, combined with `eq(metadata_value, ...)` to match a specific value. + + + + + + + + + + + + + The `.filter(...)` string syntax is unchanged: `eq(metadata_key, ...)` checks for key presence, combined with `eq(metadata_value, ...)` to match a specific value. + + + + + + + + + + + + + The `Filter` string syntax is unchanged: `eq(metadata_key, ...)` checks for key presence, combined with `eq(metadata_value, ...)` to match a specific value. + + + + + + + + + + + + + The `filter` string syntax is unchanged: `eq(metadata_key, ...)` checks for key presence, combined with `eq(metadata_value, ...)` to match a specific value. + + + + + + + + + + + + + +#### Complex boolean filters + + + + Nested `and()` / `or()` filter expressions are unchanged. + + + + + + + + + + + + + Nested `and()` / `or()` filter expressions are unchanged. + + + + + + + + + + + + + Nested `and()` / `or()` filter expressions are unchanged. + + + + + + + + + + + + + Nested `and()` / `or()` filter expressions are unchanged. + + + + + + + + + + + + + Nested `and()` / `or()` filter expressions are unchanged. + + + + + + + + + + + + + +#### Scoped filters: filter, trace_filter, tree_filter + + + + `filter`, `trace_filter`, and `tree_filter` are unchanged. `filter` applies to the matched run, `trace_filter` to the root of its trace, and `tree_filter` to other runs in the trace tree (siblings and children). + + + + + + + + + + + + + `filter`, `trace_filter`, and `tree_filter` are unchanged. `filter` applies to the matched run, `trace_filter` to the root of its trace, and `tree_filter` to other runs in the trace tree (siblings and children). + + + + + + + + + + + + + `.filter()`, `.traceFilter()`, and `.treeFilter()` are unchanged. `filter` applies to the matched run, `traceFilter` to the root of its trace, and `treeFilter` to other runs in the trace tree (siblings and children). + + + + + + + + + + + + + `Filter`, `TraceFilter`, and `TreeFilter` are unchanged. `Filter` applies to the matched run, `TraceFilter` to the root of its trace, and `TreeFilter` to other runs in the trace tree (siblings and children). + + + + + + + + + + + + + `filter`, `trace_filter`, and `tree_filter` are unchanged. `filter` applies to the matched run, `trace_filter` to the root of its trace, and `tree_filter` to other runs in the trace tree (siblings and children). + + + + + + + + + + + + + diff --git a/src/snippets/langsmith/smithdb-migration/runs-retrieve.mdx b/src/snippets/langsmith/smithdb-migration/runs-retrieve.mdx new file mode 100644 index 000000000..a93146e77 --- /dev/null +++ b/src/snippets/langsmith/smithdb-migration/runs-retrieve.mdx @@ -0,0 +1,595 @@ +import SmithdbRunsRetrieveBasicBeforePy from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-py.mdx'; +import SmithdbRunsRetrieveBasicAfterPy from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-py.mdx'; +import SmithdbRunsRetrieveBasicBeforeJs from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-js.mdx'; +import SmithdbRunsRetrieveBasicAfterJs from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-js.mdx'; +import SmithdbRunsRetrieveBasicBeforeKt from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-kt.mdx'; +import SmithdbRunsRetrieveBasicAfterKt from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-kt.mdx'; +import SmithdbRunsRetrieveBasicBeforeGo from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-go.mdx'; +import SmithdbRunsRetrieveBasicAfterGo from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-go.mdx'; +import SmithdbRunsRetrieveByIdBeforePy from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-py.mdx'; +import SmithdbRunsRetrieveByIdAfterPy from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-py.mdx'; +import SmithdbRunsRetrieveByIdBeforeJs from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-js.mdx'; +import SmithdbRunsRetrieveByIdAfterJs from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-js.mdx'; +import SmithdbRunsRetrieveByIdBeforeGo from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-go.mdx'; +import SmithdbRunsRetrieveByIdAfterGo from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-go.mdx'; +import SmithdbRunsRetrieveByIdBeforeKt from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-kt.mdx'; +import SmithdbRunsRetrieveByIdAfterKt from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-kt.mdx'; +import SmithdbRunsRetrieveBasicBeforeSh from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-before-sh.mdx'; +import SmithdbRunsRetrieveBasicAfterSh from '/snippets/code-samples/smithdb-migration/runs-retrieve-basic-after-sh.mdx'; +import SmithdbRunsRetrieveByIdBeforeSh from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-before-sh.mdx'; +import SmithdbRunsRetrieveByIdAfterSh from '/snippets/code-samples/smithdb-migration/runs-retrieve-by-id-after-sh.mdx'; + +## Runs: retrieve + +Fetch a single run by ID. Returns only the run ID by default—specify a field selection list to retrieve additional data. + +### Main changes + +#### Method name + + + + | Before | After | + |--------|-------| + | `client.read_run()` | `client.runs.retrieve()` | + + + | Before | After | + |--------|-------| + | `client.readRun()` | `client.runs.retrieve()` | + + + | Before | After | + |--------|-------| + | `client.runs().retrieve()` | `client.runs().retrieveV2()` | + + + | Before | After | + |--------|-------| + | `client.Runs.Get()` | `client.Runs.GetV2()` | + + + | Before | After | + |--------|-------| + | `GET /api/v1/runs/{run_id}` | `GET /v2/runs/{run_id}` | + + + +#### Query parameters + + + + + `runs.retrieve` requires two new fields—`project_id` and `start_time`—that `read_run` did not need. Both are required to locate the run in SmithDB. + + + | Before (`read_run`) | After (`runs.retrieve`) | Notes | + |---|---|---| + | `run_id` | `run_id` | Unchanged | + | `load_child_runs` | *(removed)* | No equivalent | + | *(not available)* | `project_id` | **Required**—UUID of the project that owns the run | + | *(not available)* | `start_time` | **Required**—run's start time (RFC3339), used with `project_id` to locate the run | + | *(all fields returned by default)* | `selects` | Field projection; defaults to `["ID"]` only; field names are uppercase | + + + + `client.runs.retrieve` requires two new fields—`project_id` and `start_time`—that `readRun` did not need. Both are required to locate the run in SmithDB. + + + | Before (`readRun`) | After (`client.runs.retrieve`) | Notes | + |---|---|---| + | `runId` | `runId` | Unchanged (positional parameter) | + | `options.loadChildRuns` | *(removed)* | No equivalent | + | *(not available)* | `project_id` | **Required**—`snake_case`; UUID of the project that owns the run | + | *(not available)* | `start_time` | **Required**—`snake_case`; run's start time (RFC3339), used to locate the run | + | *(all fields returned by default)* | `selects` | Field projection; defaults to `["ID"]` only; field names are uppercase | + + + + `retrieveV2()` requires `projectId()`, which replaces the removed `sessionId()`, and makes `startTime()` required (previously optional). Both are needed to locate the run in SmithDB. + + + | Before (`RunRetrieveParams`) | After (`RunRetrieveV2Params`) | Notes | + |---|---|---| + | `runId()` | `runId()` | Unchanged | + | `sessionId()` | *(removed)* | Replaced by `projectId()` | + | `startTime()` | `startTime()` | Now **required**; used with `projectId()` to locate the run in SmithDB | + | `excludeS3StoredAttributes()` | *(removed)* | No equivalent | + | `excludeSerialized()` | *(removed)* | No equivalent | + | `includeMessages()` | *(removed)* | No equivalent | + | *(not available)* | `projectId()` | **Required**—UUID of the project that owns the run | + | *(all fields returned by default)* | `selects()` | Field projection; defaults to `["ID"]` only; field names are uppercase | + + + + `GetV2()` requires `ProjectID`, which replaces the removed `SessionID`, and makes `StartTime` required (previously optional). Both are needed to locate the run in SmithDB. + + + | Before (`RunGetParams`) | After (`RunGetV2Params`) | Notes | + |---|---|---| + | `runID` (positional) | `runID` (positional) | Unchanged | + | `ExcludeS3StoredAttributes` | *(removed)* | No equivalent | + | `ExcludeSerialized` | *(removed)* | No equivalent | + | `IncludeMessages` | *(removed)* | No equivalent | + | `SessionID` | *(removed)* | Replaced by `ProjectID` | + | `StartTime` | `StartTime` | Now **required**; used with `ProjectID` to locate the run in SmithDB | + | *(not available)* | `ProjectID` | **Required**—UUID of the project that owns the run | + | *(all fields returned by default)* | `Selects` | Field projection; defaults to `["ID"]` only; field name constants are uppercase (e.g., `RunGetV2ParamsSelectName`) | + + + `run_id` remains in the URL path. All other parameters are query string values with `snake_case` names. + + + `GET /v2/runs/{run_id}` requires a new `project_id` query param and makes `start_time` required (previously optional). Both are needed to locate the run in SmithDB. + + + | Before (`GET /api/v1/runs/{run_id}` param) | After (`GET /v2/runs/{run_id}` param) | Notes | + |---|---|---| + | `run_id` (path) | `run_id` (path) | Unchanged | + | `load_child_runs` (query) | *(removed)* | No equivalent | + | *(not available)* | `project_id` (query) | **Required**—UUID of the project that owns the run | + | `start_time` (query) | `start_time` (query) | Now **required**; used with `project_id` to locate the run in SmithDB | + | *(all fields returned by default)* | `selects` (query, repeatable) | Field projection; defaults to `["ID"]` only; field names are uppercase | + + + +#### Response fields + + + + Pass SCREAMING_SNAKE_CASE strings to `selects` (eg. `"ID"`, `"NAME"`, `"STATUS"`) to control which fields are populated on the returned `Run`; only selected fields are non-`None`. Default `selects` contains only `"ID"`. + + | Before (v1 `Run` attribute) | After (v2 `Run` attribute) | Notes | + |---|---|---| + | `run.id` | `run.id` | Unchanged; returned by default when `selects` is omitted | + | `run.name` | `run.name` | Unchanged | + | `run.run_type` | `run.run_type` | Values are now uppercase Literals: `"LLM"`, `"CHAIN"`, etc. | + | `run.status` | `run.status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.start_time` | `run.start_time` | Unchanged | + | `run.end_time` | `run.end_time` | Unchanged | + | `run.error` | `run.error` | Unchanged | + | `run.inputs` | `run.inputs` | Unchanged | + | `run.outputs` | `run.outputs` | Unchanged | + | `run.tags` | `run.tags` | Unchanged | + | `run.extra` | `run.extra` | Unchanged | + | `run.metadata` | `run.metadata` | Unchanged | + | `run.events` | `run.events` | Unchanged | + | `run.reference_example_id` | `run.reference_example_id` | Unchanged | + | `run.trace_id` | `run.trace_id` | Unchanged | + | `run.dotted_order` | `run.dotted_order` | Unchanged | + | `run.parent_run_id` | *(removed)* | Use `run.parent_run_ids` (list of all ancestor UUIDs, root first) | + | `run.parent_run_ids` | `run.parent_run_ids` | Unchanged | + | `run.session_id` | `run.project_id` | Renamed; `session_id` was the project UUID | + | `run.feedback_stats` | `run.feedback_stats` | Unchanged | + | `run.app_path` | `run.app_path` | Unchanged | + | `run.attachments` | `run.attachments` | v2 returns pre-signed download URLs instead of raw bytes | + | `run.total_tokens` | `run.total_tokens` | Unchanged | + | `run.prompt_tokens` | `run.prompt_tokens` | Unchanged | + | `run.completion_tokens` | `run.completion_tokens` | Unchanged | + | `run.total_cost` | `run.total_cost` | Unchanged | + | `run.prompt_cost` | `run.prompt_cost` | Unchanged | + | `run.completion_cost` | `run.completion_cost` | Unchanged | + | `run.first_token_time` | `run.first_token_time` | Unchanged | + | `run.latency` (property) | `run.latency_seconds` | Renamed; was a computed `timedelta` property, now a native `float` field | + | `run.in_dataset` | `run.is_in_dataset` | Renamed | + | `run.child_run_ids` | *(removed)* | No equivalent | + | `run.child_runs` | *(removed)* | No equivalent | + | `run.serialized` | *(removed)* | Use `run.manifest` | + | `run.manifest_id` | *(removed)* | Use `run.manifest` | + | *(not available)* | `run.is_root` | New | + | *(not available)* | `run.manifest` | New: full manifest object (replaces `serialized` and `manifest_id`) | + | *(not available)* | `run.error_preview` | New: truncated error snippet | + | *(not available)* | `run.inputs_preview` | New: truncated inputs preview | + | *(not available)* | `run.outputs_preview` | New: truncated outputs preview | + | *(not available)* | `run.thread_id` | New: conversation thread UUID | + | *(not available)* | `run.reference_dataset_id` | New: dataset UUID for the reference example | + | *(not available)* | `run.share_url` | New: public share URL (only set when the run has been shared) | + | `run.prompt_token_details` | `run.prompt_token_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, int]` (element type unchanged) | + | `run.completion_token_details` | `run.completion_token_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, int]` (element type unchanged) | + | `run.prompt_cost_details` | `run.prompt_cost_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, float]` (was `dict[str, Decimal]`) | + | `run.completion_cost_details` | `run.completion_cost_details.raw` | Field now wraps the dict; access `.raw` to get `dict[str, float]` (was `dict[str, Decimal]`) | + + + Pass SCREAMING_SNAKE_CASE strings to `selects` (eg. `"ID"`, `"NAME"`, `"STATUS"`) to control which fields are populated on the returned `Run`. Default `selects` contains only `"ID"`. + + | Before (v1 `Run` property) | After (v2 `Run` property) | Notes | + |---|---|---| + | `run.id` | `run.id` | Unchanged | + | `run.name` | `run.name` | Unchanged | + | `run.runType` | `run.run_type` | Renamed to `snake_case`; values are now uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `run.status` | `run.status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.startTime` | `run.start_time` | Renamed to `snake_case` | + | `run.endTime` | `run.end_time` | Renamed to `snake_case` | + | `run.error` | `run.error` | Unchanged | + | `run.inputs` | `run.inputs` | Unchanged | + | `run.outputs` | `run.outputs` | Unchanged | + | `run.tags` | `run.tags` | Unchanged | + | `run.extra` | `run.extra` | Unchanged | + | *(not available)* | `run.metadata` | New: previously accessed via `run.extra.metadata` | + | `run.events` | `run.events` | Unchanged | + | `run.referenceExampleId` | `run.reference_example_id` | Renamed to `snake_case` | + | `run.traceId` | `run.trace_id` | Renamed to `snake_case` | + | `run.dottedOrder` | `run.dotted_order` | Renamed to `snake_case` | + | `run.parentRunId` | *(removed)* | Use `run.parent_run_ids` (list of all ancestor UUIDs, root first) | + | `run.parentRunIds` | `run.parent_run_ids` | Renamed to `snake_case` | + | `run.sessionId` | `run.project_id` | Renamed; `sessionId` was the project UUID | + | `run.feedbackStats` | `run.feedback_stats` | Renamed to `snake_case` | + | `run.appPath` | `run.app_path` | Renamed to `snake_case` | + | `run.attachments` | `run.attachments` | v2 returns pre-signed download URLs instead of raw bytes | + | `run.totalTokens` | `run.total_tokens` | Renamed to `snake_case` | + | `run.promptTokens` | `run.prompt_tokens` | Renamed to `snake_case` | + | `run.completionTokens` | `run.completion_tokens` | Renamed to `snake_case` | + | `run.totalCost` | `run.total_cost` | Renamed to `snake_case` | + | `run.promptCost` | `run.prompt_cost` | Renamed to `snake_case` | + | `run.completionCost` | `run.completion_cost` | Renamed to `snake_case` | + | `run.firstTokenTime` | `run.first_token_time` | Renamed to `snake_case` | + | `run.latency` | `run.latency_seconds` | Renamed; was a computed property, now a native `number` field (seconds) | + | `run.inDataset` | `run.is_in_dataset` | Renamed | + | `run.childRunIds` | *(removed)* | No equivalent | + | `run.childRuns` | *(removed)* | No equivalent | + | `run.serialized` | *(removed)* | Use `run.manifest` | + | `run.manifestId` | *(removed)* | Use `run.manifest` | + | `run.shareToken` | *(removed)* | Use `run.share_url` (full URL, only set when the run has been shared) | + | *(not available)* | `run.is_root` | New | + | *(not available)* | `run.manifest` | New: full manifest object (replaces `serialized` and `manifestId`) | + | *(not available)* | `run.error_preview` | New: truncated error snippet | + | *(not available)* | `run.inputs_preview` | New: truncated inputs preview | + | *(not available)* | `run.outputs_preview` | New: truncated outputs preview | + | *(not available)* | `run.thread_id` | New: conversation thread UUID | + | *(not available)* | `run.reference_dataset_id` | New: dataset UUID for the reference example | + | *(not available)* | `run.share_url` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `run.prompt_token_details` | New: per-category prompt token breakdown | + | *(not available)* | `run.completion_token_details` | New: per-category completion token breakdown | + | *(not available)* | `run.prompt_cost_details` | New: per-category prompt cost breakdown | + | *(not available)* | `run.completion_cost_details` | New: per-category completion cost breakdown | + + + Add `RunRetrieveV2Params.Select` values (eg. `Select.NAME`, `Select.STATUS`) via `.addSelect(...)` to control which fields are populated; unselected fields return empty `Optional` values. `selects()` defaults to `ID` only. + + | Before (`RunSchema` method) | After (`Run` method) | Notes | + |---|---|---| + | `run.id()` | `run.id()` | Unchanged | + | `run.name()` | `run.name()` | Unchanged | + | `run.runType()` | `run.runType()` | Values are now uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `run.status()` | `run.status()` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.startTime()` | `run.startTime()` | Unchanged | + | `run.endTime()` | `run.endTime()` | Unchanged | + | `run.error()` | `run.error()` | Unchanged | + | `run.inputs()` | `run.inputs()` | Unchanged | + | `run.outputs()` | `run.outputs()` | Unchanged | + | `run.tags()` | `run.tags()` | Unchanged | + | `run.extra()` | `run.extra()` | Unchanged | + | `run.events()` | `run.events()` | Unchanged | + | `run.feedbackStats()` | `run.feedbackStats()` | Unchanged | + | `run.inputsPreview()` | `run.inputsPreview()` | Unchanged | + | `run.outputsPreview()` | `run.outputsPreview()` | Unchanged | + | `run.referenceExampleId()` | `run.referenceExampleId()` | Unchanged | + | `run.traceId()` | `run.traceId()` | Unchanged | + | `run.dottedOrder()` | `run.dottedOrder()` | Unchanged | + | `run.parentRunId()` | *(removed)* | Use `run.parentRunIds()` (list of all ancestor UUIDs, root first) | + | `run.parentRunIds()` | `run.parentRunIds()` | Unchanged | + | `run.sessionId()` | `run.projectId()` | Renamed; `sessionId()` returned the project UUID | + | `run.appPath()` | `run.appPath()` | Unchanged | + | `run.firstTokenTime()` | `run.firstTokenTime()` | Unchanged | + | `run.totalTokens()` | `run.totalTokens()` | Unchanged | + | `run.promptTokens()` | `run.promptTokens()` | Unchanged | + | `run.completionTokens()` | `run.completionTokens()` | Unchanged | + | `run.totalCost()` | `run.totalCost()` | Return type changed from `Optional` to `Optional` | + | `run.promptCost()` | `run.promptCost()` | Return type changed from `Optional` to `Optional` | + | `run.completionCost()` | `run.completionCost()` | Return type changed from `Optional` to `Optional` | + | `run.promptTokenDetails()` | `run.promptTokenDetails()` | Unchanged | + | `run.completionTokenDetails()` | `run.completionTokenDetails()` | Unchanged | + | `run.promptCostDetails()` | `run.promptCostDetails()` | Unchanged | + | `run.completionCostDetails()` | `run.completionCostDetails()` | Unchanged | + | `run.priceModelId()` | `run.priceModelId()` | Unchanged | + | `run.inDataset()` | `run.isInDataset()` | Renamed | + | `run.referenceDatasetId()` | `run.referenceDatasetId()` | Unchanged | + | `run.threadId()` | `run.threadId()` | Unchanged | + | `run.shareToken()` | *(removed)* | Use `run.shareUrl()` (full URL, only set when the run has been shared) | + | `run.childRunIds()` | *(removed)* | No equivalent | + | `run.directChildRunIds()` | *(removed)* | No equivalent | + | `run.serialized()` | *(removed)* | Use `run.manifest()` | + | `run.manifestId()` | *(removed)* | Use `run.manifest()` | + | `run.messages()` | *(removed)* | No equivalent | + | `run.executionOrder()` | *(removed)* | No equivalent | + | `run.lastQueuedAt()` | *(removed)* | No equivalent | + | `run.traceFirstReceivedAt()` | *(removed)* | No equivalent | + | `run.traceMaxStartTime()` | *(removed)* | No equivalent | + | `run.traceMinStartTime()` | *(removed)* | No equivalent | + | `run.traceTier()` | *(removed)* | No equivalent | + | `run.traceUpgrade()` | *(removed)* | No equivalent | + | `run.ttlSeconds()` | *(removed)* | No equivalent | + | *(not available)* | `run.attachments()` | New: pre-signed download URLs for attachments (replaces S3 URL fields) | + | *(not available)* | `run.latencySeconds()` | New: wall-clock duration in seconds | + | *(not available)* | `run.isRoot()` | New | + | *(not available)* | `run.errorPreview()` | New: truncated error snippet | + | *(not available)* | `run.manifest()` | New: full manifest, typed as `Optional` (replaces `serialized()` and `manifestId()`) | + | *(not available)* | `run.metadata()` | New: metadata, typed as `Optional` (was derived from `extra.metadata`) | + | *(not available)* | `run.shareUrl()` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `run.threadEvaluationTime()` | New | + + + Pass `RunGetV2ParamsSelect` constants (eg. `RunGetV2ParamsSelectName`, `RunGetV2ParamsSelectStatus`) to `Selects` to control which fields are populated; unselected fields are zero-valued on the returned struct. `Selects` defaults to `ID` only. + + | Before (`RunSchema` field) | After (`Run` field) | Notes | + |---|---|---| + | `run.ID` | `run.ID` | Unchanged | + | `run.Name` | `run.Name` | Unchanged | + | `run.RunType` | `run.RunType` | Values changed to uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `run.Status` | `run.Status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `run.TraceID` | `run.TraceID` | Unchanged | + | `run.DottedOrder` | `run.DottedOrder` | Unchanged | + | `run.AppPath` | `run.AppPath` | Unchanged | + | `run.StartTime` | `run.StartTime` | Unchanged | + | `run.EndTime` | `run.EndTime` | Unchanged | + | `run.Error` | `run.Error` | Unchanged | + | `run.Events` | `run.Events` | Unchanged; element type is now `RunEvent` (was `map[string]interface{}`) | + | `run.Extra` | `run.Extra` | Unchanged; type is now `interface{}` (was `map[string]interface{}`) | + | `run.FeedbackStats` | `run.FeedbackStats` | Unchanged; element type is now `RunFeedbackStat` | + | `run.FirstTokenTime` | `run.FirstTokenTime` | Unchanged | + | `run.Inputs` | `run.Inputs` | Unchanged; type is now `interface{}` (was `map[string]interface{}`) | + | `run.InputsPreview` | `run.InputsPreview` | Unchanged | + | `run.Outputs` | `run.Outputs` | Unchanged; type is now `interface{}` (was `map[string]interface{}`) | + | `run.OutputsPreview` | `run.OutputsPreview` | Unchanged | + | `run.ParentRunIDs` | `run.ParentRunIDs` | Unchanged | + | `run.PriceModelID` | `run.PriceModelID` | Unchanged | + | `run.PromptCost` | `run.PromptCost` | Unchanged | + | `run.PromptCostDetails` | `run.PromptCostDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]float64` (was `map[string]string`) | + | `run.PromptTokenDetails` | `run.PromptTokenDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]int64` (element type unchanged) | + | `run.PromptTokens` | `run.PromptTokens` | Unchanged | + | `run.CompletionCost` | `run.CompletionCost` | Unchanged | + | `run.CompletionCostDetails` | `run.CompletionCostDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]float64` (was `map[string]string`) | + | `run.CompletionTokenDetails` | `run.CompletionTokenDetails.Raw` | Field now wraps the map; access `.Raw` to get `map[string]int64` (element type unchanged) | + | `run.CompletionTokens` | `run.CompletionTokens` | Unchanged | + | `run.TotalCost` | `run.TotalCost` | Unchanged | + | `run.TotalTokens` | `run.TotalTokens` | Unchanged | + | `run.ReferenceDatasetID` | `run.ReferenceDatasetID` | Unchanged | + | `run.ReferenceExampleID` | `run.ReferenceExampleID` | Unchanged | + | `run.Tags` | `run.Tags` | Unchanged | + | `run.ThreadID` | `run.ThreadID` | Unchanged | + | `run.SessionID` | `run.ProjectID` | Renamed | + | `run.InDataset` | `run.IsInDataset` | Renamed | + | `run.ChildRunIDs` | *(removed)* | No equivalent | + | `run.DirectChildRunIDs` | *(removed)* | No equivalent | + | `run.ExecutionOrder` | *(removed)* | No equivalent | + | `run.InputsS3URLs` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.LastQueuedAt` | *(removed)* | No equivalent | + | `run.ManifestID` | *(removed)* | Use `run.Manifest` | + | `run.ManifestS3ID` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.Messages` | *(removed)* | No equivalent | + | `run.OutputsS3URLs` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.ParentRunID` | *(removed)* | Use `run.ParentRunIDs` | + | `run.S3URLs` | *(removed)* | Internal storage URL; not exposed in v2 | + | `run.Serialized` | *(removed)* | Use `run.Manifest` | + | `run.ShareToken` | *(removed)* | Use `run.ShareURL` | + | `run.TraceFirstReceivedAt` | *(removed)* | No equivalent | + | `run.TraceMaxStartTime` | *(removed)* | No equivalent | + | `run.TraceMinStartTime` | *(removed)* | No equivalent | + | `run.TraceTier` | *(removed)* | No equivalent | + | `run.TraceUpgrade` | *(removed)* | No equivalent | + | `run.TtlSeconds` | *(removed)* | No equivalent | + | *(not available)* | `run.Attachments` | New: maps attachment filename to pre-signed download URL | + | *(not available)* | `run.ErrorPreview` | New: truncated error snippet | + | *(not available)* | `run.IsRoot` | New | + | *(not available)* | `run.LatencySeconds` | New: wall-clock duration in seconds | + | *(not available)* | `run.Manifest` | New: full manifest object (replaces `Serialized` and `ManifestID`) | + | *(not available)* | `run.Metadata` | New: arbitrary user-defined JSON metadata | + | *(not available)* | `run.ShareURL` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `run.ThreadEvaluationTime` | New | + + + Pass SCREAMING_SNAKE_CASE strings as repeated `selects` query parameters (eg. `selects=NAME&selects=STATUS`) to control which fields are populated. Default `selects` contains only `"ID"`. + + | Before (v1 response field) | After (v2 response field) | Notes | + |---|---|---| + | `id` | `id` | Unchanged | + | `name` | `name` | Unchanged | + | `run_type` | `run_type` | Values changed to uppercase: `"LLM"`, `"CHAIN"`, etc. | + | `status` | `status` | Values: `"SUCCESS"`, `"ERROR"`, `"PENDING"` | + | `trace_id` | `trace_id` | Unchanged | + | `dotted_order` | `dotted_order` | Unchanged | + | `app_path` | `app_path` | Unchanged | + | `start_time` | `start_time` | Unchanged | + | `end_time` | `end_time` | Unchanged | + | `error` | `error` | Unchanged | + | `events` | `events` | Unchanged | + | `extra` | `extra` | Unchanged | + | `feedback_stats` | `feedback_stats` | Unchanged | + | `first_token_time` | `first_token_time` | Unchanged | + | `inputs` | `inputs` | Unchanged | + | `inputs_preview` | `inputs_preview` | Unchanged | + | `outputs` | `outputs` | Unchanged | + | `outputs_preview` | `outputs_preview` | Unchanged | + | `parent_run_ids` | `parent_run_ids` | Unchanged | + | `price_model_id` | `price_model_id` | Unchanged | + | `prompt_cost` | `prompt_cost` | Unchanged | + | `prompt_cost_details` | `prompt_cost_details.raw` | Field now wraps the object; read `.raw` for the same `{category: cost}` mapping, now with numeric values (was strings) | + | `prompt_token_details` | `prompt_token_details.raw` | Field now wraps the object; read `.raw` for the same `{category: count}` mapping (values unchanged) | + | `prompt_tokens` | `prompt_tokens` | Unchanged | + | `completion_cost` | `completion_cost` | Unchanged | + | `completion_cost_details` | `completion_cost_details.raw` | Field now wraps the object; read `.raw` for the same `{category: cost}` mapping, now with numeric values (was strings) | + | `completion_token_details` | `completion_token_details.raw` | Field now wraps the object; read `.raw` for the same `{category: count}` mapping (values unchanged) | + | `completion_tokens` | `completion_tokens` | Unchanged | + | `total_cost` | `total_cost` | Unchanged | + | `total_tokens` | `total_tokens` | Unchanged | + | `reference_dataset_id` | `reference_dataset_id` | Unchanged | + | `reference_example_id` | `reference_example_id` | Unchanged | + | `tags` | `tags` | Unchanged | + | `thread_id` | `thread_id` | Unchanged | + | `session_id` | `project_id` | Renamed | + | `in_dataset` | `is_in_dataset` | Renamed | + | `child_run_ids` | *(removed)* | No equivalent | + | `direct_child_run_ids` | *(removed)* | No equivalent | + | `execution_order` | *(removed)* | No equivalent | + | `inputs_s3_urls` | *(removed)* | Internal storage URL; not exposed in v2 | + | `last_queued_at` | *(removed)* | No equivalent | + | `manifest_id` | *(removed)* | Use `manifest` | + | `manifest_s3_id` | *(removed)* | Internal storage URL; not exposed in v2 | + | `messages` | *(removed)* | No equivalent | + | `outputs_s3_urls` | *(removed)* | Internal storage URL; not exposed in v2 | + | `parent_run_id` | *(removed)* | Use `parent_run_ids` | + | `s3_urls` | *(removed)* | Internal storage URL; not exposed in v2 | + | `serialized` | *(removed)* | Use `manifest` | + | `share_token` | *(removed)* | Use `share_url` | + | `trace_first_received_at` | *(removed)* | No equivalent | + | `trace_max_start_time` | *(removed)* | No equivalent | + | `trace_min_start_time` | *(removed)* | No equivalent | + | `trace_tier` | *(removed)* | No equivalent | + | `trace_upgrade` | *(removed)* | No equivalent | + | `ttl_seconds` | *(removed)* | No equivalent | + | *(not available)* | `attachments` | New: maps attachment filename to pre-signed download URL | + | *(not available)* | `error_preview` | New: truncated error snippet | + | *(not available)* | `is_root` | New | + | *(not available)* | `latency_seconds` | New: wall-clock duration in seconds | + | *(not available)* | `manifest` | New: full manifest object (replaces `serialized` and `manifest_id`) | + | *(not available)* | `metadata` | New: previously nested under `extra.metadata` | + | *(not available)* | `share_url` | New: public share URL (only set when the run has been shared) | + | *(not available)* | `thread_evaluation_time` | New | + + + +### Examples + +#### Fetch a single run by ID + + + + `runs.retrieve` requires two additional parameters that `read_run` did not need: `project_id` (UUID) and `start_time`. Both are required by the SmithDB storage model to locate a run efficiently. Resolve the project UUID via `client.projects.list()` first. + + + + + + + + + + + + + `client.runs.retrieve` requires two additional parameters that `readRun` did not need: `project_id` (UUID) and `start_time`. Both are required by the SmithDB storage model to locate a run efficiently. Resolve the project UUID via `client.projects.list()` first. + + + + + + + + + + + + + `retrieveV2()` requires two additional parameters that `client.runs().retrieve()` did not need: `projectId()` (UUID) and `startTime()`. Both are required by the SmithDB storage model to locate a run efficiently. Resolve the project UUID via `client.sessions().list()` first. + + + + + + + + + + + + + `GetV2()` requires two additional parameters that `client.Runs.Get()` did not need: `ProjectID` (UUID) and `StartTime`. Both are required by the SmithDB storage model to locate a run efficiently. Resolve the project UUID via `client.Sessions.List()` first. + + + + + + + + + + + + + `GET /v2/runs/{run_id}` requires two additional query parameters that `GET /api/v1/runs/{run_id}` did not need: `project_id` (UUID) and `start_time`. Both are required by the SmithDB storage model to locate a run efficiently. Resolve the project UUID via a `GET /api/v1/sessions` request first. + + + + + + + + + + + + + +#### Selecting fields + + + + `read_run` returns a full run object with no selection needed. `runs.retrieve` returns only `id` by default—pass `selects=[...]` to request more. + + Requires `langsmith>=0.9.6`. + + + + + + + + + + + + `readRun` returns a full run object with no selection needed. `client.runs.retrieve` returns only `id` by default—pass `selects: [...]` to request more. + + Requires `langsmith@>=0.7.15`. + + + + + + + + + + + + `.retrieve()` returns a full run object with no selection needed. `.retrieveV2()` returns only `id` by default—call `.addSelect(...)` for each field you need. + + Requires `langsmith-java` 0.1.0-beta.11. + + + + + + + + + + + + `Get` returns a full run struct with no selection needed. `GetV2` returns only `ID` by default—pass `Selects` with the fields you need. + + Requires `langsmith-go` v0.17.0. + + + + + + + + + + + + `GET /api/v1/runs/{run_id}` returns a full run object with no selection needed. `GET /v2/runs/{run_id}` returns only `id` by default—pass `selects` query parameters for the fields you need. + + + + + + + + + + + + diff --git a/uv.lock b/uv.lock index b28913914..27a36c12c 100644 --- a/uv.lock +++ b/uv.lock @@ -662,6 +662,7 @@ dependencies = [ { name = "langgraph" }, { name = "langgraph-checkpoint-postgres" }, { name = "langgraph-checkpoint-sqlite" }, + { name = "langsmith" }, { name = "markdownify" }, { name = "nbconvert" }, { name = "nbformat" }, @@ -706,6 +707,7 @@ requires-dist = [ { name = "langgraph", specifier = ">=1.2.5" }, { name = "langgraph-checkpoint-postgres" }, { name = "langgraph-checkpoint-sqlite", specifier = ">=3.1.0" }, + { name = "langsmith", specifier = ">=0.9.6" }, { name = "markdownify", specifier = ">=0.13.0" }, { name = "nbconvert", specifier = ">=7.17.1" }, { name = "nbformat", specifier = ">=5.0.0" }, @@ -1376,23 +1378,27 @@ wheels = [ [[package]] name = "langsmith" -version = "0.8.18" +version = "0.9.6" source = { registry = "https://pypi.org/simple" } dependencies = [ + { name = "anyio" }, + { name = "distro" }, { name = "httpx" }, { name = "orjson", marker = "platform_python_implementation != 'PyPy'" }, { name = "packaging" }, { name = "pydantic" }, { name = "requests" }, { name = "requests-toolbelt" }, + { name = "sniffio" }, + { name = "typing-extensions" }, { name = "uuid-utils" }, { name = "websockets" }, { name = "xxhash" }, { name = "zstandard" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/9a/d9/a6681aa9847bbbc5ec21abe20a5e233b94e5edcfe39624db607ac7e8ccb4/langsmith-0.8.18.tar.gz", hash = "sha256:32dde9c0e67e053e0fb738921fc8ced768af7b8fa83d7a0e3fd63597cf8776dd", size = 4526988, upload-time = "2026-06-19T13:12:17.123Z" } +sdist = { url = "https://files.pythonhosted.org/packages/85/dc/ca2ab3b74f3a5a2089aee1483e86b6aa7ae15fba96f73866a16e31356319/langsmith-0.9.6.tar.gz", hash = "sha256:1df590a40352b2f40a36229d90e2ef6af276a0bc9f1e44a87b829f879eed2130", size = 4714803, upload-time = "2026-07-02T11:14:30.636Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/03/70/0e0cc80a3b064c8d6c8d697c3125ed86e39d5a7393ec6dc8b07cb1cf13c4/langsmith-0.8.18-py3-none-any.whl", hash = "sha256:3940183349993faef48e6c7d08e4822ee9cefd906b362d0e3c2d650314d2f282", size = 508108, upload-time = "2026-06-19T13:12:15.348Z" }, + { url = "https://files.pythonhosted.org/packages/bf/8f/6e8f1f3e12be9848993c297c879f63f225361eb594f8343ff42c2b26c6fd/langsmith-0.9.6-py3-none-any.whl", hash = "sha256:c5e5f2425dcb8fe363b9e1fa87a9cb9cf5631389bf7e168aa4f325f580ca284c", size = 660131, upload-time = "2026-07-02T11:14:28.552Z" }, ] [[package]]