File size: 1,343 Bytes
aa9134d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from agents import Agent, ModelSettings, function_tool
from duckduckgo_search import DDGS
from model import model
from writer_agent import writer_agent

INSTRUCTIONS = (
    "You are a research assistant. Given a search term, you search the web for that term and "
    "produce a concise summary of the results. The summary must 2-3 paragraphs and less than 300 "
    "words. Capture the main points. Write succintly, no need to have complete sentences or good "
    "grammar. This will be consumed by someone synthesizing a report, so its vital you capture the "
    "essence and ignore any fluff. Do not include any additional commentary other than the summary itself."
)

@function_tool
def duckduckgo_search(query: str, max_results: str = 5) -> list[dict]:
    """Search the web using DuckDuckGo and return results."""
    # Cast to int just in case the model passes a string
    max_results = int(max_results)
    with DDGS() as ddgs:
        return [r for r in ddgs.text(query, max_results=max_results)]

search_agent = Agent(
    name="Search agent",
    instructions=INSTRUCTIONS,
    tools=[duckduckgo_search],
    model=model,
    handoff_description='After searching, handoff to writer_agent to generate a report',
    handoffs=[writer_agent],
    model_settings=ModelSettings(tool_choice="required"),
)