Skip to main content

Create and Prompt Your First Agent

This guide walks you through creating a research-oriented agent designed for long, technical documents and multi-step reasoning. The agent uses Agent Composer (AC) to run a graph-based workflow that performs iterative retrieval, analysis, and synthesis across complex source material. The document set for this tutorial consists of NASA technical reports focused on Fault Detection, Isolation, and Recovery (FDIR) in safety-critical autonomous systems. These documents are intentionally dense and fragmented, making them ideal for demonstrating agentic research rather than simple single-pass RAG.

Learning Outcomes

By completing this quickstart, you’ll learn how to:
  1. Create and configure datastores for securely storing and indexing long technical documents
  2. Ingest complex PDFs with hierarchy-aware parsing, including figures, tables, and cross-references
  3. Define a research workflow using a default Agent Composer YAML graph
  4. Create an agent that uses Agent Composer to perform multi-document research and synthesis
  5. Query and interact with the agent through both the UI and API, observing retrievals, generation, and workflow execution
⏱️ This tutorial can be completed in under 15 minutes. All steps can also be performed through the GUI for a no-code Agent Composer experience.

Step 0: Set Up Your Environment

Start by installing the required dependencies and setting up your development environment. The contextual-client library provides Python bindings for the Contextual AI platform, while the additional packages support data visualization and progress tracking.
Next, import the necessary libraries that you’ll use throughout this quickstart:

API Authentication Setup

Before we can start building our RAG agent, you’ll need access to the Contextual AI platform. Step-by-Step API Key Setup:
  1. Create Your Account: Visit app.contextual.ai and click the “Start Free” button
  2. Navigate to API Keys: Once logged in, find “API Keys” in the sidebar
  3. Generate New Key: Click “Create API Key” and follow the setup steps
  4. Store Securely: Copy your API key and store it safely (you won’t be able to see it again)
API Keys page in the Contextual AI platform
Configuring Your API Key To run this quickstart, you can store your API key in a .env file. This keeps your keys separate from your code. After setting up your .env file, you can load the API key from .env to initialize the Contextual AI client. Feel free to use Google Secrets as well if in Google Colab. Now, you can load the API key from .env to initialize the Contextual AI client.

Step 1: Create Your Document Datastore

A datastore in Contextual AI is a secure, isolated container for your documents and their processed representations. Each datastore provides:
  • Isolated Storage: Documents are kept separate and secure for each use case
  • Intelligent Processing: Automatic parsing, chunking, and indexing of uploaded documents
  • Optimized Retrieval: High-performance search and ranking capabilities

Why Separate Datastores?

Each agent should have its own datastore to ensure:
  • Data isolation between different use cases
  • Security compliance for sensitive document collections
  • Performance optimization agents can be customized for specific document types and query patterns
Let’s create a datastore for our NASA document analysis agent:

Step 2: Document Ingestion and Processing

Now that your agent’s datastore is set up, let’s add a collection of NASA technical documents focused on Fault Detection, Isolation, and Recovery (FDIR). Contextual AI’s document processing engine provides enterprise-grade parsing that is well-suited for dense engineering and research content, including:
  • Complex Tables: Experimental results, system parameters, and evaluation metrics
  • Charts and Figures: Architecture diagrams, fault trees, and performance plots
  • Multi-page Technical Documents: Long reports with deep hierarchical structure, appendices, and references
These capabilities are critical for enabling research and synthesis workflows, where no single document contains a complete answer.

Supported File Formats

The platform supports a wide range of document formats commonly used in technical and research workflows:
  • PDF: Research papers, technical reports, and whitepapers
  • HTML: Saved web pages and online documentation
  • DOC/DOCX: Technical notes and written analyses
  • PPT/PPTX: Conference presentations and engineering briefings

Sample NASA FDIR Documents

For this quickstart, we intentionally use complex, unstructured technical documents rather than clean or structured datasets. The document set includes NASA technical reports covering:
  • Fault detection, isolation, and recovery (FDIR) in safety-critical systems
  • Autonomous fault recovery for distributed electric propulsion aircraft
  • Certification methodologies for lunar surface autonomy and construction missions
  • System health management and failure analysis in tightly coupled subsystems
Readers are encouraged to open and skim the source documents directly to understand their length, structure, and technical depth: These documents are deliberately chosen to be dense, technical, and fragmented across sources, making them ideal for demonstrating why agentic research and multi-document synthesis (not just simple RAG) is valuable.

Preparing the Document Collection

Next, we’ll upload these documents into the datastore. Once ingested, Contextual AI will automatically:
  • Parse and extract text from each document
  • Chunk content for efficient hybrid (semantic + lexical) retrieval
  • Index the documents for grounded research and synthesis
This processed document set will serve as the knowledge foundation for the Agent Composer workflow you’ll build in the following steps.

Document Download & Ingestion Process

The following cell will:
  • Download documents from Contextual AI’s examples repository (if not already cached)
  • Upload to Contextual AI for intelligent processing
  • Track processing status and document IDs for later reference

Step 3: Inspect Your Documents

Let’s take a look at our documents at https://app.contextual.ai/
  1. Navigate to your workspace
  2. Select Datastores on the left menu
  3. Select Documents
  4. Click on Inspect (once documents load)
You will see datastore uploads in progress. Click through the documents to see how they are chunked! Once ingested, you can view the list of documents, see their metadata, and also delete documents via API.
It may take a few minutes for the document to be ingested and processed. If the documents are still being ingested, you will see status='processing'. Once ingestion is complete, the status will show as status='completed'.
You can learn more about the metadata here.

Step 4: Agent Creation & Configuration

Now you’ll create an Agent Composer agent via the API by attaching a YAML workflow. This defines the agent as a graph of steps (research + generation), rather than a single fixed RAG path.
Example Response:

Step 5: Analyze Your Agent (optional)

Open the Agent in the UI

  • Go to: app.contextual.ai
  • Navigate: Agents -> select your agent: NASA_FDIR_AC_Demo
  • Confirm the linked datastore is your semiconductor documents datastore.

Open Agent Composer

Inside the agent page:
  • Click Agent Composer (or AC) You should see one of:
    • Workflow Builder (graph view)
    • YAML editor (text view)

Workflow Builder (Graph View)

  • Open Workflow Builder Confirm the graph contains the core steps:
    • CreateMessageHistoryStep
    • AgenticResearchStep (streams retrievals)
    • GenerateFromResearchStep (streams generation)
    • Output node wired to response

YAML View

  • Open the YAML editor
  • Confirm the YAML matches the acl_yaml you used in the API section.

Step 6: Query the Agent in the API

Example Response:

Next Steps