Loading the notebook…
Loading the notebook…
Notebooks · Deep agents · 15
Systematically test your agents with expected outputs, tool usage, and content checks. Built-in evaluation framework — nothing like this in LangChain.
Its imports and arguments are checked against shipit-agent 3.0. The outputs were saved when it was written, for an earlier release.
from pathlib import Path
import sys
ROOT = (
Path.cwd().resolve().parent
if Path.cwd().name == "notebooks"
else Path.cwd().resolve()
)
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from shipit_agent import Agent
from shipit_agent.deep import AgentBenchmark, TestCase
from examples.run_multi_tool_agent import build_llm_from_env
llm = build_llm_from_env("bedrock")Each TestCase specifies an input prompt and expectations: what the output should contain, what it shouldn't contain, and which tools should be used.
# Create a knowledge agent to benchmark
agent = Agent(
llm=llm,
prompt="You are a helpful programming assistant. Answer questions concisely and accurately.",
name="code-helper",
)
# Define benchmark test cases
benchmark = AgentBenchmark(
name="Programming Knowledge Eval",
cases=[
TestCase(
input="What is Python's GIL?",
expected_contains=["global interpreter lock", "thread"],
),
TestCase(
input="Explain what a REST API is",
expected_contains=["http", "resource"],
expected_not_contains=["graphql"], # should not confuse with GraphQL
),
TestCase(
input="What are Python decorators?",
expected_contains=["function", "wrap"],
),
TestCase(
input="Explain the difference between a list and a tuple in Python",
expected_contains=["mutable", "immutable"],
),
TestCase(
input="What is Docker?",
expected_contains=["container"],
),
],
)
print(f"Benchmark: {benchmark.name}")
print(f"Test cases: {len(benchmark.cases)}")Benchmark: Programming Knowledge Eval Test cases: 5
# Run all test cases against the agent
report = benchmark.run(agent)
# Print the summary report
print(report.summary())Agent Benchmark: Programming Knowledge Eval Cases: 5 passed, 0 failed (5 total) Pass rate: 100% Avg iterations: 1.0 [PASS] What is Python's GIL? [PASS] Explain what a REST API is [PASS] What are Python decorators? [PASS] Explain the difference between a list and a tuple in Python [PASS] What is Docker?
# Detailed inspection of each test case
for i, r in enumerate(report.results, 1):
status = "PASS" if r.passed else "FAIL"
print(f"\n{'='*60}")
print(f"Test {i}: [{status}] {r.test_case.input[:50]}...")
print(f"Output preview: {r.output[:150]}...")
if r.failures:
print("Failures:")
for f in r.failures:
print(f" - {f}")
# Export as dict for logging/dashboards
print(f"\n{'='*60}")
print("Exportable report:")
import json
print(json.dumps(report.to_dict(), indent=2)[:500])============================================================
Test 1: [PASS] What is Python's GIL?...
Output preview: **Python’s GIL (Global Interpreter Lock)**
| Aspect | Description |
|--------|-------------|
| **What it is** | A mutex (mutual‑exclusion lock) tha...
============================================================
Test 2: [PASS] Explain what a REST API is...
Output preview: **REST API (Representational State Transfer Application Programming Interface)**
A REST API is a way of designing web services that lets clients (e...
============================================================
Test 3: [PASS] What are Python decorators?...
Output preview: **Python decorators** are a language feature that lets you *wrap* or *modify* the behavior of functions (or methods, classes) without changing their a...
============================================================
Test 4: [PASS] Explain the difference between a list and a tuple ...
Output preview: **Python list vs. tuple**
| Feature | List | Tuple |
|---------|------|-------|
| **Syntax** | `my_list = [1, 2, 3]` | `my_tuple = (1, 2, 3)` (or `my...
============================================================
Test 5: [PASS] What is Docker?...
Output preview: **Docker** is an open‑source platform that enables developers and operations teams to **build, ship, and run applications in lightweight, portable con...
============================================================
Exportable report:
{
"name": "Programming Knowledge Eval",
"passed": 5,
"failed": 0,
"total": 5,
"pass_rate": 1.0,
"results": [
{
… 19 more lines