Skip to main content
This notebook shows how to use agents to interact with the NASA toolkit. The toolkit provides access to the NASA Image and Video Library API, with potential to expand and include other accessible NASA APIs in future iterations. Note: NASA Image and Video Library search queries can result in large responses when the number of desired media results is not specified. Consider this prior to using the agent with LLM token credits.

Example use


Initializing the agent

pip install -qU langchain langchain-community langchain-openai
from langchain.agents import create_agent
from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit
from langchain_community.utilities.nasa import NasaAPIWrapper
from langchain_openai import OpenAI

llm = OpenAI(model="gpt-4o-mini", temperature=0)
nasa = NasaAPIWrapper()
toolkit = NasaToolkit.from_nasa_api_wrapper(nasa)

agent = create_agent(
    model=llm,
    tools=toolkit.get_tools(),
)

Querying media assets

agent.invoke(
    "Can you find three pictures of the moon published between 2014 and 2020?"
)

Querying details about media assets

output = agent.invoke(
    "Where can I find the metadata manifest for NASA asset NHQ_2019_0311?"
)

print(output)

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.