Back to Llama Index

Setup OpenAI Agent

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

0.14.21944 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.gmail.base import GmailToolSpec

tool_spec = GmailToolSpec()
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(
    "Can you create a new email to helpdesk and support @example.com about a service"
    " outage",
    ctx=ctx,
)
python
await agent.run("Update the draft so that it's the same but from 'Adam'", ctx=ctx)
python
await agent.run("display the draft", ctx=ctx)
python
await agent.run("send the draft email", ctx=ctx)