用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/truera/trulens --skill trulens-notebook-execution命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| skill_spec_version | 0.1.0 |
| name | trulens-notebook-execution |
| version | 1.0.0 |
| description | Execute and display Jupyter notebooks for TruLens demos and quickstarts |
| tags | ["trulens","jupyter","notebook","execution","demo"] |
Execute Jupyter notebooks, display progress to the user, and handle API key requirements.
Use this skill when:
Always use jupyter nbconvert --execute to run notebooks. This:
DO NOT try to run notebooks by:
python -c with heredocsjupyter nbconvert --to notebook --execute --inplace <notebook_path>
jupyter nbconvert --to notebook --execute --inplace \
--ExecutePreprocessor.timeout=600 \
<notebook_path>
jupyter nbconvert --to notebook --execute --stdout <notebook_path>
When running a notebook, display section headers as each cell executes - NOT generic "BASH_OUTPUT" messages.
Before executing, read the notebook JSON to build a map of:
import json
with open('notebook.ipynb') as f:
nb = json.load(f)
sections = []
current_section = "Setup"
for i, cell in enumerate(nb['cells']):
if cell['cell_type'] == 'markdown':
source = ''.join(cell['source'])
# Extract header
for line in source.split('\n'):
if line.startswith('## '):
current_section = line.replace('## ', '').strip()
sections.append((i, current_section))
When checking output or between cell groups, display the section name:
=== Step 1: Create the Search Tool ===
[cell output here]
=== Step 2: Create the Deep Agent ===
[cell output here]
=== Step 3: Set Up TruLens Session ===
[cell output here]
When polling for bash output during notebook execution:
# When starting a section:
print(f"\n=== {section_name} ===")
# When showing cell output:
print(output)
# When section completes:
print("✓ Complete")
Running notebook: deep_agents_quickstart.ipynb
=== Step 1: Create the Search Tool ===
✓ Complete
=== Step 2: Create the Deep Agent ===
✓ Complete
=== Step 3: Set Up TruLens Session ===
Starting dashboard...
Dashboard started at http://localhost:8501
✓ Complete
=== Step 4: Define Agent GPA Feedback Functions ===
✓ Complete
=== Step 5: Instrument the Agent with TruGraph ===
✓ Complete
=== Step 6: Run and Evaluate ===
Running agent with question: "What is the weather in San Francisco?"
Agent response: "The weather in San Francisco is..."
Waiting for evaluation results...
✓ Evaluations complete
=== Results ===
Answer Relevance: 1.0
Tool Selection: 1.0
...
Critical: Check environment first, then prompt for keys ONE AT A TIME
env | grep -E "OPENAI|TAVILY|ANTHROPIC" || echo "No API keys found"
When prompting for keys:
Example prompt pattern:
Question: "Paste your OPENAI_API_KEY:"
Header: "OpenAI"
Options: [{"label": "sk-proj-...", "description": "Paste your sk-... key"}]
The user will paste their actual key by selecting "Other" or the option itself will be replaced with their input.
OPENAI_API_KEY="sk-..." TAVILY_API_KEY="tvly-..." \
jupyter nbconvert --execute ...
| Key | Used For |
|---|---|
OPENAI_API_KEY | OpenAI LLM calls, embeddings, feedback provider |
TAVILY_API_KEY | Web search tool (Deep Agents, research agents) |
ANTHROPIC_API_KEY | Anthropic/Claude models |
HUGGINGFACE_API_KEY | HuggingFace models |
Critical: The notebook execution process ends, killing any dashboard started within it.
After notebook execution completes, launch the dashboard separately using TruLens's run_dashboard() function.
The notebook writes its database to ./default.sqlite relative to the notebook's directory. The run_dashboard() function reads from ./default.sqlite relative to the current working directory.
This means you MUST cd to the notebook's directory before launching the dashboard.
cd /path/to/notebook/directory && \
python3 << 'EOF'
from trulens.core import TruSession
from trulens.dashboard import run_dashboard
session = TruSession()
run_dashboard(session)
EOF
Use run_in_background=true with the bash tool so the dashboard stays alive.
DO NOT try to launch the dashboard with native streamlit commands like:
# WRONG - will connect to wrong/empty database!
streamlit run /path/to/trulens/src/dashboard/trulens/dashboard/main.py
This fails because:
./default.sqlite relative to that directory# Step 1: Execute notebook
OPENAI_API_KEY="sk-..." jupyter nbconvert --execute --inplace \
/path/to/examples/notebook.ipynb
# Step 2: Launch persistent dashboard FROM THE NOTEBOOK'S DIRECTORY
cd /path/to/examples && \
python3 << 'EOF'
from trulens.core import TruSession
from trulens.dashboard import run_dashboard
session = TruSession()
run_dashboard(session)
EOF
# Use run_in_background=true for this command
The dashboard will output its URL (e.g., http://localhost:55872) and remain running until explicitly stopped.
After notebook execution:
| Issue | Solution |
|---|---|
| Notebook times out | Increase timeout: --ExecutePreprocessor.timeout=1200 |
| Kernel not found | Ensure correct Python environment is active |
| Import errors | Run pip install cell first or install dependencies |
| API key errors | Verify keys are set correctly in environment |
| Dashboard doesn't start | Check if port is already in use |
'id' was unexpected error | Remove id fields from cells (see fix below) |
If you see Additional properties are not allowed ('id' was unexpected):
import json
with open('notebook.ipynb', 'r') as f:
nb = json.load(f)
# Remove 'id' fields from cells (not valid in nbformat 4)
for cell in nb['cells']:
if 'id' in cell:
del cell['id']
with open('notebook.ipynb', 'w') as f:
json.dump(nb, f, indent=1)
User: "Run the deep agents quickstart notebook"
1. Read notebook to identify:
- Section headers (for progress display)
- Required API keys (OPENAI_API_KEY, TAVILY_API_KEY)
2. Check environment for existing keys:
env | grep -E "OPENAI|TAVILY"
3. Prompt for missing keys (ONE AT A TIME):
"Please provide your OPENAI_API_KEY:"
[User enters key]
"Please provide your TAVILY_API_KEY:"
[User enters key]
4. Execute notebook, displaying section headers:
=== Step 1: Create the Search Tool ===
✓ Complete
=== Step 2: Create the Deep Agent ===
✓ Complete
=== Step 3: Set Up TruLens Session ===
✓ Complete
=== Step 4: Define Agent GPA Feedback Functions ===
✓ Complete
=== Step 5: Instrument the Agent ===
✓ Complete
=== Step 6: Run and Evaluate ===
Running agent...
Waiting for evaluation results...
✓ Complete
5. Launch dashboard in background FROM THE NOTEBOOK'S DIRECTORY:
cd /path/to/notebook/directory && python3 -c "
from trulens.core import TruSession
from trulens.dashboard import run_dashboard
session = TruSession()
run_dashboard(session)
"
[run_in_background=true]
6. Display results summary:
"✓ Notebook execution complete!
Evaluation Results:
- Answer Relevance: 1.0
- Tool Selection: 1.0
- Tool Calling: 1.0
- Execution Efficiency: 0.33
- Plan Quality: 1.0
- Plan Adherence: 1.0
Dashboard running at: http://localhost:8501
(Dashboard will stay alive until you stop it)"
This skill works alongside:
instrumentation/ - for understanding what's being tracedevaluation-setup/ - for understanding feedback functionsrunning-evaluations/ - for interpreting resultsCreate and curate evaluation datasets with ground truth for TruLens
Configure feedback functions and selectors for TruLens evaluations
Configure and use feedback functions as runtime blocking guardrails
基于 SOC 职业分类