# Search Federal Grant Programs

`Search_Federal_Grant_Programs` searches GovTribe's federal grant program dataset and returns ALN/CFDA-style program records with program identity, descriptive content, and sponsoring federal agency context.

## When To Use

* "Find grant programs by CFDA/ALN number, exact program name, or GovTribe ID."
* "Discover federal grant programs related to a mission topic or capability area."
* "List programs for one or more specific federal agencies."
* "Get top agencies by number of matching grant programs."
* "Return rollups only (`per_page: 0`) or rollups plus sample rows (`per_page > 0`)."

## Required Reading

1. Search\_Query\_Guide: Required before setting free-text query strings when search\_mode is used.
2. Search\_Mode\_Guide: Required before choosing keyword vs semantic retrieval.

## Input Contract

* `query`: Free-text query string. See Required Reading: Search\_Query\_Guide.
  * `type`: `string`
  * `required`: `no`
  * `default`: `n/a`
* `page`: 1-based page index.
  * `type`: `null|number`
  * `required`: `no`
  * `default`: `1`
* `per_page`: Rows per page.
  * `type`: `null|number`
  * `required`: `no`
  * `default`: `10`
* `search_mode`: Query interpretation mode. See Required Reading: Search\_Mode\_Guide.
  * `type`: `string`
  * `required`: `no`
  * `default`: `keyword`
  * `options`: `keyword`, `semantic`
* `federal_agency_ids`: Filter by federal agencies. Use GovTribe IDs.
  * `type`: `array<string>`
  * `required`: `no`
  * `default`: `n/a`
* `federal_agency_ids_operator`: Choose whether to include or exclude values for Federal Agency GovTribe IDs.
  * `type`: `null|string`
  * `required`: `no`
  * `default`: `in`
  * `options`: `in`, `not_in`
* `similar_filter`: Find similar to the provided govtribe\_type + govtribe\_id.
  * `type`: `null|object`
  * `required`: `no`
  * `default`: `n/a`
  * `shape`: `{ govtribe_type: string, govtribe_id: string }`
* `federal_grant_program_ids`: Include or exclude results by GovTribe IDs.
  * `type`: `array<string>`
  * `required`: `no`
  * `default`: `n/a`
* `federal_grant_program_ids_operator`: Choose whether to include or exclude values for GovTribe IDs.
  * `type`: `null|string`
  * `required`: `no`
  * `default`: `in`
  * `options`: `in`, `not_in`
* `aggregations`: Aggregation keys to compute.
  * `type`: `array<string>`
  * `required`: `no`
  * `default`: `n/a`
  * `options`: `top_federal_agencies_by_doc_count`
* `sort`: Sort configuration.
  * `type`: `object`
  * `required`: `no`
  * `default`: `n/a`
  * `shape`: `{ key?: null|string, direction?: null|string }`
  * `options`: `key`: `postedDate`, `_score`; `direction`: `asc`, `desc`
* `fields_to_return`: Optional field list for row payloads. If omitted and `per_page > 0`, rows default to `govtribe_id`. For `per_page: 0` aggregation/meta calls, this field may be omitted. Specify `fields_to_return` whenever the user asks for fields beyond `govtribe_id`, and prefer omitting it in pure aggregation workflows.
  * `type`: `array<string>`
  * `required`: `no`
  * `default`: `n/a`
  * `options`: `govtribe_id`, `govtribe_ai_summary`, `govtribe_type`, `govtribe_url`, `name`, `cfda_number`, `description`, `updated_at`, `federal_agency`, `federal_grant_awards`, `federal_grant_opportunities`

## Output Contract

* Top-level keys:
  * `data`: Array of result rows when `per_page > 0`.
  * `current_page`, `from`, `to`, `last_page`, `per_page`: pagination fields returned with row data.
  * `total`: Total matched row count for current query filters.
  * `path`: GovTribe search URL for this result set.
  * `contains`: Dataset label for the returned result set.
  * `search_results_id`, `search_results_id_can_generate_saved_search`, `view_search_results_url`: search-session metadata.
  * `aggregations`: Aggregation payload keyed by requested aggregation names when requested.
* Row keys:
  * `govtribe_id`
  * `govtribe_ai_summary`
  * `govtribe_type`
  * `govtribe_url`
  * `name`
  * `cfda_number`
  * `description`
  * `updated_at`
  * `federal_agency`
  * `federal_grant_awards`
  * `federal_grant_opportunities`
* Relationship retrieval map:
  * `federal_agency`
    * `resource_type`: `federal_agency`
    * `tool`: `Search_Federal_Agencies`
    * `filter`: `federal_agency_ids`
    * `nested_keys`: `govtribe_id`, `govtribe_type`, `govtribe_url`, `name`
  * `federal_grant_awards`
    * `resource_type`: `federal_grant_award`
    * `tool`: `Search_Federal_Grant_Awards`
    * `filter`: `federal_grant_award_ids`
    * `nested_keys`: `govtribe_id`, `govtribe_type`, `govtribe_url`, `name`
  * `federal_grant_opportunities`
    * `resource_type`: `federal_grant_opportunity`
    * `tool`: `Search_Federal_Grant_Opportunities`
    * `filter`: `federal_grant_opportunity_ids`
    * `nested_keys`: `govtribe_id`, `govtribe_type`, `govtribe_url`, `name`

## Usage Patterns

Pattern A: Exact program lookup by CFDA/ALN-style identifier. Tool: `Search_Federal_Grant_Programs`

```json
{
  "query": "\"12.300\"",
  "search_mode": "keyword",
  "fields_to_return": [
    "govtribe_id"
  ],
  "per_page": 5,
  "page": 1
}
```

Pattern B: Semantic discovery of programs for a mission topic. Tool: `Search_Federal_Grant_Programs`

```json
{
  "query": "coastal resilience and climate adaptation community grants",
  "search_mode": "semantic",
  "fields_to_return": [
    "govtribe_id"
  ],
  "per_page": 10,
  "page": 1
}
```

Pattern C: Programs for a resolved agency ID (use `Search_Federal_Agencies` first if only a name is known). Tool: `Search_Federal_Grant_Programs`

```json
{
  "query": "",
  "search_mode": "keyword",
  "fields_to_return": [
    "govtribe_id"
  ],
  "federal_agency_ids": [
    "7500|7529-A"
  ],
  "federal_agency_ids_operator": "in",
  "per_page": 10,
  "page": 1
}
```

Pattern D: Aggregation-only agency leaderboard for matching programs. Tool: `Search_Federal_Grant_Programs`

```json
{
  "query": "",
  "search_mode": "keyword",
  "aggregations": [
    "top_federal_agencies_by_doc_count"
  ],
  "per_page": 0
}
```

Pattern E: Combined rows + aggregation output in one call. Tool: `Search_Federal_Grant_Programs`

```json
{
  "query": "behavioral health workforce training",
  "search_mode": "semantic",
  "fields_to_return": [
    "govtribe_id"
  ],
  "aggregations": [
    "top_federal_agencies_by_doc_count"
  ],
  "per_page": 5,
  "page": 1
}
```
