Skip to content

Instantly share code, notes, and snippets.

View matthew-harper's full-sized avatar

Matthew Harper matthew-harper

View GitHub Profile
#!/usr/bin/env bash
python strands_context_engineering_demo.py --help
@matthew-harper
matthew-harper / snippet18_comprehensive_command.sh
Created October 5, 2025 00:29
Pattern 7 — Run the comprehensive integration demo
#!/usr/bin/env bash
python strands_context_engineering_demo.py comprehensive
@matthew-harper
matthew-harper / snippet17_comprehensive_demo.py
Created October 5, 2025 00:29
Pattern 7 — Comprehensive Context Engineering demo
from dataclasses import dataclass
from typing import List
try:
from strands import Agent
from strands.tools import calculator, mem0_memory, tavily_search, tavily_extract, use_llm
from strands.managers import SlidingWindowConversationManager
except Exception:
class Agent:
def __init__(self, **kwargs): pass
@matthew-harper
matthew-harper / snippet16_research_command.sh
Created October 5, 2025 00:29
Pattern 6 — Run bounded web research
#!/usr/bin/env bash
python strands_context_engineering_demo.py research "Context engineering best practices"
@matthew-harper
matthew-harper / snippet15_bounded_research.py
Created October 5, 2025 00:29
Pattern 6 — Bounded Web Research (Answer model + flow)
from typing import List, Optional
from pydantic import BaseModel, Field
class Answer(BaseModel):
summary: str = Field(description="Brief summary of findings")
bullets: List[str] = Field(description="Key points as bullet list")
citations: List[str] = Field(description="Source URLs")
uncertainty: Optional[str] = Field(default=None, description="Any uncertainty notes")
def run_research_demo(query: str) -> Answer:
@matthew-harper
matthew-harper / snippet14_routing_commands.sh
Created October 5, 2025 00:29
Pattern 5 — Routing test commands
#!/usr/bin/env bash
python strands_context_engineering_demo.py route "Factor x^2 + 7x + 12"
python strands_context_engineering_demo.py route "Why does my Python code raise a TypeError?"
@matthew-harper
matthew-harper / snippet13_routing_specialists.py
Created October 5, 2025 00:29
Pattern 5 — Agents as Tools: Routing to Specialists
from pydantic import BaseModel, Field
class RouteDecision(BaseModel):
target: str = Field(description="Target specialist (math, code, generalist)")
reason: str = Field(description="Why this target was chosen")
confidence: float = Field(description="Confidence score (0.0-1.0)")
def route_query(q: str) -> RouteDecision:
ql = q.lower()
if any(k in ql for k in ["factor", "integrate", "derivative", "+", "*", "^", "solve", "math"]):
@matthew-harper
matthew-harper / snippet12_guardrails_commands.sh
Created October 5, 2025 00:29
Pattern 4 — Guardrails commands
#!/usr/bin/env bash
python strands_context_engineering_demo.py guard "My SSN is 123-45-6789" --shadow
python strands_context_engineering_demo.py guard "My SSN is 123-45-6789"
@matthew-harper
matthew-harper / snippet11_guardrails_demo.py
Created October 5, 2025 00:29
Pattern 4 — Guardrails as Context Hygiene (shadow vs enforce)
import re
def run_guardrails_demo(prompt: str, shadow: bool = True) -> None:
"""Pattern 4: Guardrails as Context Hygiene"""
print(f"\nInput: {prompt!r}")
print(f"Mode: {'Shadow (logging only)' if shadow else 'Enforcement'}")
if shadow:
print("Shadow mode: logging only (no enforcement).")
print(f"Response: {prompt}")
print("(Would log to monitoring system: PII pattern detected)")
@matthew-harper
matthew-harper / snippet16_research_command.sh
Created October 5, 2025 00:28
Pattern 6 — Run bounded web research
#!/usr/bin/env bash
python strands_context_engineering_demo.py research "Context engineering best practices"