Repository navigation
feat(hooks): add HookEngine::agent_thought - #615
Open
CodeGhost21 wants to merge 1 commit into
Open
CodeGhost21 wants to merge 1 commit into
CodeGhost21 wants to merge 1 commit into
Conversation
Fire the observational afterAgentThought event with a TextPayload (reasoning text plus optional duration_ms). Like the other lifecycle entry points it returns early when nothing is configured; matching hooks run in the background and their output is ignored. This is the last entry point OpenHuman's hooks/ops.rs re-implements. Refs senamakel#91 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeGhost21
marked this pull request as ready for review
November 16, 2026 14:12
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
HookEngine::agent_thought(identity, text, duration_ms)totinyagents_hooks::command. It fires the observationalafterAgentThoughtevent with aTextPayload { text, duration_ms }, does nothing when no hook is configured, and runs matching hooks on a background task so the turn never waits on them. Matchers select on the thought text.It is the last lifecycle entry point hosts still re-implemented. OpenHuman's
crates/openhuman-core/src/hooks/ops.rscopiessession_started,session_ended,prompt_submitted,pre_compact,subagent_starting,subagent_stoppedandPromptVerdict, which already exist here, and addsagent_thought. With this method, OpenHuman can delete that file and callHookEnginedirectly (host adoption: senamakel/openhuman#361).Fixes senamakel#91. Part of tinyhumansai/openhuman#7390 (phase 3 tracker senamakel/openhuman#391).
API Or Behavior Changes
New public method:
HookEngine::agent_thought.No event, config or wire changes.
HookEvent::AfterAgentThought(afterAgentThought, aliasagentthought),TextPayload, text-subject matching and background (non-gating) dispatch already exist.Parity with OpenHuman's free function:
The only difference is that it's a
&selfmethod instead of reading a global engine, matching the other entry points.HookEvent::is_wired()still listsAfterAgentThoughtas not wired, as its doc asks, until a host actually calls the method. A follow-up can flip it once OpenHuman adopts this.Tests
ops_tests.rs:agent_thoughtis added tolifecycle_entrypoints_are_noops_without_registered_hooks.agent_thought_fires_matching_hooks_in_the_background(unix). Asecret.*hook that sleeps 1s and prints a deny is configured. Two calls (one non-matching, one matching) return in under 900ms, only the matching one fires, and the event JSON carrieshook_event_name,session_id,conversation_id,textandduration_ms. It passed on three extra runs.agent_thought, so nothing needed to move.Commands run locally:
cargo fmt --check(cargo fmt --all -- --check)cargo clippy --all-targets -- -D warnings(-p tinyagents-hooks)cargo clippy --all-targets --all-features -- -D warnings:-p tinyagents-hooks --all-featuresfails in untouched code. Thegoalsfeature buildstinyagents-harness-toolswithouttodos, whilescratchpad/importscrate::todos(E0432/E0433). This doesn't appear when features combine in a workspace-wide--all-featuresbuild. Worth its own issue.cargo build --all-targets(cargo check --workspace --all-targets --locked)cargo build --all-targets --all-features: not run workspace-wide locally, to limit memory use; left to CIcargo test(-p tinyagents-hooks: 110 passed)cargo test --all-features: left to CIRUSTDOCFLAGS="-D warnings" cargo doc -p tinyagents-hooks --no-deps.github/scripts/test-release-workflow.pyDocumentation
crates/tinyagents-hooks/src/command/README.md: new "Lifecycle entry points" section.CHANGELOG.md: new "Unreleased" entry.Release note: OpenHuman needs a tag that contains this (a patch or minor after 3.1.4) before it can bump the gitlink and adopt it.
🤖 Generated with Claude Code
Summary by CodeRabbit
agent_thoughtlifecycle event that lets configured hooks observe thought text and optional duration. Hooks can match against the text and run in the background, so the current turn does not wait for them. When no relevant hook is configured, no event is dispatched.