Agent Trajectory | LangSmith Evaluation - Part 26
Summary
TLDRランスがLance Chainの第3回目のビデオで、エージェントの評価方法について解説。これまでは回答の評価や単一のツールコールの評価に焦点を当てたが、今回は期待されるツールコールの順序や軌跡を評価する方法を紹介。SQLエージェントを評価対象として、ツールの呼び出し順序を正確に評価する方法を説明。カスタムエバリュエータを使用して、正確な順序や順序が保たれる範囲内で挿入が許される場合の評価を実演。実際のツール軌跡を分析し、エージェントが誤ったツールを誤認識している問題を特定。この評価手法により、エージェントの改善点を見つけ出し、最適化の方向性を示す。
Takeaways
- 😀 エージェントの評価方法についての第3回目のビデオで、SQLエージェントを評価するケーススタディとして使用している。
- 🔍 これまでに回答の評価や単一のツールコールの評価について話していた。今回は、期待されるシーケンスまたは軌跡に対するツールコールのシーケンスの評価について説明する。
- 🛠️ ランチェーンのエージェントは、SQLデータベースと対話するためのステップを明示的に実行する。
- 📝 エージェントのフローは、テーブルのリストを取得、スキーマを取得、クエリを生成、チェック、実行、エラーがないか確認、そしてエラーがなければ自然言語で応答する。
- 🔄 ツールコールの軌跡を評価する方法は、期待されるツールのセットを見つけることから始まる。
- 👀 カスタムエバリュエーターを使用して、ツールコールの正確性や順序を評価することができる。
- 🔢 評価では、正確な一致を確認するシンプルな方法や、順序を保持しながら挿入が許されるより緩やかな方法の両方を提供している。
- 📊 評価結果は、ツールコールの軌跡をログに記録し、分析することで得られる。
- 🤖 エージェントは、期待される軌跡と異なるツールコールを挿入することがあることがわかった。
- 💡 評価プロセスでは、エージェントが誤ったツールコールを行った場合にそれを特定し、修正する方法を見つけることができる。
- 🔧 次回のビデオでは、このような問題を修正する方法について説明する予定である。
Q & A
ランスが紹介したエージェントの評価方法は何ですか?
-ランスは、エージェントの評価方法として、参照に対するエージェントの回答の評価、期待されるツールコールに対する単一のエージェントツールコールの評価、そして期待されるシーケンスまたは軌道に対するツールコールのシーケンスの評価について話しました。
SQLエージェントのステップはどのように定義されていますか?
-SQLエージェントは、テーブルのリストを取得し、スキーマを取得し、クエリを生成し、チェックし、実行し、実行中にエラーがないか確認し、エラーがなければ自然言語で応答するというステップを定義しています。
ツールコールの軌道評価とは何を意味しますか?
-ツールコールの軌道評価とは、エージェントが呼び出すツールのセットが期待される順序に従っているかどうかを評価することを意味します。
ランスが使用するカスタムエバリュエーターとは何ですか?
-ランスが使用するカスタムエバリュエーターは、ツールコールの正確な一致を確認するものと、順序が保たれているが中間に挿入が許されるものがあります。
エージェントが期待されるツールの順序をどのように特定しますか?
-ランスは、期待されるツールの順序を特定するために、ツールのリストから各ツールを抽出し、それらを順序に従って評価します。
エージェントのメッセージ履歴からツールコールをどのように抽出するのですか?
-ランスは、エージェントのメッセージ履歴を取得し、その履歴からツールコールを抽出する関数を使用して、ツールコールを特定します。
ランスが示したツールの軌道のログとは何ですか?
-ツールの軌道のログとは、エージェントが実行したツールコールのシーケンスを記録したものであり、そのログを分析することでエージェントの動作を評価することができます。
エージェントが誤ったツールコールを挿入する理由は何ですか?
-ランスの分析では、エージェントが誤ったツールコールを挿入する理由として、そのツールが実際に存在しないものであることが示されており、エージェントがそのツールを幻想した可能性があるとされています。
評価結果から得られる洞察は何ですか?
-評価結果からは、エージェントが期待される順序に従っているかどうかを確認できるだけでなく、幻想されたツールコールが挿入されるという不正な動作が存在する可能性があることが洞察できます。
ランスが今後のエージェントの改善に取り組む点とは何ですか?
-ランスは、エージェントが幻想したツールコールを挿入する問題を解決し、より最適化されたエージェントの動作を目指す改善に取り組む予定です。
この評価方法が役立つ状況とはどのような時ですか?
-この評価方法は、エージェントのツールコールの軌道を詳細に分析し、期待される動作と実際の動作のギャップを特定するのに役立ちます。
Outlines
😲 エージェントの評価:ツール呼び出しの正確性
ランスは、SQLエージェントの評価方法について説明しています。このビデオでは、ツール呼び出しのシーケンスを期待されるシーケンスと比較して評価する方法に焦点を当てています。エージェントは、テーブルのリストやスキーマの取得、クエリの生成、実行、エラーチェックを実行し、エラーがなければ自然言語で応答するという一連のステップを実行することが期待されています。評価では、エージェントが呼び出したツールのセットを比較し、正確に従われたかどうかを確認します。
🔍 ツール呼び出しのトラジェクトリーの評価
このセクションでは、ツール呼び出しのトラジェクトリーを評価するためのカスタムエバリュエータの使用方法について説明されています。ランスは、ツール呼び出しの正確な順序を確認するだけでなく、誤ったツールが誤って呼び出される可能性があることを指摘しています。実際の評価では、期待されるツールの順序に従っているかどうか、または誤ったツールが挿入された場合でも順序が維持されているかどうかをチェックしています。このプロセスにより、エージェントが誤ったツールを誤って認識するという興味深いエラーを特定できました。
Mindmap
Keywords
💡エージェント評価
💡ツール呼び出し
💡期待されるツールの順序
💡カスタムエバリュエータ
💡メッセージ履歴
💡正確な一致
💡挿入許容順序
💡ハローケーション
💡トレース
💡期待される動作パターン
Highlights
Lance 介绍了Lang chain的第三个视频,专注于代理评估。
讨论了评估代理答案与参考答案的相对性。
探讨了评估单个代理工具调用与预期工具调用的相对性。
本视频将讨论评估一系列工具调用与预期序列或轨迹的相对性。
使用SQL代理作为评估案例研究。
介绍了一个明确列出与SQL数据库交互步骤的代理。
代理执行list table工具调用,然后获取表的schema。
代理生成查询,检查并执行它,最后如果没有错误则结束。
讨论了如何评估工具调用序列是否准确遵循。
展示了如何定义代理预期调用的工具集。
介绍了自定义评估器的使用,以检查工具调用的准确性。
提出了一种简单的评估方法:检查工具调用是否完全匹配预期列表。
提出了一种更灵活的评估方法,允许工具调用顺序中的插入。
展示了如何运行评估并记录工具调用轨迹。
分析了评估结果,发现代理在工具调用中出现了错误。
观察到代理错误地调用了一个不存在的工具。
讨论了代理可能错误地幻想出不存在的工具。
展示了如何通过评估发现并纠正代理的错误。
强调了评估工具调用轨迹的重要性,以识别和修复代理的问题。
预告了下一视频中将展示如何纠正代理的问题。
总结了使用自定义函数进行工具使用轨迹评估的能力。
指出了代理在生产环境中的错误调用可能导致的额外成本和延迟。
Transcripts
hey this is Lance from Lang chain this
is the third video that we're focusing
on agent evaluation so previously we
talked about evaluating an agent answer
relative to reference we talked about
evaluating a single agent tool call
relative to expected tool call and now
we're going to talk about evaluating a
sequence of tool calls relative to an
expected sequence or trajectory so again
just to remind you we working with SQL
agents just as an evaluation case study
so I introduced this interesting agent
we put together that lays out a lot of
the steps required to query and interact
with SQL database very explicitly uh so
basically it will perform a uh list
table tool call it should reform a get
schema for the table it'll then generate
a query it'll attempt to check it it'll
execute it it'll go back uh check that
there's no errors in execution um and it
will end if there's no errors in
execution or it'll respond with the
natural language response based upon the
executed answer so that's kind of the
flow here now let's talk about how we
can actually evaluate whether or not
this trajectory of tool calls was
followed accurately so I'm going to zoom
down we've defined our agent we talked
through that in some prior um videos
here um and we previously showed how to
do response valuation so we've actually
already walked through that now let's
talk a little bit about trajectory
evaluation so here it's actually pretty
simple I'm just going to find the set of
tools I expect my agent to invoke in
order so in this particular particular
case it's going to be this particular
tool SQL list the tables uh so this is
from our our you know list tables node
it's going to be uh get the schema of
those tables it's going to be execute
the query um and it's going to be uh
submit the final answer so that's really
the kind of the steps you expected to
take now all I really need here is first
I have this little wrapper function that
just invokes my my agent and Returns the
messages so that's all I need there now
for the valuation itself here's where
you can actually be you can be kind of
creative and clever cuz we're going to
use custom evaluators to do this so
first here's like two different ways I
want I want to do the most simple way I
might evaluate this is check for an
exact match so what I'm going to do is
I'm running my agent I'm getting the
messages or like kind of it its history
of uh its message history back and what
I'm going to do is I'm going to extract
the tool calls from that message history
okay and that's what this little
function does here it just gets the tool
calls and then I print them out for
convenience you can look at them and
really simple if the tool calls matches
exactly that expected list it's one
otherwise it's a zero or return that now
I can also be clever here I can do
really anything I want with these custom
evaluators so here I'm going to find a
separate one that will ask it checks the
tools are called in order but allows for
there to be insertions like it might try
a certain tool twice something like that
as long as the order is preserved even
if there's if there's tools that are
injected in between the correct order
it's still permissible so that's like
another check that's just a little bit
more permissible than the first one
they're both kind of interesting to look
at for different reasons which we'll
show here in a minute so I basically
just find these custom evaluators um and
now I go ahead and call my evaluate
function I pass my uh my wrapper in here
right here uh I'm going to use the same
data set that we've been we've been
working with I Bally just pass my two
evaluators right here I'll run three
repetitions of this to build some
additional confidence um I'm just going
to go ahead and and name it um as here
and this will kick off so this will
start running and we're going to
actually see what's kind of nice is
we're just going to log the the tool
trajectories um cool so evaluation ran
we can go over to our data set and we
can see that the overall scores from
both of values are shown here now you
see something pretty interesting first
we see we ran again three repetitions
first we see that the tools in order is
scores one so that's correct every time
but exact order scores a zero so that's
actually interesting it's kind of an
interesting clue about what may be going
with our agent so we can actually zoom
in here and we can go ahead and and open
up any one of these and we can go ahead
and look at the trace so let's just say
you know I want to look at the trace
here and I can kind of zoom in and I can
see that we go to our I'll see if I can
open this up a little bit more um right
so we go to our list tables tool we go
our schema tool um and we do go to our
query gen tool okay so I'm gonna go
ahead and look at what happens
there so here's where something kind of
interesting happens what appears to
occur is I'm going to hit this query gen
tool it looks like we basically fail um
this condition that we called the wrong
tool the SQL DB query tool was called
now if I zoom back out here here is a
logging of all the tools uh for a bunch
of my runs that I that I called so you
can see SQL Deb list tool schema SLE DB
query um query tool submit final
answer
um let's Zoom back up and check the
expected trajectory of tools so we can
see the expected trajectory is basically
list the tables get the schema DB query
so that's basically you're query your DB
submit the final answer so that's what
we expect now what you see is this SQL
query or SQL DB query is getting
injected into our trajectory almost
every time now here's what's pretty
interesting that's not actually a real
tool I go back to my tools list I
inspected independently offline this
doesn't actually exist so what's
happening is this is kind of our my
hypothesis that what's happening is this
tool is actually hallucinated by the
agent um from looking at the trajectory
of tools and its message history that
you pass to it so that's actually pretty
interesting point what's happening is we
appear to hallucinate a tool that should
not exist we catch it and say hey the
wrong tool was called please fix your
mistake um we again try again and when
we try again it doesn't invoke that fake
tool it just Returns the raw career
which is exactly what you want then that
goes to this correct querier query check
then it goes that soon continues so to
recap what appears to be happening is
that along the trajectory of our agent
it inserts this tool hallucination which
we catch in our agent as an error and
then it kind of corrects itself and does
not return a tool call um in this
particular node so we see this very
clearly with our agent eval trajectory
evaluation because we can see in our
aggregate scores that uh the tool calls
an exact order is always zero
effectively if we even go back to the
aggregate view I believe it is always
zero so effectively every time we run
our agent it's injecting this fake and
hallucinated Tool call maybe in fact it
kind of differs you can actually see
it's pretty interesting sometimes we
like we'll do SQL DB schema query twice
and so there's different types of
failure modes that we appear to have in
terms of the tool trajectory but in any
case being able to run this evaluation
and actually look in granular detail at
the trajectory of tool calls your
agent's taking allows you identify um
kind of interesting errors and then in
the next video we actually may show how
to kind of correct this and this is
another kind of very good use face for
line graph in terms of agent kind of
construction which we'll go into some
detail next but I just want to show you
the ability to use custom functions to
do tool use trajectory evaluation with
agents we ran that here and we showed
that interesting some weird tool
Hallucination is occurring in our agent
which is something we may indeed want to
go and fix because this is actually you
know we're running this agent production
it's incurring extra tokens we don't
need it's incurring extra latency so
it's a suboptimal characteristic of our
agent which we'll want to fix going
forward thanks
Browse More Related Video
![](https://i.ytimg.com/vi/AVPflFmRkd4/hq720.jpg)
Single Step | LangSmith Evaluation - Part 25
![](https://i.ytimg.com/vi/NbQKDfSw3gM/hq720.jpg)
Agent Response | LangSmith Evaluation - Part 24
![](https://i.ytimg.com/vi/lTfhw_9cJqc/hq720.jpg)
RAG Evaluation (Answer Correctness) | LangSmith Evaluations - Part 12
![](https://i.ytimg.com/vi/Fr_7HtHjcf0/hq720.jpg)
RAG Evaluation (Document Relevance) | LangSmith Evaluations - Part 14
![](https://i.ytimg.com/vi/IlNglM9bKLw/hq720.jpg)
RAG Evaluation (Answer Hallucinations) | LangSmith Evaluations - Part 13
![](https://i.ytimg.com/vi/3gCTa0Li4ew/hq720.jpg)
Corrections + Few Shot Examples (Part 1) | LangSmith Evaluations
5.0 / 5 (0 votes)