Skip to content

feat(hooks): add HookEngine::agent_thought - #615

Open
CodeGhost21 wants to merge 1 commit into
tinyhumansai:mainfrom
CodeGhost21:feat/91-hook-agent-thought
Open

CodeGhost21 wants to merge 1 commit into
tinyhumansai:mainfrom
CodeGhost21:feat/91-hook-agent-thought

Conversation

@CodeGhost21

@CodeGhost21 CodeGhost21 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds HookEngine::agent_thought(identity, text, duration_ms) to tinyagents_hooks::command. It fires the observational afterAgentThought event with a TextPayload { 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.rs copies session_started, session_ended, prompt_submitted, pre_compact, subagent_starting, subagent_stopped and PromptVerdict, which already exist here, and adds agent_thought. With this method, OpenHuman can delete that file and call HookEngine directly (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, alias agentthought), TextPayload, text-subject matching and background (non-gating) dispatch already exist.

  • Parity with OpenHuman's free function:

    • same event and payload;
    • returns early with no hooks;
    • non-blocking, and hook output (including a deny) is ignored;
    • per-hook or engine-default timeouts.

    The only difference is that it's a &self method instead of reading a global engine, matching the other entry points.

  • HookEvent::is_wired() still lists AfterAgentThought as 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_thought is added to lifecycle_entrypoints_are_noops_without_registered_hooks.
  • New agent_thought_fires_matching_hooks_in_the_background (unix). A secret.* 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 carries hook_event_name, session_id, conversation_id, text and duration_ms. It passed on three extra runs.
  • OpenHuman has no test for 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-features fails in untouched code. The goals feature builds tinyagents-harness-tools without todos, while scratchpad/ imports crate::todos (E0432/E0433). This doesn't appear when features combine in a workspace-wide --all-features build. 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 CI
  • cargo test (-p tinyagents-hooks: 110 passed)
  • cargo test --all-features: left to CI
  • RUSTDOCFLAGS="-D warnings" cargo doc -p tinyagents-hooks --no-deps
  • .github/scripts/test-release-workflow.py

Documentation

  • 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

  • New Features
    • Added an agent_thought lifecycle 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.
  • Documentation
    • Added guidance on lifecycle events, hook matching, and the return behavior of lifecycle entry points.

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>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds the public async HookEngine::agent_thought entry point. It dispatches thought text and an optional duration as an AfterAgentThought event when hooks are registered. The change includes tests and documentation.

Changes: Agent thought event

Layer / File(s) Summary
Thought event dispatch and validation
crates/tinyagents-hooks/src/command/ops.rs, crates/tinyagents-hooks/src/command/ops_tests.rs, crates/tinyagents-hooks/src/command/command_tests.rs, crates/tinyagents-hooks/src/command/README.md, CHANGELOG.md
agent_thought returns early when no AfterAgentThought hooks are registered. Otherwise, it dispatches thought text and optional duration. Tests verify that the call does not wait for a delayed hook and that only the matching thought is logged with the expected event fields. The documentation describes the lifecycle entry point and its observational behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: senamakel, tinysweeper

Merge Risk: Minimal · up to 1b87d

This adds a new hook entry point for agent thoughts that dispatches in the background and does not change existing behaviour. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(hooks): add HookEngine::agent_thought" names the primary change. The changeset adds the public HookEngine::agent_thought method in crates/tinyagents-hooks/src/command/ops.rs, with test…
Linked Issues check Passed Issue #91 (direct) requires adding HookEngine::agent_thought to tinyagents-hooks. The diff at the reviewed head adds pub async fn agent_thought(&self, identity, text, duration_ms) in `crates/tinya…
Out of Scope Changes check Passed All changed areas connect to issue #91. The ops.rs hunk is the requested method. ops_tests.rs and command_tests.rs add tests for that method. command/README.md and CHANGELOG.md document the …
Full details: Title check

Explanation

The title "feat(hooks): add HookEngine::agent_thought" names the primary change. The changeset adds the public HookEngine::agent_thought method in crates/tinyagents-hooks/src/command/ops.rs, with tests, README, and CHANGELOG updates. The title is specific, concise, and follows a conventional-commit style.

Full details: Linked Issues check

Explanation

Issue #91 (direct) requires adding HookEngine::agent_thought to tinyagents-hooks. The diff at the reviewed head adds pub async fn agent_thought(&amp;self, identity, text, duration_ms) in crates/tinyagents-hooks/src/command/ops.rs. It returns early when no AfterAgentThought hook exists, builds a TextPayload with text and duration_ms, and calls dispatch. This matches the requested capability. The issue asks for tests that covered this in OpenHuman. The PR reports that OpenHuman has no agent_thought test to move. The PR adds agent_thought to lifecycle_entrypoints_are_noops_without_registered_hooks in ops_tests.rs. It also adds agent_thought_fires_matching_hooks_in_the_background in command_tests.rs, which checks non-blocking return, matcher selection, and event payload fields. The remaining items are the release/tag, OpenHuman gitlink bump, and digest re-pin. Those are non-coding or host-side follow-ups and are excluded from this PR's requirements. Background dispatch relies on the existing dispatch path. The PR states this was already present, and the test's timing check exercises it. I did not inspect dispatch itself.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to issue #91. The ops.rs hunk is the requested method. ops_tests.rs and command_tests.rs add tests for that method. command/README.md and CHANGELOG.md document the new public method. The PR changes no event, config, or wire behavior. The is_wired() value is left as-is, and the PR states this on purpose. Documentation and tests support the requested capability. No unrelated change was found in the reviewed diff.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit reads the thought-text stream
And sends a hook a quiet beam
The matching words go hopping by
While calls return before they fly
Duration joins the event's trail
The rabbit stamps the changelog, hale

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e97b63f-9249-4cb3-881b-afad4712efcf
Commits

Reviewing files that changed from the base of the PR and between 28cf21e and 1b87d5c.

Files selected for processing: 5

  • CHANGELOG.md
  • crates/tinyagents-hooks/src/command/README.md
  • crates/tinyagents-hooks/src/command/command_tests.rs
  • crates/tinyagents-hooks/src/command/ops.rs
  • crates/tinyagents-hooks/src/command/ops_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@CodeGhost21
CodeGhost21 marked this pull request as ready for review November 16, 2026 14:12

This branch has not been deployed

No deployments
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.

[core-shrink] upstream: HookEngine::agent_thought

1 participant