LlamaIndex Agent 评测 Quickstart
llamaIndex_agent_evals 模板用 tool call 准确率指标评测 LlamaIndex workflow agent。
创建项目
ragas quickstart llamaIndex_agent_evals
cd llamaIndex_agent_evals
安装依赖
uv sync
设置 API Key
export OPENAI_API_KEY="your-openai-key"
export GOOGLE_API_KEY="your-google-key" # For evaluator LLM
运行评测
uv run python evals.py
项目结构
llamaIndex_agent_evals/
├── README.md # Project documentation
├── pyproject.toml # Project configuration
├── llamaindex_agent.py # LlamaIndex agent with tools
├── evals.py # Evaluation workflow
├── __init__.py # Python package marker
└── evals/
├── datasets/
│ └── contexts/ # Test context files (JSON)
├── experiments/ # Evaluation results
└── logs/ # Execution logs
评测内容
该模板评测 LlamaIndex agent 的 tool calling 准确率:
- Agent:带列表管理工具(添加、删除、列出条目)的 LlamaIndex
FunctionAgent - 测试用例:重复添加、歧义删除请求等复杂场景
- 指标:Tool call 准确率、回复正确性
理解代码
Agent(llamaindex_agent.py)
带简单工具的 LlamaIndex agent:
from llama_index.core.agent.workflow import FunctionAgent
agent = FunctionAgent(
name="list_manager",
tools=[add_item, remove_item, list_items],
llm=llm
)
评测(evals.py)
使用 F1 score 测试 tool call 准确率:
@numeric_metric(name="tool_call_accuracy")
def tool_call_accuracy_metric(predicted_calls: List[Dict], ground_truth_calls: List[Dict]):
# Compares predicted vs ground truth tool calls
# Returns F1 score between 0.0 and 1.0
测试数据
模板在 evals/datasets/contexts/ 中包含 JSON 测试上下文:
ambiguous_removal_request.json- 测试对歧义请求的处理duplicate_addition.json- 测试对重复操作的处理repeated_removal.json- 测试重复操作