用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill langchain-test-agent命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | langchain-test-agent |
| description | > Use when this capability is needed. |
| Scenario | Use | Why |
|---|---|---|
| Tool logic / validation / errors | Pytest | Deterministic and fast |
| External I/O around a tool | Pytest + mocks | Avoid network and LLM cost |
| Tool selection / multi-step traces | LangSmith | The model decides the path |
| Structured output / RAG / prompt quality | LangSmith | Needs model-level evaluation |
| Latency / tokens / cost | LangSmith traces + experiment metrics | Execution metrics live in tracing |
.invoke() method or the underlying function.@pytest.mark.langsmith.response_format on create_agent.result["structured_response"].Why this separation matters:
from langchain_core.tools import tool
import pytest
@tool
def calculate_score(score: int) -> str:
"""Return PASS or FAIL based on score."""
if score < 0 or score > 100:
raise ValueError("Score must be between 0 and 100")
return "PASS" if score >= 60 else "FAIL"
def test_calculate_score_pass():
assert calculate_score.invoke({"score": 85}) == "PASS"
def test_calculate_score_invalid():
with pytest.raises(ValueError, match="0 and 100"):
calculate_score.invoke({"score": 150})
import pytest
from langchain.agents import create_agent
from langsmith import testing as t
from pydantic import BaseModel
class ContactInfo(BaseModel):
name: str
email: str
@pytest.mark.langsmith
def test_agent_structured_output():
query = "Extract: John Doe, john@example.com"
t.log_inputs({"query": query})
agent = create_agent(
model="gpt-4.1-mini",
tools=[],
response_format=ContactInfo,
system_prompt="Extract contact info."
)
result = agent.invoke({"messages": [{"role": "user", "content": query}]})
t.log_outputs({"structured_response": result["structured_response"]})
assert result["structured_response"].name == "John Doe"
assert result["structured_response"].email == "john@example.com"
from typing_extensions import Annotated, TypedDict
from langchain_openai import ChatOpenAI
from langsmith import evaluate
class FaithfulnessGrade(TypedDict):
explanation: Annotated[str, ..., "Explain the score"]
faithful: Annotated[bool, ..., "The answer is supported by the context"]
judge_llm = ChatOpenAI(model="gpt-4.1", temperature=0).with_structured_output(
FaithfulnessGrade,
method="json_schema",
strict=True,
)
def faithfulness_evaluator(inputs: dict, outputs: dict) -> bool:
prompt = f"Context: {inputs['context']}\nAnswer: {outputs['answer']}"
grade = judge_llm.invoke(
[
{"role": "system", "content": "Evaluate whether the answer is grounded only in the context."},
{"role": "user", "content": prompt},
]
)
return grade["faithful"]
evaluate(
rag_chain,
data="rag-dataset-name",
evaluators=[faithfulness_evaluator],
)
from langsmith import Client
client = Client()
experiment = client.evaluate(
rag_chain,
data="rag-dataset-name",
evaluators=[faithfulness_evaluator],
experiment_prefix="rag-fidelity",
)
print(f"Latency p50: {experiment.latency_p50}")
print(f"Total tokens: {experiment.total_tokens}")
print(f"Prompt tokens: {experiment.prompt_tokens}")
print(f"Completion tokens: {experiment.completion_tokens}")
uv add pytest pytest-mock langsmith
pytest tests/tools/ -v
LANGSMITH_API_KEY=your_key pytest tests/agents/ -v
Source: ColRuDev/job-candidate-matcher — distributed by TomeVault.