Seb Duerr
January 20, 2026
Open in GithubJanuary 20, 2026
- 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
- PydanticAI Agent Architecture - Building conversational agents with tools
- Cerebras Integration - Using Cerebras LLMs with PydanticAI
- Pydantic Schemas - Type-safe structured outputs from LLMs
- Unstructured - High-quality PDF text extraction
- 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:- Cerebras: https://cloud.cerebras.ai (free tier available)
- Unstructured: https://unstructured.io (free tier available)
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’sRunContext. 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 samestrict 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-120bmodel ResearchDepsfor dependency injectionprepare_toolshook 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’shi_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:- Generate search queries
- Search arXiv
- Analyze abstracts
- Download and process PDFs
- Perform deep analysis
- Synthesize findings
- 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-120bfor fast, high-quality reasoning - Unstructured for PDF text extraction
- Pydantic schemas for type-safe structured outputs
Key Patterns
- Cerebras Strict Mode: Use
prepare_toolshook to normalize all tools tostrict=False - Dependency Injection: Use
RunContext[ResearchDeps]to share API clients and caches - Schema Validation: Validate all LLM outputs with Pydantic models
- Error Resilience: Tools return error messages instead of raising exceptions
- 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)

