Skip to content

Instantly share code, notes, and snippets.

@matthew-harper
Created October 5, 2025 00:29
Show Gist options
  • Select an option

  • Save matthew-harper/e7843d429e0ece385029623df47ba398 to your computer and use it in GitHub Desktop.

Select an option

Save matthew-harper/e7843d429e0ece385029623df47ba398 to your computer and use it in GitHub Desktop.
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:
# Placeholder demo: replace with real tavily_search / tavily_extract calls
bullets = [
"Anthropic: context engineering involves thoughtfully curating tokens; use compaction and structured notes.",
"LangChain: write/select/compress/isolate context to keep windows tight.",
"Mezmo: prompt design, context management, RAG, memory, efficiency, safety.",
]
citations = [
"https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents",
"https://blog.langchain.com/context-engineering-for-agents/",
"https://www.mezmo.com/learn-observability/context-engineering-for-observability",
]
return Answer(summary=f"Synthesis of recent context engineering best practices for: {query}",
bullets=bullets, citations=citations)
if __name__ == "__main__":
print(run_research_demo("Context engineering best practices").model_dump_json(indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment