Skip to main content
Seb Duerr
January 20, 2026
Open in Github
This cookbook demonstrates how to build a conversational agent that:
  • Generates diverse arXiv search queries
  • Searches and analyzes academic papers
  • Downloads and processes PDFs with Unstructured
  • Performs deep analysis and synthesizes research insights and saves them as reports

What You’ll Learn

  1. PydanticAI Agent Architecture - Building conversational agents with tools
  2. Cerebras Integration - Using Cerebras LLMs with PydanticAI
  3. Pydantic Schemas - Type-safe structured outputs from LLMs
  4. Unstructured - High-quality PDF text extraction
  5. Tool Design - Creating effective agent tools with RunContext

Setup

Install Dependencies

Load API Keys

Get API keys to get started with super fast inference, and Unstructured’s powerful document procesing: Next, we suggest to add the secrets in the Google Collab Password service, or via a .env file, if you cloned the repository.

Part 1: Pydantic Schemas

We are using Pydantic models for type safety. Pydantic is a production grade typing framework, that helps to create reliable LLM responses. These schemas:
  • Guide the LLM on expected output structure
  • Validate responses automatically
  • Provide type hints throughout the codebase

Example: Using Schemas for Type Safety

Here’s how schemas validate LLM outputs:

Part 2: Dependencies & Configuration

The agent uses dependency injection via PydanticAI’s RunContext. This allows tools to access shared resources like API clients and caches.

Part 3: Cerebras in Strict Mode

Important: Cerebras requires all tools to have the same strict parameter value. PydanticAI may generate tools with mixed values, which causes errors. We proactively avoid this with a prepare_tools hook that normalizes all tools to strict=False:

Part 4: Create the Agent

Now we instantiate the PydanticAI agent with:
  • Cerebras gpt-oss-120b model
  • ResearchDeps for dependency injection
  • prepare_tools hook for strict mode
  • System prompt defining the agent’s role

Part 5: Define the 7 Research Tools

In PydanticAI, each tool is decorated with @agent.tool and receives RunContext[ResearchDeps] for dependency access.

Tool 1: Generate arXiv Search Queries

Tool 2: Search arXiv Papers

Tool 3: Analyze Paper Abstracts

Tool 4: Download and Process PDF

Next, we create a tool that downloads PDFs from arXiv and uses Unstructured’s hi_res partitioning strategy to detect document layout and extract structured elements like tables, images, and text. You can also swap this out for VLM partitioning, add chunking, enrichment (like table descriptions or NER), and embedding nodes to your workflow. Check out this notebook for a hands-on tutorial.

Tool 5: Deep Analyze Papers

Tool 6: Synthesize Research Findings

Tool 7: Save Research Report

Part 6: Conversational Interface

This function handles the conversation with the agent, including extracting the response from PydanticAI’s message structure:

Part 7: Run the Agent!

Instantiate Our Previously Created Dependencies

Example 1: Full Research Workflow

The agent will autonomously:
  1. Generate search queries
  2. Search arXiv
  3. Analyze abstracts
  4. Download and process PDFs
  5. Perform deep analysis
  6. Synthesize findings
  7. Save the report

Example 2: Quick Abstract-Only Analysis

The agent adapts to simpler requests:

Example 3: Follow-up Questions

The agent can answer follow-up questions:

Part 8: Inspect Results

View Cached Papers

View Saved Reports

Summary

What We Built

A conversational academic research agent with:
  • tools for a complete research workflow
  • PydanticAI for agent orchestration and tool management
  • Cerebras gpt-oss-120b for fast, high-quality reasoning
  • Unstructured for PDF text extraction
  • Pydantic schemas for type-safe structured outputs

Key Patterns

  1. Cerebras Strict Mode: Use prepare_tools hook to normalize all tools to strict=False
  2. Dependency Injection: Use RunContext[ResearchDeps] to share API clients and caches
  3. Schema Validation: Validate all LLM outputs with Pydantic models
  4. Error Resilience: Tools return error messages instead of raising exceptions
  5. Caching: Cache papers and full text to avoid redundant API calls

Next Steps

  • Add semantic search with vector embeddings, rather than different API calls to arxiv’s API
  • Add a citation graph analysis
  • Add multi-source search (PubMed, Semantic Scholar)

Resources

Acknowledgement

Thank you team from Pydantic AI and Unstructured for incredibly helpful inputs during the creation of this cookbook. Also a shoutout to my colleagues Zhenwei Gao, Ryan Loney and Sarah Chieng for great feedback on initial versions.