Skip to content

langchain-samples/litellm-agents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple ReAct Agent with LangGraph + LiteLLM

A clean ReAct pattern implementation using LangGraph and LiteLLM with automatic LangSmith tracing.

Features

  • Universal LLM Support via LiteLLM (OpenAI, Anthropic, Gemini, etc.)
  • LangSmith Tracing with custom wrap_litellm() wrapper (similar to wrap_openai())
  • ReAct Pattern for tool-augmented reasoning
  • Simple example tools: weather lookup and calculator

Quick Start

# Install
uv sync

# Configure
cp .env.example .env
# Edit .env with your API key and model choice

# Run
python agent.py

LiteLLM Wrapper

Reusable wrapper for automatic LangSmith tracing of LiteLLM calls:

from litellm_wrapper import wrap_litellm
import litellm

wrap_litellm(name="LiteLLM")

# All calls now traced automatically
response = await litellm.acompletion(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}]
)

Features:

  • Traces litellm.completion() and litellm.acompletion()
  • Appears in LangSmith with run_type="llm"
  • Captures model, temperature, and metadata

Project Structure

  • agent.py - Main ReAct agent
  • litellm_wrapper.py - LangSmith wrapper for LiteLLM
  • utils.py - Message conversion helpers
  • test_wrapper.py - Standalone wrapper demo
  • annotate.py - Script to add feedback to recent traces
  • sampling.py - Demonstrate configurable sampling rates

Configurable Sampling Rates

Use sampling.py to see how different sampling rates work:

python sampling.py

This demonstrates:

  • Running the agent with different sampling rates (100%, 50%, 25%, 0%)
  • Using tracing_context to control sampling per-operation
  • Balancing observability vs. cost in production

Adding Feedback to Traces

Use annotate.py to add feedback scores to recent traces:

python annotate.py

This demonstrates how to use the LangSmith SDK to:

  • Retrieve recent traces from a project
  • Attach multiple feedback scores to each run (helpfulness & correctness)
  • View and analyze feedback in the LangSmith dashboard

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages