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

# Train AI on a Business, using Sphinx

> Train an agent on a fictional business using Sphinx, then evaluate it yourself.

Giving an agent access to your files and databases is a starting point. Useful answers also depend on understanding your business: which definitions different teams use, which decisions are current, how systems fit together, and when an exception changes the answer.

Sphinx training lets your agent study that context before you put it to work. It studies your sources, connects related business context and generates synthetic tasks from the material. Your agent can apply what training uncovered to new questions, without requiring you to explain every business rule in each prompt.

This example gives you a fictional business to train on and evaluate yourself.

## Meet Cedar Bank

Cedar Bank is a commercial lender with 1,800 loans. Its source material includes warehouse exports, policy discussions, legal amendments and operations handovers. A SQLite database contains the same warehouse data, so both agents can query the underlying numbers.

An analyst asks, **“How much exposure do we have at September close?”** Finance reports the loans Cedar owns. Credit Risk monitors loans it still services, including some it has sold. Both reporting purposes are valid, and a useful answer should identify which one its total represents.

Finding the definitions is only part of the work. Whether a sold loan still belongs in Risk's report depends on legal approval, a completed handover and when the evidence arrived. Those facts live in separate records. The agent needs to connect them and apply the resulting scope to its calculation.

## What happens during training

Sphinx studies the documents and data, connects related definitions and decisions, and makes up synthetic business tasks from that material. A practice question might ask whether a loan copied into a new system should count as a second facility. Working through the identity mappings helps establish a reusable reporting rule. Other tasks make reporting purposes, policy approvals and information cutoffs concrete.

Your answering agent keeps access to the original files and SQLite data so it can check calculations when you ask a question. Training provides business context before that work begins.

This demo uses Sphinx for training and GPT-6 Luna for both answering agents.

## Before you start

* Use Python 3.10+ and a Codex CLI that supports the supplied permission configuration.
* Have a **Sphinx project API key** for the project you want to train. You use this key for both training and Sphinx-enabled answers. Select your workspace in [Sphinx](https://app.sphinx.ai), then create the key under **Settings → API keys**.
* Have an **OpenAI API key** with access to GPT-6 Luna for the plain Codex baseline and GPT-6.2 Sol for the automated judge.

> [card] [Download the runnable example](https://github.com/sphinx-ml/business-training-demo/releases/download/v1.0.0/cedar-bank-training-demo.zip)
>
> Company records, SQLite data, a Python training script and starter questions. Use Sphinx's production service to train, then generate your own answers.

## Train on the company records

**1. Install the example**

Unpack the download and run these commands from the extracted `cedar-bank-training-demo` folder:

```bash theme={null}
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python verify.py
```

**2. Configure both API keys**

Set your two API keys:

```bash theme={null}
export SPHINX_API_KEY="your-sphinx-project-api-key"
export OPENAI_API_KEY="your-openai-api-key"
```

The demo uses Sphinx's production endpoints automatically. The OpenAI key is used for the direct baseline and automated grading.

**3. Train using Sphinx**

The `training/` folder contains the complete raw company records. `training-prompt.txt` asks Sphinx to connect reporting purposes, dates, approvals and joins, work through representative business questions, and preserve valid alternatives. The example uses the published `sphinx_learn==0.2.0` SDK.

The Python call in `train.py` is:

```python theme={null}
import sphinx_learn

job = sphinx_learn.fit(
    prompt=open(
        "training-prompt.txt"
    ).read(),
    docs="training",
)
print(job.url)
```

Submit training:

```bash theme={null}
python train.py
```

`fit()` queues the job and returns its link. Open that link in Sphinx, wait for training to finish, then review and accept the completed changes before evaluating the agent. Sphinx runs the training for you.

**4. Connect your agent**

Use the same Sphinx project API key with the production Responses endpoint. Confirm that both agents resolve the same model and reasoning setting:

```bash theme={null}
python check_endpoints.py \
  --model gpt-6-luna \
  --effort none --stream
```

Both agents retain access to the original company files and database. For other clients, see [Responses API configuration](https://docs.sphinx.ai/responses-api/overview.md).

![Cedar Bank source folders beside a Python call that trains an agent using Sphinx on the company records](https://mintcdn.com/sphinx-977f1673/8bRWVGtcxDFVsXOC/images/examples/cedar-bank/training.png?fit=max\&auto=format\&n=8bRWVGtcxDFVsXOC\&q=85\&s=2794bedddc7c9f5cee28a99de1c81071)

Example source material and the Python training call included in the download.

## Evaluate it yourself

Compare the same Luna model in the same Codex harness, with and without Sphinx training. Give both agents every original training file, the same SQLite database, the same analyst prompt and the same questions.

For these ten selected questions, expect roughly these automated accuracy ranges:

| Agent | Expected accuracy |
| - | - |
| Plain Luna + Codex, with every source file and the database | 40–45% |
| The same Luna + Codex, after training using Sphinx | 75–80% |

Individual runs vary; generate fresh answers and use the supplied judge to see your own results. [View the ten questions](https://github.com/sphinx-ml/business-training-demo/releases/download/v1.0.0/cedar-bank-questions.txt).

Run the complete comparison:

```bash theme={null}
python compare.py --label my-demo
```

The script asks all ten questions twice per agent: 20 answers without Sphinx and 20 with it. Answer workers run concurrently, with answer generation and grading shown as separate phases. Use a new label for each run to preserve previous answers.

Open `runs/my-demo/RESULTS.md` for the automated scores. The download includes a fixed judge and source-derived rubric, so you do not need to design an evaluation or score answers manually. The judge uses GPT-6.2 Sol through your OpenAI key, does not receive the answering endpoint, and saves its decisions. Reports use only automated judgments, with no manual overrides.

Start with the ten supplied questions, then explore your own follow-up questions about reporting purposes, information cutoffs or scenarios that combine several sources.

### See the difference

Ask both agents: **“Who should Collections call next about hardship plans?”** The approved daily-batch rule prioritizes loans with the most principal that would leave the committee's non-performing loan (NPL) total after one further successful payment.

The plain agent recommends **L0048**, with **USD 220,000** eligible for release. The trained agent correctly puts **L0992**, with **USD 1,951,900**, first—about **8.9× more principal per call**. A successful next payment would remove that principal from the committee's NPL total.

![Actual plain Luna answer incorrectly chooses L0048 first, with 220000 dollars of releasable principal](https://mintcdn.com/sphinx-977f1673/BWkc2-6fcvByhKGZ/images/examples/cedar-bank/without-sphinx.png?fit=max\&auto=format\&n=BWkc2-6fcvByhKGZ\&q=85\&s=66661d1b30f8142872a0567e27217586)

![Actual Sphinx-enabled Luna answer correctly ranks L0992 first, with 1951900 dollars of releasable principal](https://mintcdn.com/sphinx-977f1673/BWkc2-6fcvByhKGZ/images/examples/cedar-bank/with-sphinx.png?fit=max\&auto=format\&n=BWkc2-6fcvByhKGZ\&q=85\&s=c1bf2d5fdcde299ed9478bab8cb385bc)

**Why the plain agent got it wrong.** It found the approved call-batch policy, but its attempts to calculate the full ranking failed. It fell back to checking a few loans and chose L0048. Its answer even excluded L0032, a larger eligible loan at 35 days past due with no nonaccrual flag, claiming that a base NPL trigger would remain. The rule excludes loans at **90 or more days past due or on nonaccrual**; 35 days alone does not disqualify a loan. Finding the policy did not translate into applying it correctly across the portfolio.

**What went right with Sphinx.** The trained agent kept two rules separate: a second successful hardship payment removes the hardship overlay, while a base NPL trigger would still keep a loan non-performing. It combined that distinction with the approved arrangement dates and payment counts, authoritative loan records, servicing eligibility and closing exchange rates. Its calculation found 64 eligible loans and ranked their releasable principal, putting L0992 first. Training helps turn scattered business decisions into guidance the agent can apply; the agent still checks records and performs the calculation with its tools.

These are actual answer excerpts from two standard-API validation runs using the same Luna model, question, prompt, original files and SQLite data. The approved ranking and amounts are identical under both authorized September cutoffs.

Training should help the agent connect the relevant records, calculate correctly, preserve legitimate alternatives and recognize missing inputs. Keep its database and file tools available so it can check the original evidence while answering new questions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.