GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — braintrust-sdk-python/examples/langchain at main · braintrustdata/braintrust-sdk-python

Expand file tree

/

langchain

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

langchain

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
README.md
README.md
 
 
anthropic_prompt_cache.py
anthropic_prompt_cache.py
 
 
example.py
example.py
 
 
pyproject.toml
pyproject.toml
 
 

README.md

Outline

LangChain + Braintrust

Calls braintrust.auto_instrument(), which patches langchain_core.tracers.context to install a global BraintrustCallbackHandler. After that, every chain run is traced with no config={"callbacks": [...]} plumbing required — the trace shows the RunnableSequence task span with ChatPromptTemplate and ChatOpenAI children.

Run

export BRAINTRUST_API_KEY=...
export OPENAI_API_KEY=...

uv sync
uv run python example.py

Anthropic prompt-cache metrics demo

Use it to verify cache reads/writes and token totals on real Braintrust spans.

# Loads BRAINTRUST_API_KEY and ANTHROPIC_API_KEY from ../../.env automatically.
uv sync
uv run python anthropic_prompt_cache.py

To inspect the logged spans with the Braintrust CLI:

bt projects list --json | jq '.[] | select(.name == "z-abhi-langchain-anthropic-cache-demo")'
bt view logs --object-ref project_logs:<project-id> --list-mode spans --limit 10 --json
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.