File size: 1,204 Bytes
979cd82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import asyncio
from pydantic import BaseModel, Field
from agents import Agent, Runner

SEARCHES = 3

planner_instructions = f""" You a helpful reasearch assitant. 

You will be given a question and you will need to come up with a set of web searches to perform the query.

Out put {SEARCHES} searches that you would perform to answer the question. 

You should only output the search query and not any other text. 

"""


## Lets create a stuctured output for the agent to return the searches in.
class SearchOutput(BaseModel):
    reason: str = Field(
        ...,
        description="Reason why the search term is accurate and will provide accurate results for the query",
    )
    query: str = Field(..., description="The search query to be performed")


class SearchPlanItems(BaseModel):
    searches: list[SearchOutput] = Field(
        ...,
        description=f"A list of search queries to be performed. Each item should be a SearchOutput object. There should be {SEARCHES} search queries in total.",
    )


planner_agent = Agent(
    name="Search Planner Agent",
    instructions=planner_instructions,
    model="gpt-4o-mini",
    output_type=SearchPlanItems,
)