Skip to content

Add extension hooks for mental model operations#260

Merged
cdbartholomew merged 1 commit intomainfrom
feat/mental-model-extension-hooks
Jan 31, 2026
Merged

Add extension hooks for mental model operations#260
cdbartholomew merged 1 commit intomainfrom
feat/mental-model-extension-hooks

Conversation

@cdbartholomew
Copy link
Contributor

@cdbartholomew cdbartholomew commented Jan 30, 2026

Summary

  • Add OperationValidatorExtension hooks for mental model operations
  • New dataclasses: MentalModelGetContext, MentalModelGetResult, MentalModelRefreshResult
  • New hook methods: validate_mental_model_get, on_mental_model_get_complete, on_mental_model_refresh_complete
  • Invoke hooks in http.py (GET mental model endpoint) and memory_engine.py (refresh flow)

Context

Mental model operations (retrieve and refresh) had no extension hooks, unlike retain/recall/reflect. This adds the same hook pattern so extensions can validate, track, and respond to mental model operations.

  • validate_mental_model_get: called before returning a mental model, allowing extensions to reject the request
  • on_mental_model_get_complete: called after a mental model is retrieved, with output token count
  • on_mental_model_refresh_complete: called after a mental model is refreshed, with token counts and facts/models used

Test plan

  • New test file tests/test_mental_model_hooks.py with tests for all three hooks
  • CI passes

@cdbartholomew cdbartholomew changed the title Add extension hooks for mental model usage metering Add extension hooks for mental model operations Jan 30, 2026
@cdbartholomew cdbartholomew force-pushed the feat/mental-model-extension-hooks branch from 0cc90bc to 1be9bd6 Compare January 30, 2026 22:02
Add dataclasses and hook methods to OperationValidatorExtension for
tracking mental model operations:

- MentalModelGetContext/Result: context and result for GET operations
- MentalModelRefreshResult: result for refresh operations with token counts
- validate_mental_model_get: pre-operation validation hook
- on_mental_model_get_complete: post-GET completion hook
- on_mental_model_refresh_complete: post-refresh completion hook

Invoke hooks in http.py (GET endpoint) and memory_engine.py (refresh).
Add tests verifying hooks are called with correct parameters.
@cdbartholomew cdbartholomew force-pushed the feat/mental-model-extension-hooks branch from 1be9bd6 to d113b35 Compare January 30, 2026 22:02
@cdbartholomew cdbartholomew merged commit 9c3fda7 into main Jan 31, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant