Repository navigation
Description
Summary
MelleaSession.instruct() has no way to override model_options (temperature, max_tokens, extra_body, etc.) for a single call. Once a session is constructed with a given OpenAIBackend, all calls use the same backend config. The only way to change any request parameter is to reconstruct the entire session, which discards the HTTP connection pool.
Motivation
We hit this when building an evaluation harness that runs the same MelleaSession across three thinking tiers (NOTHINK / LIGHT / DEEP). Each tier requires a different chat_template_kwargs value in extra_body — but these are request-scoped, not session-scoped. There is no clean way to forward them without tearing down and rebuilding the session for each request.
Current workaround: construct a new MelleaSession (and therefore a new AsyncOpenAI client with a fresh connection pool) per request. This works but:
- Adds latency and GC pressure under load.
- Prevents connection reuse.
- Makes session-level caching (e.g. for adapter loading) useless.
This issue is the complement of feat(backends): add default_extra_body to OpenAIBackend (filed separately). Together they provide a clean two-level override system: construction-time defaults via default_extra_body, and per-call overrides via instruct(model_options=...).
Proposed fix
Add an optional model_options: dict | None = None keyword argument to MelleaSession.instruct(). When provided, merge it with the backend's existing options for that call only (not persisted to the session):
async def instruct(
self,
prompt: str,
requirements: list[Requirement] | None = None,
*,
model_options: dict | None = None, # <-- new
**kwargs,
) -> SamplingResult:
...Internally, the merged options would be forwarded to the backend for that single call. The session's default options remain unchanged.
Caller side (our use-case):
# Reuse one session; vary thinking tier per call
result = await session.instruct(
prompt,
requirements=reqs,
model_options={"extra_body": {"chat_template_kwargs": {"enable_thinking": True, "thinking_budget": 5000}}},
)The change is:
- Additive —
model_options=Nonepreserves existing behaviour exactly. - Enables session reuse — one
MelleaSessionper endpoint rather than one per request. - Unblocks issue Incorporate example Colab notebooks #4 (
MelleaSessionnot safely reusable across tiers) oncedefault_extra_bodyis also available.
Environment
- Mellea v0.6.0
- Reproducer: any caller that needs to vary
extra_bodybetweeninstruct()calls on the same session.
Activity
cptnm3 commentedon Jul 29, 2026
@planetf1 @ajbozarth I would like to work on this. Could you please assign this to me?
ajbozarth commentedon Jul 29, 2026
Given this is recently opened by @planetf1 I'll defer to him on you picking this up just in case he intended to do it himself (fyi he's on London time and might not see this till tomorrow)
cptnm3 commentedon Jul 29, 2026
Makes sense. Thank you @ajbozarth
psschwei commentedon Jul 29, 2026
doesn't this already exist?
mellea/mellea/stdlib/session.py
Line 575 in 6530575
planetf1 commentedon Jul 30, 2026
Yes can hold on this one for now. I had some findings in some analytics I was doing of melea/granite behaviour. The issue was indended to be opened yet.
I’ll assign it to myself to handle for now as it needs more clarification and validation
planetf1 commentedon Aug 10, 2026
Closing as already implemented.
@psschwei was right —
instruct()already acceptsmodel_options: dict | None = Noneas a parameter (seemellea/stdlib/session.pyline 575). Per-call model options (includingextra_bodycontents) can be passed today:```python
result = await session.instruct(
prompt,
model_options={"extra_body": {"chat_template_kwargs": {"enable_thinking": True, "thinking_budget": 5000}}},
)
```
The underlying need (forwarding thinking-tier flags without tearing down the session) is addressed by #1453 (
default_extra_bodyonOpenAIBackend) for the construction-time case. The per-call override already exists.