dragon-harness / opencode /INSTALL.md
dragonlimited's picture
fix the install instructions: `pip install git+https://huggingface.co/...` FAILS - pip's partial clone (--filter=blob:none) gets "fatal: expected 'packfile'" from the Hub's git server. Replaced with clone + local install in README, QUICKSTART and opencode/INSTALL.
2881a17 verified
|
Raw History Blame Contribute Delete
5.77 kB

Install: a working local finance agent

End state: OpenCode running a 7B model on your own GPU, with finance tools that answer reported figures exactly — verified at 99.8% on 6,802 evaluation items.

Time: ~15 minutes, most of it downloading.


0. What you need

GPU 8 GB VRAM is enough (tested against an RTX 5060 target)
RAM 16 GB minimum, 32 GB comfortable
disk ~10 GB for the model and the tool databases
software Python 3.10+, llama.cpp, OpenCode

1. Install the harness

git clone https://huggingface.co/dragonlimited/dragon-harness
pip install "./dragon-harness[mcp]"

Verify:

python -c "import dragon_harness, mcp; print('ok', dragon_harness.__version__)"

If import torchvision fails with operator torchvision::nms does not exist, your torch and torchvision are mismatched — they must be installed as a pair:

uv pip install --force-reinstall torch==2.15.0 torchvision==0.29.2 \
    --index-url https://download.pytorch.org/whl/cu132

torchvision 0.29.2 requires torch >= 2.14. This is the single most common failure; see the troubleshooting table at the end.

2. Get the model

huggingface-cli download dragonlimited/Dragon-Finance-7B \
    Dragon-Finance-7B-Q4_K_M.gguf --local-dir ./models

(Quantised weights are on the roadmap; until then, any Q4_K_M build of Qwen2.5-Coder-7B-Instruct works — that is the documented base.)

3. Serve it

./opencode/serve-model.sh ./models/Dragon-Finance-7B-Q4_K_M.gguf

Check:

curl -s http://127.0.0.1:8080/v1/models

The script uses -ctk q8_0 -ctv q8_0 — quantised KV cache is what makes 32k context fit inside 8 GB. Expect roughly 60 tok/s.

4. Build the tool databases

The tools need two local artifacts. See training/README.md for the full pipeline.

# facts (~2 min for 8 quarters; the eval quarters are already scripted)
python training/build_facts.py

# corpus index (resumable; ~790 chunks/s)
DRAGON_TARGET_CHUNKS=2000000 python training/index_corpus.py

Set the paths if yours differ:

export DRAGON_RAG_DIR=/path/to/dragon_rag
export DRAGON_FACTS_DB=/path/to/facts.duckdb
export DRAGON_DEVICE=cuda          # embed on GPU

Prove the tools work before involving OpenCode:

dragon filer "3M CO"
#      cik    name
# 0  66740   3M CO

dragon resolve "what is gross profit?" \
    --adsh 0000066740-23-000092 --ddate 20220930 --qtrs 1
# {"value": 3891.0, "method": "formula:gross_profit"}

If that prints 3891.0, the hard part is done. Everything after this is plumbing.

5. Wire it into OpenCode

cp opencode/opencode.jsonc   /your/project/opencode.jsonc
cp opencode/AGENTS.md        /your/project/AGENTS.md

That config does three things:

section effect
providers.dragon points OpenCode at http://127.0.0.1:8080/v1 as an OpenAI-compatible local model
mcp.servers.dragon launches python -m dragon_harness.mcp_server and exposes its 5 tools
agents.dragon-finance the primary agent, with AGENTS.md as its instructions

codemode is set to false on the MCP server deliberately — a 7B model does better with tools presented directly than behind a code-execution layer.

Confirm the server connected:

opencode mcp list

You should see dragon connected. In OpenCode, /mcps shows the same, and the tools appear as dragon_search_knowledge_tool, dragon_query_financials_tool, and so on.

6. Use it

$ opencode
> What was 3M's gross profit for the period ending 2022-09?

  dragon_query_financials  (3M CO, 10-Q, 20220930, qtrs=1)
  dragon_candidate_tags    (0000066740-23-000092)

  Gross profit was 3,891 million USD, from accession 0000066740-23-000092.

Ask something narrative and it uses search_knowledge instead, returning the passages it read with their source, file and chunk offset.


How to tell whether it is working

sign meaning
the agent calls a tool before answering a numeric question correct
the agent names an accession number in its answer correct
the agent says "not found" correct — that is the designed behaviour
the agent states a figure with no tool call it is guessing. Check AGENTS.md loaded

Troubleshooting

symptom cause fix
operator torchvision::nms does not exist torch/torchvision mismatch install the matched pair (step 1)
Could not import module 'Qwen2ForCausalLM' same root cause as above
MCP server unavailable SDK missing pip install "mcp[cli]"
dragon needs authentication wrong transport it should be type: local
tools missing in OpenCode codemode left true, or server failed to start check opencode mcp list
Unable to open database file DRAGON_FACTS_DB unset or wrong export it, or pass environment in the config
empty search_knowledge results index not built run index_corpus.py
slow first tool call embedding model loading ~10 s once, then fast
model refuses to call tools --jinja missing it is required for tool-calling templates

Verified on this configuration

harness accuracy 99.8% on 6,802 eval items, no model in the loop
large-cap split 100.0% (1,303/1,303)
resolve_question returned 3891.0 — exact
MCP tools published 5, on MCP 2.3.0
adapter training 60 steps, 39 s, loss 0.3832 → 0.2494

Full results on the model card.