search_the_web from yesterday returns a long string with citations and summaries. Your literature note needs a single structured fact — main claim and source — not a multi-paragraph search result. How do you extract the key fact from the search output?
Chain it. Run the search agent, pass the output to an extraction agent with a Fact Pydantic model — fact: str and source: str — same structured output pattern from Day 10. The search result is the input to the extractor.
Exactly. Two agents, one chain:
from pydantic import BaseModel
class Fact(BaseModel):
fact: str
source: str
search_result = Agent(model).run_sync(topic).output
extract_agent = Agent(model, result_type=Fact)
return extract_agent.run_sync(search_result).output.model_dump()The search agent and extract agent both use model. Are they the same model?
In this lesson both use the ai-search model (Perplexity/sonar). In the Day 28 capstone, the search step explicitly uses the search model and the extraction step uses a basic model. For today, model is consistent across both calls — the extraction works because Perplexity can handle structured output as well as search.
So I'm asking a search engine to extract a structured fact from its own search result. That's a slightly recursive call, but it works.
It works because the extraction task is simple — pull the main claim and the source citation from the search text. The model handles both tasks at this scale.
Search result in, structured {"fact": "...", "source": "..."} out. I can append that dict to my citations Sheet directly. That's the first step of the automated literature pipeline.
The append step is one line:
finding = research_and_extract(topic)
print(finding["fact"][:80])
print("Source:", finding["source"])Verify the extracted source against the original — the model may paraphrase citations.
from pydantic import BaseModel
class Fact(BaseModel):
fact: str
source: str
# Step 1: search
search_result = Agent(model).run_sync(topic).output
# Step 2: extract structured fact
extract_agent = Agent(model, result_type=Fact)
return extract_agent.run_sync(search_result).output.model_dump()Search and extraction are different tasks. Separating them lets you tune each agent independently — different system prompts, different result_type, different models if needed.
The extracted source field may paraphrase the citation or miss author details. Always cross-check against the raw search result before adding to a formal bibliography. The structured extraction is a discovery aid; the original paper is the ground truth.
search_the_web from yesterday returns a long string with citations and summaries. Your literature note needs a single structured fact — main claim and source — not a multi-paragraph search result. How do you extract the key fact from the search output?
Chain it. Run the search agent, pass the output to an extraction agent with a Fact Pydantic model — fact: str and source: str — same structured output pattern from Day 10. The search result is the input to the extractor.
Exactly. Two agents, one chain:
from pydantic import BaseModel
class Fact(BaseModel):
fact: str
source: str
search_result = Agent(model).run_sync(topic).output
extract_agent = Agent(model, result_type=Fact)
return extract_agent.run_sync(search_result).output.model_dump()The search agent and extract agent both use model. Are they the same model?
In this lesson both use the ai-search model (Perplexity/sonar). In the Day 28 capstone, the search step explicitly uses the search model and the extraction step uses a basic model. For today, model is consistent across both calls — the extraction works because Perplexity can handle structured output as well as search.
So I'm asking a search engine to extract a structured fact from its own search result. That's a slightly recursive call, but it works.
It works because the extraction task is simple — pull the main claim and the source citation from the search text. The model handles both tasks at this scale.
Search result in, structured {"fact": "...", "source": "..."} out. I can append that dict to my citations Sheet directly. That's the first step of the automated literature pipeline.
The append step is one line:
finding = research_and_extract(topic)
print(finding["fact"][:80])
print("Source:", finding["source"])Verify the extracted source against the original — the model may paraphrase citations.
from pydantic import BaseModel
class Fact(BaseModel):
fact: str
source: str
# Step 1: search
search_result = Agent(model).run_sync(topic).output
# Step 2: extract structured fact
extract_agent = Agent(model, result_type=Fact)
return extract_agent.run_sync(search_result).output.model_dump()Search and extraction are different tasks. Separating them lets you tune each agent independently — different system prompts, different result_type, different models if needed.
The extracted source field may paraphrase the citation or miss author details. Always cross-check against the raw search result before adding to a formal bibliography. The structured extraction is a discovery aid; the original paper is the ground truth.
Create a free account to get started. Paid plans unlock all tracks.