Skip to content

Feature: Add model output context to before_tool_call hook #12617

Description

@duckshrug

Summary

The before_tool_call plugin hook currently receives toolName and params, but not the model's output that preceded the tool call. This limits the ability to implement compliance patterns.

Use Case

I want to enforce a behavioral pattern where the model must output a classification statement (e.g., CLASSIFY: [task] → Model: [cheap/expensive]) before every tool call. A plugin could:

  1. Listen to before_tool_call
  2. Check if the preceding model output contains the required pattern
  3. Block the tool call with a helpful message if missing

Current Limitation

// Current event shape
PluginHookBeforeToolCallEvent = {
  toolName: string;
  params: Record<string, unknown>;
};

No access to what the model said before the tool call.

Proposed Enhancement

Add optional context about the preceding model output:

PluginHookBeforeToolCallEvent = {
  toolName: string;
  params: Record<string, unknown>;
  // New fields
  precedingText?: string;      // Model output before this tool call
  messageId?: string;          // Reference to the full message if needed
};

Alternatives Considered

  • Behavioral enforcement only: Works but relies on the model remembering the rule
  • System prompt injection: Already possible via before_agent_start, but can't enforce

Impact

This would enable plugins to implement various compliance/governance patterns:

  • Cost classification enforcement
  • Tool usage audit trails with context
  • Custom approval workflows based on what the model is trying to do

Happy to discuss implementation approach if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions