Back to Llama Index

Setup OpenAI Agent

llama-index-integrations/tools/llama-index-tools-google/examples/google_calendar.ipynb

0.14.21860 B
Original Source
python
# Setup OpenAI Agent
import os 

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

from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
python
# Import and initialize our tool spec
from llama_index.tools.google_calendar.base import GoogleCalendarToolSpec

tool_spec = GoogleCalendarToolSpec()
python
# Create the Agent with our tools
agent = FunctionAgent(
    tools=tool_spec.to_tool_list(), 
    llm=OpenAI(model="gpt-4.1"),
)

# Context to store chat history
from llama_index.core.workflow import Context
ctx = Context(agent)
python
await agent.run("what is the first thing on my calendar today", ctx=ctx)
python
await agent.run(
    "Please create an event for june 15th, 2023 at 5pm for 1 hour and invite"
    " [email protected] to discuss tax laws",
    ctx=ctx,
)