API Keys & Environment
Relevant source files
The following files were used as context for generating this wiki page:
The API Keys & Environment module serves as the foundational configuration layer for the CoI-Agent system. It manages the integration of external Large Language Model (LLM) providers and academic search services, ensuring that agents have the necessary credentials and endpoints to perform research tasks, literature searches, and reasoning.
The system supports multiple LLM backends (OpenAI and Azure OpenAI) and utilizes specific environment variables to manage API routing, model selection, and search capabilities through Semantic Scholar.
Sources: config.yaml:1-22, README.md:46-72
Configuration Management
The project uses a config.yaml file to define essential API keys and service endpoints. At runtime, the main.py script parses this file and injects the values into the system's environment variables to be accessed by various modules like LLM.py and agents.py.
Environment Injection Flow
The diagram above shows how configuration data flows from the static YAML file into the runtime environment and subsequent functional modules.
Sources: main.py:10-17, LLM.py:65-103
LLM Provider Integration
CoI-Agent is designed to work with both standard OpenAI and Azure OpenAI services. The choice of provider is determined by the is_azure boolean flag in the configuration.
Supported Providers and Parameters
| Parameter | Type | Description | Source |
|---|---|---|---|
is_azure | Boolean | Toggles between Azure OpenAI and standard OpenAI. | config.yaml:3 |
MAIN_LLM_MODEL | String | Primary model for complex reasoning (e.g., gpt-4o). | config.yaml:19 |
CHEAP_LLM_MODEL | String | Secondary model for cost-effective tasks (e.g., gpt-4o-mini). | config.yaml:21 |
AZURE_OPENAI_ENDPOINT | String | The base URL for the Azure OpenAI resource. | config.yaml:6 |
OPENAI_BASE_URL | String | Custom base URL for OpenAI (used for proxies). | config.yaml:13 |
LLM Initialization Logic
The openai_llm class in LLM.py performs a check on environment variables during initialization. If required keys (like AZURE_OPENAI_KEY or OPENAI_API_KEY) are missing or empty strings, the system raises a ValueError.
Sources: LLM.py:66-93, agents.py:16-25
Academic Search Configuration
The system relies on the Semantic Scholar API for literature discovery. This requires a dedicated API key defined in the configuration.
- API Key:
SEMENTIC_SEARCH_API_KEY - Module:
SementicSearcherinsearcher/sementic_search.py - Usage: The key is passed in the request headers as
x-api-key.
This sequence illustrates the retrieval and application of the search API key during a paper search operation.
Sources: searcher/sementic_search.py:86-90, config.yaml:1
Embedding Services
For semantic ranking and Reranking of papers, the system uses embedding models. These can be configured independently of the main LLM models.
| Variable | Usage | Source |
|---|---|---|
EMBEDDING_API_KEY | Credential for the embedding service. | config.yaml:15 |
EMBEDDING_API_ENDPOINT | Custom endpoint for embedding requests. | config.yaml:16 |
EMBEDDING_MODEL | The specific model identifier (e.g., text-embedding-3-large). | config.yaml:17 |
If these are not explicitly set, the system defaults to using the credentials and model settings of the main LLM client.
Sources: LLM.py:126-140, config.yaml:14
Implementation Example: Environment Loading
The following snippet demonstrates how main.py converts YAML configuration into system environment variables:
# main.py:10-17
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
for key, value in config.items():
if value == "":
continue
else:
os.environ[key] = str(value)
Sources: main.py:10-17
Summary
The API Keys & Environment system provides a flexible, dual-provider architecture. By separating the "Main" and "Cheap" models and centralizing API key management through config.yaml, the project allows for optimized research workflows while maintaining security and ease of setup. Proper configuration of these variables is critical for the ReviewAgent and DeepResearchAgent to function.
Sources: agents.py:15-30, README.md:46-60