Back to Llama Index

Setup OpenAI Agent

llama-index-integrations/tools/llama-index-tools-duckduckgo/examples/duckduckgo_search.ipynb

0.14.21528 B
Original Source
python
# Setup OpenAI Agent
import os

os.environ["OPENAI_API_KEY"] = "sk-..."

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
python
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
python
agent = FunctionAgent(
    tools=DuckDuckGoSearchToolSpec().to_tool_list(),
    llm=OpenAI(model="gpt-4.1"),
)
python
print(await agent.run("Who is Goethe?"))
python
print(await agent.run("Give me a quote of Goethe (Deutsch)?"))