Skip to content

Instantly share code, notes, and snippets.

@dbreunig
Last active February 20, 2026 21:51
Show Gist options
  • Select an option

  • Save dbreunig/c13d0e950467659d51bd370a6f19e11f to your computer and use it in GitHub Desktop.

Select an option

Save dbreunig/c13d0e950467659d51bd370a6f19e11f to your computer and use it in GitHub Desktop.
import dspy
from tavily import TavilyClient
from typing import Literal
# Connect to and set an LLM
lm = dspy.LM('openai/gpt-5-mini', api_key='YOUR_OPENAI_API_KEY')
dspy.configure(lm=lm)
# Set up our search tools
tavily_client = TavilyClient(api_key=TAVILY_API)
def internet_search(query: str, max_results: int = 5, include_raw_content: bool = False):
"""Run a web search"""
return tavily_client.search(
query, max_results=max_results,
include_raw_content=include_raw_content,
topic="general",
)
def read_webpage(url: str) -> dict:
"""Read the content of a URL."""
response = tavily_client.extract(url)
return response
# Define our programs
clarifying_signature = "research_request: str, number_of_questions: int -> clarifying_questions: list[str]"
clarifier = dspy.Predict(clarifying_signature)
researcher_signature = "research_request: str, clarifying_questions_and_answers -> report: str"
researcher = dspy.ReAct(researcher_signature, tools=[internet_search, read_webpage])
# Main
#
# Generate our questions
results = clarifier(research_request=research_request, number_of_questions=3)
# Get our answers
q_and_a = []
for question in results.clarifying_questions:
answer = input(f"{question}\n")
q_and_a.append({"clarifying_question": question, "user_guidance": answer})
# Run the researcher
report = deep_researcher_with_clarification(
research_request=research_request,
clarifying_questions_and_answers=q_and_a
)
print(result.report)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment