Input Schema
Pass a dict that matches the input schema.
Input Schema.
1"""2Input Schema3=============================45Input Schema.6"""78from typing import List910from kern.agent import Agent11from kern.models.openai import OpenAIResponses12from kern.tools.hackernews import HackerNewsTools13from pydantic import BaseModel, Field141516class ResearchTopic(BaseModel):17 """Structured research topic with specific requirements"""1819 topic: str20 focus_areas: List[str] = Field(description="Specific areas to focus on")21 target_audience: str = Field(description="Who this research is for")22 sources_required: int = Field(description="Number of sources needed", default=5)232425# Define agents26# ---------------------------------------------------------------------------27# Create Agent28# ---------------------------------------------------------------------------29hackernews_agent = Agent(30 name="Hackernews Agent",31 model=OpenAIResponses(id="gpt-5-mini"),32 tools=[HackerNewsTools()],33 role="Extract key insights and content from Hackernews posts",34 input_schema=ResearchTopic,35)3637# ---------------------------------------------------------------------------38# Run Agent39# ---------------------------------------------------------------------------40if __name__ == "__main__":41 # Pass a dict that matches the input schema42 hackernews_agent.print_response(43 input={44 "topic": "AI",45 "focus_areas": ["AI", "Machine Learning"],46 "target_audience": "Developers",47 "sources_required": "5",48 }49 )5051 # Pass a pydantic model that matches the input schema52 hackernews_agent.print_response(53 input=ResearchTopic(54 topic="AI",55 focus_areas=["AI", "Machine Learning"],56 target_audience="Developers",57 sources_required=5,58 )59 )Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/02_input_output45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python input_schema.py