> For the complete documentation index, see [llms.txt](https://docs.openg2p.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openg2p.org/products/open-agri-stack/exchange/composite/running-locally.md).

# Running the Composite Locally

Running the Composite and its tests on a laptop.

The service is in [`composite/backend`](https://github.com/openg2p/agri-stack/tree/develop/composite/backend). It needs Python 3.11 or later (the image uses 3.12), [openg2p-fastapi-common](https://github.com/OpenG2P/openg2p-fastapi-common) from `develop` (its `PartnerMgmtKeyStore`, for partner keys from PM, is not in a 1.2.x release yet) and `iam-core` from the [IAM](https://github.com/OpenG2P/iam) `develop` line (the console's staff login; its 1.4.x releases do not work with the framework's `develop`).

```bash
cd composite/backend
python3.11 -m venv .venv && . .venv/bin/activate
pip install "git+https://github.com/openg2p/openg2p-fastapi-common@develop#subdirectory=openg2p-fastapi-common"
pip install "git+https://github.com/openg2p/iam@develop#subdirectory=iam-core"
pip install -e ".[test]"
pytest                                     # no network needed

python ../../scripts/partner_kit.py keys      # test keys in scripts/kit-out (git-ignored)
export AGRI_COMPOSITE_USE_CASES_DIR=../use-cases
export AGRI_COMPOSITE_SIGNING_P12_PATH=../../scripts/kit-out/composite.p12 AGRI_COMPOSITE_SIGNING_P12_PASSWORD=openg2p-test
export AGRI_COMPOSITE_PARTNER_MGMT_API_URL=http://localhost:9001          # a PM partner-api
export AGRI_COMPOSITE_REGISTRIES='{"farmer-registry":{"url":"http://localhost:9002/dci/registry/sync/search"},
                                  "crop-sown-registry":{"url":"http://localhost:9003/dci/registry/sync/search"}}'
python -m openg2p_agri_composite.main run  # http://localhost:8000/docs
```

* The ports are examples: point `PARTNER_MGMT_API_URL` and `REGISTRIES` at a PM partner API and the registries' partner APIs you can reach, e.g. through `kubectl port-forward`.
* The partner's and the Composite's public keys must be in that PM (`PARTNER_BANK_A`, `PARTNER_AGRI_COMPOSITE`), and the partner needs a policy there for the use case (`loan-profile@1`); `partner_kit.py keys` prints the onboarding requests, the partner's with its policy for the use case.
* With the console off (the default outside the chart) the service has no database; startup only loads the use cases. The chart turns the console on, which needs a database, IAM and Redis (see [Composite console](/products/open-agri-stack/exchange/composite/console.md)).
* The consent mode is `exchange` by default: set `AGRI_COMPOSITE_CONSENT_EXCHANGE_CM_URL` to a reachable CM partner API (the default is the in-cluster service), or `AGRI_COMPOSITE_CONSENT_MODE=passthrough` to skip the Exchange CM.
* Every setting is listed in [Use-Case Configuration](/products/open-agri-stack/exchange/composite/use-case-configuration.md).

Then call it as a partner:

```bash
python ../../scripts/partner_kit.py describe --url http://localhost:8000
python ../../scripts/partner_kit.py call --url http://localhost:8000 \
    --subject FAYDA_FAN:<FAN of a registered farmer> --param crop_year=2019 --param season=SEASON_MEHER
```

## Building the image

The Dockerfile is [`composite/docker/agri-composite-api/Dockerfile`](https://github.com/openg2p/agri-stack/blob/develop/composite/docker/agri-composite-api/Dockerfile). CI builds and publishes the image (`openg2p/openg2p-agri-composite-api`) and the chart only when something under `composite/` changes, not on documentation-only pushes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openg2p.org/products/open-agri-stack/exchange/composite/running-locally.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
