Back to Llama Index

Setup OpenAI Agent

llama-index-integrations/tools/llama-index-tools-notion/examples/notion.ipynb

0.14.21901 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.notion.base import NotionToolSpec

notion_token = "secret_your-key"
tool_spec = NotionToolSpec(integration_token=notion_token)
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
print(
    await agent.run(
        "append the heading 'I Am Legend' to the movies page",
        ctx=ctx,
    )
)
python
print(
    await agent.run(
        "append the heading 'I Am Legend' to the movies page",
        ctx=ctx,
    )
)