> ## Documentation Index
> Fetch the complete documentation index at: https://docs.a1facts.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Clinical Trials Agent

> This example demonstrates how to use `a1facts` to build an agent that can answer questions about clinical trials from various sources.

This agent can answer complex questions about clinical trials by using a knowledge graph and external data sources to provide accurate, consolidated information.

## How it Works

The agent is built using the following components, which you can find in the `cookbook/clinical_trials` directory:

<CardGroup>
  <Card title="`trialsagent.py`" icon="robot">
    The main script that creates and runs the agent. It initializes the `a1facts` tool, which acts as the bridge between the agent and the knowledge graph.
  </Card>

  <Card title="`trials.yaml`" icon="sitemap">
    This file defines the schema of our knowledge graph. It specifies the types of entities (e.g., `ClinicalTrial`, `Drug`, `Condition`) and the relationships between them.
  </Card>

  <Card title="`sources.yaml`" icon="cloud-download">
    This file configures the external data sources that the agent can query for information about clinical trials.
  </Card>
</CardGroup>

When you run `trialsagent.py`, it initializes an agent with the `a1facts` tool. The agent is then asked a complex query about clinical trials. The `a1facts` tool uses the information from `trials.yaml` and `sources.yaml` to understand the query, fetch relevant data, and then synthesize a precise answer.

## Running the Example

<Steps>
  <Step title="Set up your environment">
    Create a `.env` file in the `a1facts/cookbook/clinical_trials` directory and add your API keys:

    ```dotenv .env theme={null}
    OPENAI_API_KEY="your_openai_api_key"
    EXA_API_KEY="your_exa_api_key"
    ```
  </Step>

  <Step title="Run the agent">
    Navigate to the `a1facts/cookbook/clinical_trials` directory and run the following command:

    ```bash theme={null}
    uv run python trialsagent.py
    ```
  </Step>

  <Step title="Expected Output">
    The agent will run the query and print a detailed answer to the console, consolidating information from the knowledge graph and external sources to address the complex query about clinical trials.
  </Step>
</Steps>
