Single Step | LangSmith Evaluation - Part 25

LangChain · Beginner ·🧠 Large Language Models ·2y ago

Key Takeaways

LangChain's LSmith evaluation series covers agent evaluation, focusing on evaluating a single step in an agent, specifically the tool calling process in LangGraph agents, using a simple evaluation function to check if the LLM calls the correct tool.

Full Transcript

hey this is l l chain we're continuing our lsmith evaluation series talking about agent evaluation so in the last video I kind of gave a deep dive into General structure of agents and Tool calling and um how agents can be laid out um so we talked about Lang graph agent and this is kind of the classical kind of langra agent layout where you have a tool calling llm with some bound tools input the llm makes a decision to use a tool or not if it uses a tool that goes to a different node this tool node that actually runs the tool Returns the tool output to the llm and this continues until LM just returns a text response and doesn't choose to call tool anymore so that's like a very basic agent architecture you can put together with Lang graph and we talked about three types of eval so one type of eval is evaluating the final response which is we talk through in detail now the second thing you can do is think about evaluating a single step in this agent so typically what this looks like is you might evaluate given an input do I call the right tool so let's show how to let kind of blid that out again when we look at tool use right really what you're doing is you have an llm you're binding a tool to it or so a set of tools typically and given an input you're just kind of checking whether or not the right tool is called so this is actually really useful especially because so many different llms right now have tool calling you may want to evaluate like how well is it actually working in my case with my tools so this is a really good eval to think about now this is The Notebook we already talked through so just in case you hadn't seen it yet this basically sets up uh a lang graph agent for SQL so I'm using chin chinuk DB um so this is kind of all the code we already talked through this is basically setting up my Lang graph agent this is kind of defining all the different tools I want so I'm using the SQL toolkit um and I'm defining two custom tools right here this query Checker uh and then this result Checker so those are my tools I Define my state I Define my agent and again we talked through this already so you know you can proceed the prior video if you wanted to see a little bit more explanation here lay out my graph and there you go you can see the graph we always showed how you can run this as a test now we just talk through response evaluation and for that we built a data set of question answer pairs okay so that's what we have now let's talk about this single tool evaluation so for this what's kind of nice is I don't even really need my agent all I need is basically just that llm tool invocation I can test that in isolations that's a nice little component I can I can test so this function basically just wraps that assistant runnable is basically you can go back and look that is basically just our SQL agent so or or sorry I should be more clear that is the llm that's part of our agent so that is this piece okay llm tool to use and you can see you you put it in our agent like this so you have the llm it gets a prompt it makes decisions whether or not to use a tool and Lang graph orchestrates this by basically connecting this llm piece to a tool to node so this is like kind of your assistant node tool node and this goes in a circle but the key thing is that llm node needs to be able to use choose the right tool at the right time so that's something you may absolutely want to evaluate okay so that's that's what this runnable is this is basically that llm node and isolation first I def find this very simple function that wraps my assistant runnable which we just talked through so again that assistant runnable uh is basically just going to uh invoke tool use or not so I'm going to basically pass example questions from my data set which we talked about previously so I have five different questions related to my database I'm going to pass each example into my runnable right here and I'll get some result out now again if you look at our diagram here that result is either going to be a tool call or just a response of some type okay and all I'm going to do is in my evaluation function I'm just going to go ahead and grab that response so that's what you see here and I'm going to extract the tool call if there is one now there may not be but that's fine I just try to catch it so if there's a tool call I get it and I compare the tool call to what I expected that's all I'm doing one if if it's correct else zero so this is a really simple way to build a custom evaluator that basically looks at whether or not the tool called by your llm matches the tool you expect and this is very generally useful you can use this with you know many different llms that offer tool calling um so I can go ahead and kick off an evaluation so again I'm just passing in my function here I'm passing in my data set name I'm passing in my custom evaluator that's all I need I go to my data set look at my experiments great and ran so I can look at all my examples and here I can look at this is just like the raw output of my of my uh llm and you can see here's the input the output is indeed a tool call and it's calling the SQL DB list tables which is exactly what we want so basically the way to think about this is for our particular agent for any input question the first thing we've instructed to do is hit the SQL DB to list the tables okay so for all cases we expect this is the tool that it'll call so that's just a really nice simple thing and I've hardcoded that in my evaluation function if I go back and look I can see one one one one so these are my single tool call scores and they're all correct so basically my agent or in this case it's just my llm I'm testing in isolation is correctly for every input question calling uh that SQL DB list tables you can see them all right here so this is a good example of a really simple uh single step evaluation you can do um in my particular case I always expected for any of input question that this tool will be called and so that's why I can hardcode it now you can also be more sophisticated here because you could put this tool name in your eval set as a reference and then for if for example if different questions or prompts basically elicited different tools you can encode all that and very simply run that evaluation as well so this is showing like the simplest case where you hardcode your tool call but you can absolutely do more sophisticated things like basically put this tool call in your uh in your data set as a reference you could run the eval that way so again really simple very useful eval and very useful for evaluating different llms that all offer tool calling thanks

Original Description

With the rapid pace of AI, developers are often faced with a paradox of choice: how to choose the right prompt, how to trade-off LLM quality vs cost? Evaluations can accelerate development with structured process for making these decisions. But, we've heard that it is challenging to get started. So, we are launching a series of short videos focused on explaining how to perform evaluations using LangSmith. This video focuses on agent evaluation and specifically on single step evaluation. Agents generally perform multiple actions. While it is useful to evaluate them end-to-end, it can also be useful to evaluate these individual actions. This generally involves evaluating a single step of the agent - the LLM call where it decides what to do. Concept: https://docs.smith.langchain.com/concepts/evaluation#agents Code: https://docs.smith.langchain.com/tutorials/Developers/agents
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from LangChain · LangChain · 0 of 60

← Previous Next →
1 Chat With Your Documents Using LangChain + JavaScript
Chat With Your Documents Using LangChain + JavaScript
LangChain
2 LangChain SQL Webinar
LangChain SQL Webinar
LangChain
3 LangChain "OpenAI functions" Webinar
LangChain "OpenAI functions" Webinar
LangChain
4 LangSmith Launch
LangSmith Launch
LangChain
5 LangChain x Pinecone: Supercharging Llama-2 with RAG
LangChain x Pinecone: Supercharging Llama-2 with RAG
LangChain
6 LangChain Expression Language
LangChain Expression Language
LangChain
7 Building LLM applications with LangChain with Lance
Building LLM applications with LangChain with Lance
LangChain
8 Benchmarking Question/Answering Over CSV Data
Benchmarking Question/Answering Over CSV Data
LangChain
9 LangChain "RAG Evaluation" Webinar
LangChain "RAG Evaluation" Webinar
LangChain
10 Fine-tuning in Your Voice Webinar
Fine-tuning in Your Voice Webinar
LangChain
11 Tabular Data Retrieval
Tabular Data Retrieval
LangChain
12 Building an LLM Application with Audio by AssemblyAI
Building an LLM Application with Audio by AssemblyAI
LangChain
13 Superagent Deepdive Webinar
Superagent Deepdive Webinar
LangChain
14 Lessons from Deploying LLMs with LangSmith
Lessons from Deploying LLMs with LangSmith
LangChain
15 Shortwave Assistant Deepdive Webinar
Shortwave Assistant Deepdive Webinar
LangChain
16 Cognitive Architectures for Language Agents
Cognitive Architectures for Language Agents
LangChain
17 Effectively Building with LLMs in the Browser with Jacob
Effectively Building with LLMs in the Browser with Jacob
LangChain
18 Data Privacy for LLMs
Data Privacy for LLMs
LangChain
19 "Theory of Mind" Webinar with Plastic Labs
"Theory of Mind" Webinar with Plastic Labs
LangChain
20 LangChain Templates
LangChain Templates
LangChain
21 Using Natural Language to Query Postgres with Jacob
Using Natural Language to Query Postgres with Jacob
LangChain
22 Building a Research Assistant from Scratch
Building a Research Assistant from Scratch
LangChain
23 Benchmarking RAG over LangChain Docs
Benchmarking RAG over LangChain Docs
LangChain
24 Skeleton-of-Thought: Building a New Template from Scratch
Skeleton-of-Thought: Building a New Template from Scratch
LangChain
25 Benchmarking Methods for Semi-Structured RAG
Benchmarking Methods for Semi-Structured RAG
LangChain
26 LangSmith Highlights: Getting Started
LangSmith Highlights: Getting Started
LangChain
27 LangSmith Highlights: Debugging
LangSmith Highlights: Debugging
LangChain
28 LangSmith Highlights: Datasets
LangSmith Highlights: Datasets
LangChain
29 LangSmith Highlights: Evaluation
LangSmith Highlights: Evaluation
LangChain
30 LangSmith Highlights: Human Annotation
LangSmith Highlights: Human Annotation
LangChain
31 LangSmith Highlights: Monitoring
LangSmith Highlights: Monitoring
LangChain
32 LangSmith Highlights: Hub
LangSmith Highlights: Hub
LangChain
33 SQL Research Assistant
SQL Research Assistant
LangChain
34 Getting Started with Multi-Modal LLMs
Getting Started with Multi-Modal LLMs
LangChain
35 Build a Full Stack RAG App With TypeScript
Build a Full Stack RAG App With TypeScript
LangChain
36 Auto-Prompt Builder (with Hosted LangServe)
Auto-Prompt Builder (with Hosted LangServe)
LangChain
37 LangChain v0.1.0 Launch: Introduction
LangChain v0.1.0 Launch: Introduction
LangChain
38 LangChain v0.1.0 Launch: Observability
LangChain v0.1.0 Launch: Observability
LangChain
39 LangChain v0.1.0 Launch: Integrations
LangChain v0.1.0 Launch: Integrations
LangChain
40 LangChain v0.1.0 Launch: Composability
LangChain v0.1.0 Launch: Composability
LangChain
41 LangChain v0.1.0 Launch: Streaming
LangChain v0.1.0 Launch: Streaming
LangChain
42 LangChain v0.1.0 Launch: Output Parsing
LangChain v0.1.0 Launch: Output Parsing
LangChain
43 LangChain v0.1.0 Launch: Retrieval
LangChain v0.1.0 Launch: Retrieval
LangChain
44 LangChain v0.1.0 Launch: Agents
LangChain v0.1.0 Launch: Agents
LangChain
45 Build and Deploy a RAG app with Pinecone Serverless
Build and Deploy a RAG app with Pinecone Serverless
LangChain
46 Hosted LangServe + LangChain Templates
Hosted LangServe + LangChain Templates
LangChain
47 LangGraph: Intro
LangGraph: Intro
LangChain
48 LangGraph: Agent Executor
LangGraph: Agent Executor
LangChain
49 LangGraph: Chat Agent Executor
LangGraph: Chat Agent Executor
LangChain
50 LangGraph: Human-in-the-Loop
LangGraph: Human-in-the-Loop
LangChain
51 LangGraph: Dynamically Returning a Tool Output Directly
LangGraph: Dynamically Returning a Tool Output Directly
LangChain
52 LangGraph: Respond in a Specific Format
LangGraph: Respond in a Specific Format
LangChain
53 LangGraph: Managing Agent Steps
LangGraph: Managing Agent Steps
LangChain
54 LangGraph: Force-Calling a Tool
LangGraph: Force-Calling a Tool
LangChain
55 LangGraph: Multi-Agent Workflows
LangGraph: Multi-Agent Workflows
LangChain
56 Streaming Events: Introducing a new `stream_events` method
Streaming Events: Introducing a new `stream_events` method
LangChain
57 Building a web RAG chatbot: using LangChain, Exa (prev. Metaphor), LangSmith, and Hosted Langserve
Building a web RAG chatbot: using LangChain, Exa (prev. Metaphor), LangSmith, and Hosted Langserve
LangChain
58 OpenGPTs
OpenGPTs
LangChain
59 Open Source RAG with Nomic's New Embedding Model (and ChromaDB and Ollama)
Open Source RAG with Nomic's New Embedding Model (and ChromaDB and Ollama)
LangChain
60 LangGraph: Persistence
LangGraph: Persistence
LangChain

This video teaches how to evaluate a single step in an LLM agent, specifically the tool calling process, using a simple evaluation function to check if the LLM calls the correct tool. It demonstrates how to set up a LangGraph agent, define custom tools, and run a single step evaluation.

Key Takeaways
  1. Set up a LangGraph agent
  2. Define custom tools
  3. Create a data set of question-answer pairs
  4. Define an evaluation function to check tool calls
  5. Run the evaluation on the data set
💡 Evaluating a single step in an LLM agent, such as tool calling, can be done using a simple evaluation function to check if the LLM calls the correct tool.

Related Reads

📰
🚀 Day 3 of 100 Days of GenAI for DevOps is LIVE!
Learn how to estimate GPU memory needs for Large Language Models (LLMs) and optimize deployment as a DevOps engineer
Dev.to AI
📰
Unlocking Open-Weight LLMs: A Developer's Guide to Seamless API Integration
Learn to integrate Open-Weight LLMs into your applications using seamless API integration and unlock new possibilities for natural language processing
Dev.to · NovaStack
📰
We Built AI Using Wikipedia, But Wikipedia Is 40% Wrong
Learn how AI built using Wikipedia can be flawed due to the platform's inaccuracies and why this matters for AI development
Medium · Machine Learning
📰
LLM vs RAG Explained (EP2): How AI Actually Finds the Right Answers
Learn how LLMs and RAGs work together to help AI find the right answers, and why they sometimes get things wrong
Medium · Data Science
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →