Skip to content

Commit e6dac91

Browse files
author
Test
committed
Respect the selected provider thinking switch during memory extraction
1 parent 1d32334 commit e6dac91

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

‎docs/api.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ Bundled experts live in `src/octop/infra/agents/experts/library/`
432432
| `GET` | `/agents/{aid}/heartbeat-config` | owner | read heartbeat YAML |
433433
| `PUT` | `/agents/{aid}/heartbeat-config` | owner | write heartbeat YAML |
434434
| `GET` | `/agents/{aid}/memory/daily` | owner | list daily memory files |
435-
| `GET`/`PUT` | `/agents/{aid}/memory/extract-config` | owner/admin | Read/update memory runtime and extraction options. `aux_model_mode` and `extract_rules_mode` independently accept `inherit` or `custom`. Omitted fields keep their values. A legacy `aux_model: null` leaves the selection unchanged. Explicit `custom` with a null model follows the expert’s chat model. |
435+
| `GET`/`PUT` | `/agents/{aid}/memory/extract-config` | owner/admin | Read/update memory runtime and extraction options. `aux_model_mode` and `extract_rules_mode` independently accept `inherit` or `custom`. Omitted fields keep their values. A legacy `aux_model: null` leaves the selection unchanged. Explicit `custom` with a null model follows the expert’s chat model. For a selected extraction model such as HY4, `extract_thinking: "auto"` or `"off"` uses the provider’s request-body switch when available. Explicit `extract_extra_body` values take priority. |
436436
| `GET`/`PUT` | `/settings/memory-defaults` | `memory_defaults` | Read or patch the global `aux_model`, `extract_keep_rules` and `extract_skip_rules`. The caller must have access to a newly selected model. On save, `affected_agent_count` counts enabled experts inheriting a changed setting, including stopped experts that will pick it up when started. |
437437
| `GET`/`PUT` | `/agents/{aid}/memory/strong` | owner | read/edit user-maintained MEMORY.md, including for stopped agents; new sessions snapshot full content once, existing sessions keep their snapshot |
438438
| `GET`/`PUT` | `/agents/{aid}/memory/user` | owner | read/edit user-maintained USER.md with the same session snapshot policy; distinct from the derived profile |

‎src/octop/infra/agents/manager.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from octop.infra.agents.memory_shared_access import shared_memory_tools
3838
from octop.infra.agents.providers import HostModelFactory, ProviderStore, sync_providers_to_harness
3939
from octop.infra.agents.providers.health import ModelHealthRegistry
40+
from octop.infra.agents.providers.reasoning import reasoning_request_parameters
4041
from octop.infra.agents.security import SecuritySettingsStore, ToolGuardRulesStore
4142
from octop.infra.agents.security.hitl_session import (
4243
HitlSessionPolicyStore,
@@ -295,6 +296,7 @@ def _memory_extract_settings(
295296
*,
296297
supported_fields: frozenset[str] = _HARNESS_AGENT_CONFIG_FIELDS,
297298
is_ref_usable: Callable[[str], bool] | None = None,
299+
reasoning_for_ref: Callable[[str], dict[str, Any] | None] | None = None,
298300
global_defaults: GlobalMemoryDefaults | None = None,
299301
) -> dict[str, Any]:
300302
"""Extract the ``memory`` config section into HarnessAgentConfig kwargs.
@@ -311,6 +313,19 @@ def _memory_extract_settings(
311313
out: dict[str, Any] = _memory_aux_model_settings(
312314
effective.effective_aux_model, supported_fields, is_ref_usable
313315
)
316+
ref = out.get("memory_aux_light_model")
317+
if (
318+
ref
319+
and reasoning_for_ref is not None
320+
and "memory_aux_extra_body" in supported_fields
321+
and mem.get("extract_thinking", "auto") in ("auto", "off")
322+
):
323+
capability = reasoning_for_ref(ref)
324+
if capability and capability.get("toggle"):
325+
# Models such as HY4 can spend the entire extraction budget on thinking.
326+
options = reasoning_request_parameters(capability, mode="disabled", effort=None)
327+
if provider_body := options.get("extra_body"):
328+
out["memory_aux_extra_body"] = provider_body
314329
if _supports_memory_extract_rules(supported_fields):
315330
if effective.effective_keep_rules:
316331
out["memory_extract_keep_rules"] = effective.effective_keep_rules
@@ -387,7 +402,7 @@ def _memory_extract_settings(
387402
and extra_body
388403
and (not has_aux_override or "memory_aux_light_model" in out)
389404
):
390-
out["memory_aux_extra_body"] = dict(extra_body)
405+
out["memory_aux_extra_body"] = {**out.get("memory_aux_extra_body", {}), **extra_body}
391406

392407
# octop-harness 0.9.5 predates the interval trigger fields. Keep
393408
# hot reload working against that release and approximate interval mode
@@ -4805,6 +4820,7 @@ def _managed_harness_config(
48054820
memory_settings = _memory_extract_settings(
48064821
cfg,
48074822
is_ref_usable=self._providers.is_model_ref_usable,
4823+
reasoning_for_ref=self._providers.get_model_reasoning_capability,
48084824
global_defaults=self.get_global_memory_defaults(),
48094825
)
48104826
if memory_settings.get("memory_enabled") is not True:
@@ -5218,6 +5234,7 @@ def _mobile_workspace_for(agent_id: str) -> Any:
52185234
**_memory_extract_settings(
52195235
cfg,
52205236
is_ref_usable=self._providers.is_model_ref_usable,
5237+
reasoning_for_ref=self._providers.get_model_reasoning_capability,
52215238
global_defaults=self.get_global_memory_defaults(),
52225239
),
52235240
**_resolve_memory_backend_kwargs(cfg, workspace_dir=workspace_dir, config=self._config),

‎tests/unit/agents/test_memory_defaults.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,40 @@ def test_memory_extract_settings_applies_global_defaults_to_fresh_agent(
151151
}
152152

153153

154+
@pytest.mark.parametrize(
155+
("memory", "expected"),
156+
[
157+
({}, {"thinking": {"type": "disabled"}}),
158+
(
159+
{"aux_model": "provider/hy4", "extract_thinking": "off"},
160+
{"thinking": {"type": "disabled"}},
161+
),
162+
({"extract_thinking": "on"}, None),
163+
(
164+
{"extract_extra_body": {"thinking": {"type": "enabled"}}},
165+
{"thinking": {"type": "enabled"}},
166+
),
167+
],
168+
)
169+
def test_memory_uses_provider_thinking_switch_for_resolved_model(
170+
memory: dict[str, Any], expected: dict[str, Any] | None
171+
) -> None:
172+
from octop.infra.agents.providers.reasoning import reasoning_capability
173+
174+
def capability(ref: str) -> dict[str, Any] | None:
175+
assert ref == memory.get("aux_model", "global/hy4")
176+
return reasoning_capability(
177+
{"id": "hy4", "reasoning_config": {"adapter": "thinking", "toggle": True}}
178+
)
179+
180+
result = _memory_extract_settings(
181+
{"memory": memory},
182+
global_defaults=GlobalMemoryDefaults(aux_model="global/hy4"),
183+
reasoning_for_ref=capability,
184+
)
185+
assert result.get("memory_aux_extra_body") == expected
186+
187+
154188
def test_memory_extract_settings_drops_extra_body_when_inherited_global_model_is_stale() -> None:
155189
glob = GlobalMemoryDefaults(aux_model="deleted/model")
156190
settings = _memory_extract_settings(

0 commit comments

Comments
 (0)