You.com 成为 Pydantic AI 的一项能力
You.com is now a Pydantic AI capability
Pydantic AI Harness 新增来自 You.com 的两项 Web 搜索能力 YouSearch 与 YouResearch,共提供五个 API。示例中,精简智能体单次搜索 3 条结果、上限 2,000 字符,成本约 $0.01;详尽智能体取 8 条结果并使用 full_page 与 YouResearch,成本约 $0.13,两者均返回价格与日期两个字段并归入同一个 Logfire span。YouResearch 的 research_effort 支持 lite、standard、deep、exhaustive,timeout_ms 默认十分钟。
正文
当前显示原文,中文全文译文尚未就绪。
Pydantic AI Harness now has two new web search capabilities from You.com, YouSearch and YouResearch. Each one comes with web search APIs that provide real-time LLM-ready access to the web and perform deep research for agentic workflows.
Five APIs, two capabilities. YouSearch for surveying and reading, YouResearch for the questions a single lookup cannot settle.
Here is how each part works, and what to set before an agent starts reading the open web on your behalf.
#Two agents, same question, 8x more input tokens
To illustrate how the two capabilities compare, two agents run the same prompt: what is the latest price of silver per troy ounce.
Here is the gist with the full code. To run, follow the instructions below. This post is a walkthrough of the code shown in the gist.
In this example, the lean agent performs a single search with three results and a 2,000 character cap. It costs about $0.01. The thorough agent gets eight results and full_page, a second search wrapped in PrefixTools and pinned to two domains you add, and YouResearch returning a typed brief. It costs about $0.13. Both return the same two fields, a price and a date, and both nest under one Logfire span, so the bill reads straight off the trace tree.
Building agents in production?
See what they're actually doing with Logfire — traces, evals, cost, and behavior in one view.
#Getting started
Start by installing the required libraries. I'm using Pydantic AI as the agent framework, Pydantic Logfire as the observability layer and Anthropic as the model provider.
Create your access keys at you.com/platform, and your model provider's key. Export both with:
In this example, the model provider uses Pydantic AI Gateway with PYDANTIC_AI_GATEWAY_API_KEY. To set your key, enable the Gateway in Logfire and click the API Keys tab, as shown on the video below. You can choose to set up a custom provider by bringing your own key (BYOK), or create a key using built-in providers on Logfire. This allows you to swap models seamlessly, set up spending caps, assign budgets per key or project, and more.
You can also use your model provider's API key directly (ANTHROPIC_API_KEY, in this case) and replace the Agent string with 'anthropic:claude-sonnet-5' or any other model you'd like to use.
One list entry, and the agent can search the web. It comes with its tools, instructions, and settings already wired together with capabilities=[YouSearch(), YouResearch()].
Now add the settings that turn it into a survey:
Three settings cap what this agent can read. num_results=3 cuts the default of ten. extraction_mode='highlights' returns query-relevant excerpts only, instead of entire page bodies. max_text_chars=2_000 truncates anything that comes back, down from a default of 10,000. num_results=3 × max_text_chars=2_000 caps the agent at 6,000 characters of web text per call, whatever you ask it. freshness='week' keeps quotes older than a week out of the results.
output_type=SilverBrief sets the shape of the reply to a Pydantic BaseModel, so you get a float and a date string, according to what you specify. It does not change how much reading happens first. Both return the same two fields, while the thorough run uses substantially more input and costs more to produce them.
#Setting that decides how much text comes back
web_search defaults to extraction_mode='highlights', so each result arrives as excerpts and looking at eight sources stays affordable. The model then picks what to read with get_page. Switch to extraction_mode='full_page' when you would rather have the markdown up front.
Full page text, from either tool, is capped at max_text_chars. The cap keeps the head of the document, since a page's lead usually carries the substance, and appends a [... page text truncated at N characters] marker so the model knows it is holding part of a page. num_results is enforced twice, once in the request to You.com and again on the response.
Empty results are not a failure. A query that matches nothing returns No results found for {query!r}., which the model can pass to the user or use to reword the search. Real problems arrive as a ModelRetry: a rate limit, a URL that came back empty, a parameter You.com rejected, a network blip. The run continues and the model gets another go. Authentication, billing, and permission errors stop it, because those are yours to fix and no amount of retrying helps.
#Research, and how hard it works
Use answer for a question you expect one call to settle. Use research when it needs many searches and a synthesis across them. finance_research is the same loop tuned for financial analysis.
research waits for its result instead of returning a job to poll, and a deep pass regularly runs for minutes, so timeout_ms defaults to ten minutes. Effort is set per capability with research_effort: lite, standard, deep, or exhaustive. You.com also has a frontier level, which only runs as a background job, so it is not offered here. finance_research takes its own finance_effort, either deep or exhaustive.
For a structured report output, give research a JSON schema:
Without extra='forbid', You.com rejects the schema. It only accepts one that closes itself to extra keys, and that config is what puts additionalProperties: false in the generated JSON. Leave it out and the model gets a validation error back on its first research call, several minutes in.
The other rule is checked earlier: You.com rejects a schema at lite effort, and the capability catches that pairing when you construct it.
#Citations your application can render
Every one of the five tools returns a ToolReturn. The model sees return_value, the text, with a Sources: block appended when the tool has citations. Your application reads metadata['sources'], the same sources as YouSource records:
The model never sees metadata, so nothing here competes for context, and the footnotes in your UI never depend on the model repeating a URL correctly. web_search puts the response's search_uuid and latency in there too, which is what you want in a trace when a run went sideways, and you need to ask You.com about one specific query.
#Scoping what it reads
Both capabilities take the same controls, and they reach web_search, answer, and research. finance_research is the exception: it takes its input and finance_effort, nothing else, so a domain filter you set will not narrow it. include_domains is an allowlist and cannot be combined with either. exclude_domains and boost_domains do combine, so a denylist and a re-rank work together. freshness takes day, week, month, year, or a YYYY-MM-DDtoYYYY-MM-DD range, and country takes a two-letter code. Bad values raise at construction time.
One agent, two search setups, is a common ask: the open web for context, a couple of trusted domains for anything it will cite. Two instances of the same capability would register the same tool names, so wrap the second in core's PrefixTools:
The agent above removes the lean agent's limits, adds a second search pinned to two domains, and sends the write-up through research.
Set guidance='' on the wrapped instance, or replace it with text explaining when the prefixed tools apply. Otherwise, both instances contribute the same default paragraph.
The same naming rule is why an agent gets one web search capability. Anything else registering a web_search tool collides with YouSearch, and the agent fails at construction rather than at the first call. Wrap one of them in PrefixTools if you want both.
#What the tools cost
Eight results at full_page and 20,000 characters each is a 160,000 character ceiling, against the lean agent's 6,000. Both runs nest under one Logfire span, so the token counts sit next to each other in the trace tree:
The two differ in capabilities and instructions; the capability differences are:
Each run calls both agents back to back on the same question, so the lean number and the thorough number come from the same minute of the web. The figures below are five such runs, and the headline is the median of the five ratios.
Eight times the input for the same two fields. Across the five runs the paired ratio ran from 5.4x to 11.8x, median 8.2x.
One tool call accounts for most of that. research took a median 16.3 seconds, 62% of the thorough run's wall time, and carries most of the token difference.
Instructions decide whether the expensive tool runs at all. research_effort only decides how long it runs once it does. With the wording above, research was called in all five runs and the thorough agent's input tokens varied by 1.4%, from 65,075 to 67,698.
The lean agent's input tokens varied from 5,581 to 12,160 across the same five runs, because nothing anchors what a highlights search returns except what the web served when the agent called.
Five runs inside seven minutes measures the configuration. It does not measure how either agent behaves on a day when silver is actually moving.
Whether the trade is worth making is a question for the human in the loop. The thorough brief cites its sources and checks the quoted price against a domain. The lean one returns a number from the open web in five seconds.
#Why this pairing works
An agent that reads the web is an agent whose answers depend on things you do not control. Pages change, a search returns something odd, a summary quietly drops the one source that mattered. None of that has to be guesswork. The tool definitions are typed and the outputs are validated, so a malformed result fails where you can see it, and Pydantic Logfire keeps the receipt: which queries ran, what came back, which pages were read in full, and what the whole run cost.
You.com's contribution is retrieval that already distinguishes an excerpt from a page from a research pass, so your agent code does not have to invent that distinction on top of a single search endpoint.
Some caveats before you ship:
Harness is on 0.x releases, so the API can change between minor versions. Changes come with deprecation warnings and migration guidance in the release notes; research blocks for the length of the pass. At deep or exhaustive, size the surrounding request timeouts for minutes, not seconds; A prebuilt client is used as given, so its timeout and host are yours to configure. timeout_ms only applies to the default client; Domain filters shape what the agent can see. They are not a security boundary for what it can be told by a page it does read
#Try it
When you want more than the first run:
The You.com capability docs carry the full reference for YouSearch, YouResearch, and their toolsets; The Pydantic AI Harness capabilities docs list every available capability, written to be read and copied, with examples and tool descriptions behind each capability; You.com keeps four worked cookbooks of their own, each grounded in a different field: an antimicrobial resistance brief through research, a survey of K-12 teacher retention on YouSearch, a private credit read through finance_research, and a due-diligence desk that routes across all three with SubAgents. Start there if your domain is closer to one of those than to a generic search agent; Every agent above is traced with Pydantic Logfire, which turns each run into a trace you can open and query with SQL: searches, page reads, retries, token costs. Keep the Logfire MCP server open while you debug one and your agent can read its own traces back to you; Pydantic Evals is the next thing you want once the agent is choosing its own sources, so a prompt change that sharpens one question does not blunt another
If you build something good with this, we would like to see it. The harness lives on GitHub, the issues are open, and the capability shelf grows mostly because people tell us what is missing from it. Come say hello in the Pydantic Slack.
Together, these are pieces of the Pydantic Stack. Try it out!