Skip to content

Commit a546f07

Browse files
authored
chore: add info for working with intrinsics to AGENTS.md (#768)
* chore: add info for working with intrinsics to AGENTS.md Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * review comments: Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> --------- Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
1 parent 3feca7b commit a546f07

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,68 @@ Found a bug, workaround, or pattern? Update the docs:
146146
- **Issue/workaround?** → Add to Section 7 (Common Issues) in this file
147147
- **Usage pattern?** → Add to [`docs/AGENTS_TEMPLATE.md`](docs/AGENTS_TEMPLATE.md)
148148
- **New pitfall?** → Add warning near relevant section
149+
150+
## 13. Working with Intrinsics
151+
152+
Intrinsics are specialized LoRA adapters that add task-specific capabilities (RAG evaluation, safety checks, calibration, etc.) to Granite models. Mellea handles adapter loading and input formatting automatically — you just call the right function.
153+
154+
### Using Intrinsics in Mellea
155+
156+
**Prefer the high-level wrappers** in `mellea/stdlib/components/intrinsic/`. These handle adapter loading, context formatting, and output parsing for you:
157+
158+
| Module | Function | Description |
159+
|--------|----------|-------------|
160+
| `core` | `check_certainty(context, backend)` | Model certainty about its last response (0–1) |
161+
| `core` | `requirement_check(context, backend, requirement)` | Whether text meets a requirement (0–1) |
162+
| `core` | `find_context_attributions(response, documents, context, backend)` | Sentences that influenced the response |
163+
| `rag` | `check_answerability(question, documents, context, backend)` | Whether documents can answer a question (0–1) |
164+
| `rag` | `rewrite_question(question, context, backend)` | Rewrite question into a retrieval query |
165+
| `rag` | `clarify_query(question, documents, context, backend)` | Generate clarification or return "CLEAR" |
166+
| `rag` | `find_citations(response, documents, context, backend)` | Document sentences supporting the response |
167+
| `rag` | `check_context_relevance(question, document, context, backend)` | Whether a document is relevant (0–1) |
168+
| `rag` | `flag_hallucinated_content(response, documents, context, backend)` | Flag potentially hallucinated sentences |
169+
170+
```python
171+
from mellea.backends.huggingface import LocalHFBackend
172+
from mellea.stdlib.components import Message
173+
from mellea.stdlib.components.intrinsic import core
174+
from mellea.stdlib.context import ChatContext
175+
176+
backend = LocalHFBackend(model_id="ibm-granite/granite-4.0-micro")
177+
context = (
178+
ChatContext()
179+
.add(Message("user", "What is the square root of 4?"))
180+
.add(Message("assistant", "The square root of 4 is 2."))
181+
)
182+
score = core.check_certainty(context, backend)
183+
```
184+
185+
For lower-level control (custom adapters, model options), use `mfuncs.act()` with `Intrinsic` directly — see examples in `docs/examples/intrinsics/`.
186+
187+
### Project Resources
188+
189+
- **Canonical catalog**: `mellea/backends/adapters/catalog.py` — source of truth for intrinsic names, HF repo IDs, and adapter types
190+
- **Usage examples**: `docs/examples/intrinsics/` — working code for every intrinsic
191+
- **Helper functions**: `mellea/stdlib/components/intrinsic/rag.py` and `core.py`
192+
193+
### Adding New Intrinsics
194+
195+
When adding support for a new intrinsic (not just using an existing one), fetch its README from Hugging Face first. Each README contains the authoritative spec for input/output format, intended use, and examples.
196+
197+
**Writing examples?** The HF READMEs also document intended usage patterns and example inputs — useful reference when writing code in `docs/examples/intrinsics/`.
198+
199+
| Repo | Purpose | Intrinsics |
200+
|------|---------|------------|
201+
| [`ibm-granite/granitelib-rag-r1.0`](https://huggingface.co/ibm-granite/granitelib-rag-r1.0) | RAG pipeline | answerability, citations, context_relevance, hallucination_detection, query_rewrite, query_clarification |
202+
| [`ibm-granite/granitelib-core-r1.0`](https://huggingface.co/ibm-granite/granitelib-core-r1.0) | Core capabilities | context-attribution, requirement-check, uncertainty |
203+
| [`ibm-granite/granitelib-guardian-r1.0`](https://huggingface.co/ibm-granite/granitelib-guardian-r1.0) | Safety & compliance | guardian-core, policy-guardrails, factuality-detection, factuality-correction |
204+
205+
**README URLs** — RAG intrinsics (no model subfolder):
206+
```
207+
https://huggingface.co/ibm-granite/granitelib-rag-r1.0/blob/main/{intrinsic_name}/README.md
208+
```
209+
210+
Core and Guardian intrinsics (include model subfolder):
211+
```
212+
https://huggingface.co/ibm-granite/granitelib-{core,guardian}-r1.0/blob/main/{intrinsic_name}/granite-4.0-micro/README.md
213+
```

0 commit comments

Comments
 (0)