Agent Trajectory | LangSmith Evaluation - Part 26

LangChain
20 Jun 202408:14

Summary

TLDRランスがLance Chainの第3回目のビデオで、エージェントの評価方法について解説。これまでは回答の評価や単一のツールコールの評価に焦点を当てたが、今回は期待されるツールコールの順序や軌跡を評価する方法を紹介。SQLエージェントを評価対象として、ツールの呼び出し順序を正確に評価する方法を説明。カスタムエバリュエータを使用して、正確な順序や順序が保たれる範囲内で挿入が許される場合の評価を実演。実際のツール軌跡を分析し、エージェントが誤ったツールを誤認識している問題を特定。この評価手法により、エージェントの改善点を見つけ出し、最適化の方向性を示す。

Takeaways

  • 😀 エージェントの評価方法についての第3回目のビデオで、SQLエージェントを評価するケーススタディとして使用している。
  • 🔍 これまでに回答の評価や単一のツールコールの評価について話していた。今回は、期待されるシーケンスまたは軌跡に対するツールコールのシーケンスの評価について説明する。
  • 🛠️ ランチェーンのエージェントは、SQLデータベースと対話するためのステップを明示的に実行する。
  • 📝 エージェントのフローは、テーブルのリストを取得、スキーマを取得、クエリを生成、チェック、実行、エラーがないか確認、そしてエラーがなければ自然言語で応答する。
  • 🔄 ツールコールの軌跡を評価する方法は、期待されるツールのセットを見つけることから始まる。
  • 👀 カスタムエバリュエーターを使用して、ツールコールの正確性や順序を評価することができる。
  • 🔢 評価では、正確な一致を確認するシンプルな方法や、順序を保持しながら挿入が許されるより緩やかな方法の両方を提供している。
  • 📊 評価結果は、ツールコールの軌跡をログに記録し、分析することで得られる。
  • 🤖 エージェントは、期待される軌跡と異なるツールコールを挿入することがあることがわかった。
  • 💡 評価プロセスでは、エージェントが誤ったツールコールを行った場合にそれを特定し、修正する方法を見つけることができる。
  • 🔧 次回のビデオでは、このような問題を修正する方法について説明する予定である。

Q & A

  • ランスが紹介したエージェントの評価方法は何ですか?

    -ランスは、エージェントの評価方法として、参照に対するエージェントの回答の評価、期待されるツールコールに対する単一のエージェントツールコールの評価、そして期待されるシーケンスまたは軌道に対するツールコールのシーケンスの評価について話しました。

  • SQLエージェントのステップはどのように定義されていますか?

    -SQLエージェントは、テーブルのリストを取得し、スキーマを取得し、クエリを生成し、チェックし、実行し、実行中にエラーがないか確認し、エラーがなければ自然言語で応答するというステップを定義しています。

  • ツールコールの軌道評価とは何を意味しますか?

    -ツールコールの軌道評価とは、エージェントが呼び出すツールのセットが期待される順序に従っているかどうかを評価することを意味します。

  • ランスが使用するカスタムエバリュエーターとは何ですか?

    -ランスが使用するカスタムエバリュエーターは、ツールコールの正確な一致を確認するものと、順序が保たれているが中間に挿入が許されるものがあります。

  • エージェントが期待されるツールの順序をどのように特定しますか?

    -ランスは、期待されるツールの順序を特定するために、ツールのリストから各ツールを抽出し、それらを順序に従って評価します。

  • エージェントのメッセージ履歴からツールコールをどのように抽出するのですか?

    -ランスは、エージェントのメッセージ履歴を取得し、その履歴からツールコールを抽出する関数を使用して、ツールコールを特定します。

  • ランスが示したツールの軌道のログとは何ですか?

    -ツールの軌道のログとは、エージェントが実行したツールコールのシーケンスを記録したものであり、そのログを分析することでエージェントの動作を評価することができます。

  • エージェントが誤ったツールコールを挿入する理由は何ですか?

    -ランスの分析では、エージェントが誤ったツールコールを挿入する理由として、そのツールが実際に存在しないものであることが示されており、エージェントがそのツールを幻想した可能性があるとされています。

  • 評価結果から得られる洞察は何ですか?

    -評価結果からは、エージェントが期待される順序に従っているかどうかを確認できるだけでなく、幻想されたツールコールが挿入されるという不正な動作が存在する可能性があることが洞察できます。

  • ランスが今後のエージェントの改善に取り組む点とは何ですか?

    -ランスは、エージェントが幻想したツールコールを挿入する問題を解決し、より最適化されたエージェントの動作を目指す改善に取り組む予定です。

  • この評価方法が役立つ状況とはどのような時ですか?

    -この評価方法は、エージェントのツールコールの軌道を詳細に分析し、期待される動作と実際の動作のギャップを特定するのに役立ちます。

Outlines

00:00

😲 エージェントの評価:ツール呼び出しの正確性

ランスは、SQLエージェントの評価方法について説明しています。このビデオでは、ツール呼び出しのシーケンスを期待されるシーケンスと比較して評価する方法に焦点を当てています。エージェントは、テーブルのリストやスキーマの取得、クエリの生成、実行、エラーチェックを実行し、エラーがなければ自然言語で応答するという一連のステップを実行することが期待されています。評価では、エージェントが呼び出したツールのセットを比較し、正確に従われたかどうかを確認します。

05:01

🔍 ツール呼び出しのトラジェクトリーの評価

このセクションでは、ツール呼び出しのトラジェクトリーを評価するためのカスタムエバリュエータの使用方法について説明されています。ランスは、ツール呼び出しの正確な順序を確認するだけでなく、誤ったツールが誤って呼び出される可能性があることを指摘しています。実際の評価では、期待されるツールの順序に従っているかどうか、または誤ったツールが挿入された場合でも順序が維持されているかどうかをチェックしています。このプロセスにより、エージェントが誤ったツールを誤って認識するという興味深いエラーを特定できました。

Mindmap

Keywords

💡エージェント評価

エージェント評価とは、人工知能エージェントの性能や正確性を測定するプロセスのことです。このビデオでは、SQLエージェントのツール呼び出しの順序を評価する方法について説明しており、その正確性や期待される動作パターンに従っているかを検証する主なテーマです。例えば、「このビデオでは、エージェントが期待されるツールの順序に従っているかを評価する」と述べています。

💡ツール呼び出し

ツール呼び出しは、エージェントが特定のタスクを実行するために使用する機能やメソッドを指します。ビデオでは、SQLエージェントがデータベースと対話する際に必要な一連のツール呼び出しステップを明確にし、それらのステップが正確に実行されるかを評価しています。例えば、「ツール呼び出しの順序」が期待される動作パターンとして挙げられています。

💡期待されるツールの順序

期待されるツールの順序とは、エージェントが特定のタスクを正しく実行するために、呼び出すべき一連のツールの正しい順序です。ビデオでは、SQLリストテーブル、スキーマ取得、クエリ実行、最終回答の提出という一連のステップが期待される順序として説明されています。

💡カスタムエバリュエータ

カスタムエバリュエータは、特定の評価基準や条件に従ってエージェントの動作を評価するための独自の関数やメカニズムです。ビデオでは、ツール呼び出しの正確性や順序を評価するためにカスタムエバリュエータを使用する方法が紹介されており、それによってエージェントの動作を詳細に分析できます。

💡メッセージ履歴

メッセージ履歴は、エージェントがタスクを実行する過程で生成された一連のメッセージや応答を指します。ビデオでは、エージェントのメッセージ履歴からツール呼び出しを抽出し、それが期待される順序と一致しているかを評価するプロセスが説明されています。

💡正確な一致

正確な一致は、エージェントのツール呼び出しが期待されるリストと完全に一致していることを指します。ビデオでは、正確な一致を評価するカスタムエバリュエータを使用して、エージェントの動作が期待通りであるかを判断する例が示されています。

💡挿入許容順序

挿入許容順序とは、ツール呼び出しが期待される順序を保持しながら、途中に追加のツール呼び出しが挿入されることが許容される評価基準です。ビデオでは、この順序を評価するカスタムエバリュエータを使用して、より寛容な評価基準でのエージェントの動作を分析しています。

💡ハローケーション

ハローケーションは、エージェントが存在しないものと誤解したり、実際のデータや状況と一致しないものを生成することを指します。ビデオでは、エージェントが「SQL DB query」という存在しないツールを呼び出すというハローケーションが発生していることが示されています。

💡トレース

トレースは、エージェントの実行過程を記録したものであり、各ステップや呼び出しがどのように行われるかを追跡できます。ビデオでは、トレースを使ってエージェントのツール呼び出しの順序を詳細に分析し、ハローケーションなどの問題を見つけ出しています。

💡期待される動作パターン

期待される動作パターンとは、エージェントが特定のタスクを正しく実行するために従うべき一連のステップやプロセスです。ビデオでは、SQLエージェントがデータベースと対話する際に期待される一連のツール呼び出しステップを示し、そのパターンに従っているかを評価しています。

Highlights

Lance 介绍了Lang chain的第三个视频,专注于代理评估。

讨论了评估代理答案与参考答案的相对性。

探讨了评估单个代理工具调用与预期工具调用的相对性。

本视频将讨论评估一系列工具调用与预期序列或轨迹的相对性。

使用SQL代理作为评估案例研究。

介绍了一个明确列出与SQL数据库交互步骤的代理。

代理执行list table工具调用,然后获取表的schema。

代理生成查询,检查并执行它,最后如果没有错误则结束。

讨论了如何评估工具调用序列是否准确遵循。

展示了如何定义代理预期调用的工具集。

介绍了自定义评估器的使用,以检查工具调用的准确性。

提出了一种简单的评估方法:检查工具调用是否完全匹配预期列表。

提出了一种更灵活的评估方法,允许工具调用顺序中的插入。

展示了如何运行评估并记录工具调用轨迹。

分析了评估结果,发现代理在工具调用中出现了错误。

观察到代理错误地调用了一个不存在的工具。

讨论了代理可能错误地幻想出不存在的工具。

展示了如何通过评估发现并纠正代理的错误。

强调了评估工具调用轨迹的重要性,以识别和修复代理的问题。

预告了下一视频中将展示如何纠正代理的问题。

总结了使用自定义函数进行工具使用轨迹评估的能力。

指出了代理在生产环境中的错误调用可能导致的额外成本和延迟。

Transcripts

play00:01

hey this is Lance from Lang chain this

play00:02

is the third video that we're focusing

play00:04

on agent evaluation so previously we

play00:06

talked about evaluating an agent answer

play00:08

relative to reference we talked about

play00:10

evaluating a single agent tool call

play00:12

relative to expected tool call and now

play00:14

we're going to talk about evaluating a

play00:16

sequence of tool calls relative to an

play00:17

expected sequence or trajectory so again

play00:21

just to remind you we working with SQL

play00:23

agents just as an evaluation case study

play00:26

so I introduced this interesting agent

play00:29

we put together that lays out a lot of

play00:31

the steps required to query and interact

play00:33

with SQL database very explicitly uh so

play00:36

basically it will perform a uh list

play00:39

table tool call it should reform a get

play00:42

schema for the table it'll then generate

play00:45

a query it'll attempt to check it it'll

play00:48

execute it it'll go back uh check that

play00:50

there's no errors in execution um and it

play00:53

will end if there's no errors in

play00:55

execution or it'll respond with the

play00:57

natural language response based upon the

play00:58

executed answer so that's kind of the

play01:00

flow here now let's talk about how we

play01:03

can actually evaluate whether or not

play01:04

this trajectory of tool calls was

play01:05

followed accurately so I'm going to zoom

play01:08

down we've defined our agent we talked

play01:09

through that in some prior um videos

play01:12

here um and we previously showed how to

play01:15

do response valuation so we've actually

play01:17

already walked through that now let's

play01:19

talk a little bit about trajectory

play01:20

evaluation so here it's actually pretty

play01:23

simple I'm just going to find the set of

play01:25

tools I expect my agent to invoke in

play01:28

order so in this particular particular

play01:30

case it's going to be this particular

play01:31

tool SQL list the tables uh so this is

play01:34

from our our you know list tables node

play01:36

it's going to be uh get the schema of

play01:39

those tables it's going to be execute

play01:41

the query um and it's going to be uh

play01:46

submit the final answer so that's really

play01:48

the kind of the steps you expected to

play01:49

take now all I really need here is first

play01:52

I have this little wrapper function that

play01:53

just invokes my my agent and Returns the

play01:56

messages so that's all I need there now

play01:58

for the valuation itself here's where

play02:00

you can actually be you can be kind of

play02:01

creative and clever cuz we're going to

play02:02

use custom evaluators to do this so

play02:05

first here's like two different ways I

play02:08

want I want to do the most simple way I

play02:09

might evaluate this is check for an

play02:11

exact match so what I'm going to do is

play02:13

I'm running my agent I'm getting the

play02:15

messages or like kind of it its history

play02:17

of uh its message history back and what

play02:21

I'm going to do is I'm going to extract

play02:23

the tool calls from that message history

play02:26

okay and that's what this little

play02:27

function does here it just gets the tool

play02:29

calls and then I print them out for

play02:31

convenience you can look at them and

play02:33

really simple if the tool calls matches

play02:35

exactly that expected list it's one

play02:38

otherwise it's a zero or return that now

play02:41

I can also be clever here I can do

play02:42

really anything I want with these custom

play02:43

evaluators so here I'm going to find a

play02:45

separate one that will ask it checks the

play02:48

tools are called in order but allows for

play02:50

there to be insertions like it might try

play02:52

a certain tool twice something like that

play02:54

as long as the order is preserved even

play02:56

if there's if there's tools that are

play02:58

injected in between the correct order

play03:00

it's still permissible so that's like

play03:02

another check that's just a little bit

play03:04

more permissible than the first one

play03:05

they're both kind of interesting to look

play03:06

at for different reasons which we'll

play03:07

show here in a minute so I basically

play03:09

just find these custom evaluators um and

play03:13

now I go ahead and call my evaluate

play03:15

function I pass my uh my wrapper in here

play03:19

right here uh I'm going to use the same

play03:21

data set that we've been we've been

play03:22

working with I Bally just pass my two

play03:24

evaluators right here I'll run three

play03:26

repetitions of this to build some

play03:28

additional confidence um I'm just going

play03:30

to go ahead and and name it um as here

play03:33

and this will kick off so this will

play03:35

start running and we're going to

play03:36

actually see what's kind of nice is

play03:37

we're just going to log the the tool

play03:39

trajectories um cool so evaluation ran

play03:43

we can go over to our data set and we

play03:46

can see that the overall scores from

play03:47

both of values are shown here now you

play03:49

see something pretty interesting first

play03:51

we see we ran again three repetitions

play03:54

first we see that the tools in order is

play03:58

scores one so that's correct every time

play03:59

but exact order scores a zero so that's

play04:02

actually interesting it's kind of an

play04:03

interesting clue about what may be going

play04:04

with our agent so we can actually zoom

play04:06

in here and we can go ahead and and open

play04:09

up any one of these and we can go ahead

play04:12

and look at the trace so let's just say

play04:15

you know I want to look at the trace

play04:16

here and I can kind of zoom in and I can

play04:20

see that we go to our I'll see if I can

play04:23

open this up a little bit more um right

play04:25

so we go to our list tables tool we go

play04:27

our schema tool um and we do go to our

play04:31

query gen tool okay so I'm gonna go

play04:35

ahead and look at what happens

play04:36

there so here's where something kind of

play04:39

interesting happens what appears to

play04:42

occur is I'm going to hit this query gen

play04:44

tool it looks like we basically fail um

play04:51

this condition that we called the wrong

play04:53

tool the SQL DB query tool was called

play04:56

now if I zoom back out here here is a

play05:00

logging of all the tools uh for a bunch

play05:03

of my runs that I that I called so you

play05:05

can see SQL Deb list tool schema SLE DB

play05:10

query um query tool submit final

play05:13

answer

play05:15

um let's Zoom back up and check the

play05:20

expected trajectory of tools so we can

play05:22

see the expected trajectory is basically

play05:24

list the tables get the schema DB query

play05:27

so that's basically you're query your DB

play05:29

submit the final answer so that's what

play05:31

we expect now what you see is this SQL

play05:35

query or SQL DB query is getting

play05:38

injected into our trajectory almost

play05:41

every time now here's what's pretty

play05:44

interesting that's not actually a real

play05:47

tool I go back to my tools list I

play05:49

inspected independently offline this

play05:52

doesn't actually exist so what's

play05:53

happening is this is kind of our my

play05:56

hypothesis that what's happening is this

play05:58

tool is actually hallucinated by the

play06:01

agent um from looking at the trajectory

play06:04

of tools and its message history that

play06:06

you pass to it so that's actually pretty

play06:07

interesting point what's happening is we

play06:10

appear to hallucinate a tool that should

play06:13

not exist we catch it and say hey the

play06:16

wrong tool was called please fix your

play06:18

mistake um we again try again and when

play06:22

we try again it doesn't invoke that fake

play06:25

tool it just Returns the raw career

play06:27

which is exactly what you want then that

play06:29

goes to this correct querier query check

play06:31

then it goes that soon continues so to

play06:33

recap what appears to be happening is

play06:36

that along the trajectory of our agent

play06:39

it inserts this tool hallucination which

play06:42

we catch in our agent as an error and

play06:47

then it kind of corrects itself and does

play06:48

not return a tool call um in this

play06:51

particular node so we see this very

play06:54

clearly with our agent eval trajectory

play06:57

evaluation because we can see in our

play06:59

aggregate scores that uh the tool calls

play07:04

an exact order is always zero

play07:07

effectively if we even go back to the

play07:08

aggregate view I believe it is always

play07:10

zero so effectively every time we run

play07:12

our agent it's injecting this fake and

play07:15

hallucinated Tool call maybe in fact it

play07:18

kind of differs you can actually see

play07:19

it's pretty interesting sometimes we

play07:21

like we'll do SQL DB schema query twice

play07:23

and so there's different types of

play07:25

failure modes that we appear to have in

play07:26

terms of the tool trajectory but in any

play07:28

case being able to run this evaluation

play07:30

and actually look in granular detail at

play07:32

the trajectory of tool calls your

play07:34

agent's taking allows you identify um

play07:36

kind of interesting errors and then in

play07:38

the next video we actually may show how

play07:39

to kind of correct this and this is

play07:41

another kind of very good use face for

play07:43

line graph in terms of agent kind of

play07:45

construction which we'll go into some

play07:46

detail next but I just want to show you

play07:48

the ability to use custom functions to

play07:51

do tool use trajectory evaluation with

play07:53

agents we ran that here and we showed

play07:55

that interesting some weird tool

play07:58

Hallucination is occurring in our agent

play08:00

which is something we may indeed want to

play08:01

go and fix because this is actually you

play08:03

know we're running this agent production

play08:05

it's incurring extra tokens we don't

play08:06

need it's incurring extra latency so

play08:08

it's a suboptimal characteristic of our

play08:10

agent which we'll want to fix going

play08:11

forward thanks

Rate This

5.0 / 5 (0 votes)

Related Tags
エージェント評価SQLツールトラジェクトリーエラー特定改善方法カスタムエバリュエーターツール呼び出しメッセージ履歴ツールハロケーションエージェント改善
Do you need a summary in English?