{"slug": "give-a-pydantic-ai-agent-live-web-search-and-news-with-one-capability", "title": "Give a Pydantic AI agent live web search and news with one capability", "summary": "NestDaddy published pydantic-ai-nestdaddy, an MIT-licensed Pydantic AI capability that adds three tools — search_web, search_news and read_page — to an agent in one line, installable via pip with a NESTDADDY_API_KEY. In a test run on 3 December 2026 with Pydantic AI 2.78 and the local qwen2.5:7b model via Ollama, the agent made a single search_news call with num_results set to 3 and returned three linked headlines; the capability's country filter (set to US) was needed because the same query without it returned mostly Chinese-language articles. The toolset catches malformed arguments locally and retries up to three times without spending an API call, while bad keys, exhausted quota and network failures raise NestDaddyError.", "body_md": "# Give a Pydantic AI agent live web search and news with one capability\n\npydantic-ai-nestdaddy adds web search, news search by country and page reading to a Pydantic AI agent in one line. Install, run it with a free local model, use it in an agent spec, or take just the toolset.\n\nA language model knows what it was trained on. It does not know what happened this morning, and it cannot read the page behind a headline. Pydantic AI has a clean answer for extending an agent: a **capability** that bundles tools and the instructions for using them.\n\nWe published one for NestDaddy: [`pydantic-ai-nestdaddy`](https://pypi.org/project/pydantic-ai-nestdaddy/) ([source on GitHub](https://github.com/nestdaddy-ai/pydantic-ai-nestdaddy), MIT). It gives an agent three tools and a short instruction on when to use each.\n\n| Tool | What it does | \n|---|---|\n| `search_web` | Web results with title, url, snippet and domain. | \n| `search_news` | Real-time news, newest and best match first, filtered by age in days and by a two-letter country code. | \n| `read_page` | The clean full text of a page or article, so the agent reads the source before it states details. | \n\n## Install\n\n```\npip install pydantic-ai-nestdaddy \"pydantic-ai-slim[openai]\"\nexport NESTDADDY_API_KEY=\"your-key\"\n```\n\nGet a key at [nestdaddy.com/dashboard](https://nestdaddy.com/dashboard) (a free plan is available).\n\n## One line\n\nThis runs a free local model through Ollama (`ollama pull qwen2.5:7b`). For a hosted model, pass a name such as `\"openai:gpt-5\"` instead.\n\n``` python\nfrom pydantic_ai import Agent\nfrom pydantic_ai.models.openai import OpenAIChatModel\nfrom pydantic_ai.providers.ollama import OllamaProvider\nfrom pydantic_ai_nestdaddy import NestDaddyCapability\n\nmodel = OpenAIChatModel(\"qwen2.5:7b\", provider=OllamaProvider(base_url=\"http://localhost:11434/v1\"))\nagent = Agent(model, capabilities=[NestDaddyCapability(country=\"US\", news_days=2)])\n\nresult = agent.run_sync(\"What happened in AI today? Give 3 headlines with links.\")\nprint(result.output)\n```\n\n## What we got\n\nWe ran exactly this on 3 December 2026 with Pydantic AI 2.78 and `qwen2.5:7b`. The agent made one call, `search_news {\"query\": \"AI\", \"num_results\": 3}`, and answered with three headlines, each linked to its source:\n\n1. What Healthcare's AI Leaders Can Teach About Checking AI's Work (Forbes)\n2. AI Has So Many Problems. Local AI Might Solve Them All (Wired)\n3. Suno Tries to Tie Christmas to AI With Holiday Remixes (Variety)\n\nWithout `country=\"US\"` the same question returns the world's news, which on that day was mostly Chinese-language articles. That is the point of the country filter: say where the news should come from.\n\n## Options\n\nAll optional: `api_key` (otherwise `NESTDADDY_API_KEY`), `num_results` (default 10), `news_days` (default 30), `country`, `max_chars` for `read_page` (default 8000) and `timeout`.\n\n## Only the tools\n\nIf you prefer a plain toolset to a capability:\n\n``` python\nfrom pydantic_ai import Agent\nfrom pydantic_ai_nestdaddy import nestdaddy_toolset\n\nagent = Agent(\"openai:gpt-5\", toolsets=[nestdaddy_toolset(country=\"US\")])\n```\n\n## Agent specs\n\nEvery field is serializable, so the capability works in a YAML agent spec. This needs PyYAML (`pip install \"pydantic-ai-slim[spec]\"`).\n\n```\nmodel: openai:gpt-5\ncapabilities:\n  - NestDaddy:\n      country: GB\n      news_days: 7\npython\nfrom pydantic_ai import Agent\nfrom pydantic_ai_nestdaddy import NestDaddyCapability\n\nagent = Agent.from_file(\"agent.yaml\", custom_capability_types=[NestDaddyCapability])\n```\n\n## How it behaves when something goes wrong\n\n- A one-character query, a malformed country code or a URL without `http` is caught locally and sent back to the model as a retry, without spending an API call.\n- A 400 or 422 from the API is also a retry, so the model can fix its own arguments. The toolset allows three retries.\n- A bad key, a used-up quota or a network failure raises `NestDaddyError` with a clear message, because the model cannot fix those.\n\nThe tests run offline through `httpx.MockTransport`, so you can read them as documentation of the exact requests the tools send.\n\n## Why a capability and not just functions\n\nYou can always write two plain functions, and we show that in our [Pydantic AI guide](https://nestdaddy.com/integrations/pydantic-ai). A capability adds the part people forget: the instruction that tells the model *when* to search news, *when* to search the web, and to read a page before relying on its details. Small local models in particular get this wrong without it. If the agent builds on a model with a short memory of the world, [how to build an AI agent from scratch](https://nestdaddy.com/blog/how-to-build-an-ai-agent-from-scratch) explains why the reading step matters.\n\n## Next\n\nThe package and its [PyPI page](https://pypi.org/project/pydantic-ai-nestdaddy/) are live now. If you build agents in another framework, the same search, news and page reading come as an [MCP server](https://nestdaddy.com/mcp) for Claude, Cursor and VS Code, and as plain REST calls in the [API docs](https://nestdaddy.com/apis).", "url": "https://wpnews.pro/news/give-a-pydantic-ai-agent-live-web-search-and-news-with-one-capability", "canonical_source": "https://nestdaddy.com/blog/pydantic-ai-web-search-news", "published_at": "2026-12-02 18:45:36.534830+00:00", "updated_at": "2026-12-02 18:45:38.714563+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-search"], "entities": ["NestDaddy", "Pydantic AI", "pydantic-ai-nestdaddy", "Ollama", "qwen2.5:7b", "NestDaddyCapability", "NestDaddyError"], "also_reported_by": [], "takeaway": "pydantic-ai-nestdaddy bundles search_web, search_news and read_page into one Pydantic AI capability, and setting country=\"US\" on search_news changed results from mostly Chinese-language articles to US outlets on the 3 December 2026 test.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/give-a-pydantic-ai-agent-live-web-search-and-news-with-one-capability", "markdown": "https://wpnews.pro/news/give-a-pydantic-ai-agent-live-web-search-and-news-with-one-capability.md", "text": "https://wpnews.pro/news/give-a-pydantic-ai-agent-live-web-search-and-news-with-one-capability.txt", "jsonld": "https://wpnews.pro/news/give-a-pydantic-ai-agent-live-web-search-and-news-with-one-capability.jsonld"}}