Skip to content

Opt hook example - #91

Merged
bouillipx merged 2 commits into
mainfrom
opt_hook_example
Feb 14, 2026
Merged

bouillipx merged 2 commits into
mainfrom
opt_hook_example

Conversation

@bouillipx

Copy link
Copy Markdown
Collaborator

Summary

  • What does this PR change?
  • Why is this change needed?

Scope (One PR One Thing)

  • Primary objective:
  • Out of scope:
  • I confirm this PR handles a single objective only: [ ] Yes

Changed Files (required)

List all touched files and why each file changed.

File Reason
path/to/file reason

If this PR is a large diff (>300 changed lines), explain why split PRs are not possible and provide a split follow-up plan.

Acceptance Criteria

  • Criteria 1
  • Criteria 2

Test Evidence (required)

  • Local commands run:
    • ...
  • CI links or job names:
    • ...
  • Evidence/output summary:
    • ...

If this PR changes high-risk runtime paths (auth/concurrency/execution control), include risk-matrix evidence.

Risk and Rollback

  • Risk level: Low / Medium / High
  • Main risk points:
  • Rollback plan:

Dependency and Lockfile Changes

  • Lockfile changed in this PR: [ ] Yes [ ] No
  • If yes, manifest updated in same PR (requirements.txt/pyproject.toml/package.json): [ ] Yes [ ] No [ ] N/A

Agent Rules Checklist (required)

Reference: docs/agent_rules.md

  • Only task-related files changed; no opportunistic refactor
  • Public interfaces/data structures unchanged unless explicitly required
  • Tests added/updated and evidence attached
  • Any skip/only/exclude usage is explained and reviewed
  • Merge will be done by approved reviewer (no self-merge auto-ship)

Replace the lightweight hook module note with a detailed design document aligned to the agent detailed-doc granularity, including contracts, lifecycle phases, dispatch flow, patch governance, builder/config integration, reliability semantics, and known gaps.

Add examples/08-hook-governance as a real OpenRouter-backed interactive CLI (mirroring the 05-style runtime workflow) with a custom GovernancePolicyHook that demonstrates:
- BEFORE_MODEL model_input patch visibility
- BEFORE_MODEL keyword-based BLOCK behavior
- BEFORE_TOOL ALLOW/BLOCK visibility (including write_file policy block)
- /stats introspection for phase and policy hit counters

Set the default example workspace to Path.cwd() so user prompts about the current directory behave as expected, and document the README path nuance in the example README.

Add focused unit tests for the 08 example to verify command parsing, default workspace behavior, BEFORE_MODEL block/patch behavior, and BEFORE_TOOL tracking.
Improve runtime robustness across transport, ReAct loop handling, and OpenRouter serialization.

Key changes:
- base_agent: emit structured AGENT_EXECUTION_FAILED envelopes when execute() raises.
- react_agent: add fallback text for empty final model replies and a repeated-tool-call loop guard.
- openrouter_adapter: preserve assistant tool_calls in OpenRouter function-call format.
- examples/02-with-tools: simplify channel wiring and await builder build() consistently.
- tests: add/extend unit coverage for transport error signaling, loop guard/fallback behavior,
  example channel construction, and adapter tool_call serialization.

Rationale:
- Prevent silent failures in transport mode and make client error handling deterministic.
- Avoid non-converging tool loops and empty user-facing responses in ReAct execution.
- Keep tool-call context intact for multi-turn OpenRouter interactions.
- Ensure sample code reflects current runtime contracts and prevent regressions via tests.
@bouillipx
bouillipx merged commit bd51c47 into main Feb 14, 2026
6 checks passed
@bouillipx
bouillipx deleted the opt_hook_example branch February 14, 2026 08:04
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