feat: Day 13 - root README, example agent scripts, and demo seed script

This commit is contained in:
Vectry
2026-02-10 01:48:47 +00:00
parent e0f13cdaa6
commit 98bfa968ce
7 changed files with 2189 additions and 2 deletions

92
examples/basic_agent.py Normal file
View File

@@ -0,0 +1,92 @@
"""
AgentLens Basic Example — Simplest possible usage.
Demonstrates:
- Initializing the SDK
- Creating a trace with tags
- Logging decision points (TOOL_SELECTION, PLANNING)
- Graceful shutdown
Usage:
pip install vectry-agentlens
python basic_agent.py
"""
import agentlens
import time
# 1. Initialize AgentLens
agentlens.init(
api_key="your-api-key-here",
endpoint="http://localhost:4200",
)
# 2. Run an agent task inside a trace context
with agentlens.trace("research-task", tags=["demo", "basic"]):
# Simulate: agent decides which tool to use for research
agentlens.log_decision(
type="TOOL_SELECTION",
chosen={
"name": "search_web",
"confidence": 0.85,
"params": {"query": "latest AI research papers 2025"},
},
alternatives=[
{
"name": "search_docs",
"confidence": 0.6,
"reason_rejected": "Internal docs unlikely to have latest papers",
},
{
"name": "search_arxiv",
"confidence": 0.78,
"reason_rejected": "Web search covers arXiv plus other sources",
},
],
reasoning="Web search gives the broadest coverage for recent AI papers.",
)
time.sleep(0.3) # Simulate tool execution time
# Simulate: agent plans next steps after getting search results
agentlens.log_decision(
type="PLANNING",
chosen={
"name": "summarize_top_3",
"confidence": 0.92,
"params": {"max_papers": 3, "format": "bullet_points"},
},
alternatives=[
{
"name": "summarize_all",
"confidence": 0.5,
"reason_rejected": "Too many results, would dilute quality",
},
],
reasoning="Focusing on top 3 papers gives concise, high-value summary.",
)
time.sleep(0.2) # Simulate summarization
# Simulate: decide whether to retry with refined query
agentlens.log_decision(
type="CUSTOM",
chosen={
"name": "return_results",
"confidence": 0.95,
"params": {"result_count": 3},
},
alternatives=[
{
"name": "refine_and_retry",
"confidence": 0.3,
"reason_rejected": "Current results are already high quality",
},
],
reasoning="Results are comprehensive enough; no need to retry.",
)
# 3. Shutdown — flush any pending data
agentlens.shutdown()
print("Done! Check your AgentLens dashboard for the 'research-task' trace.")