Skip to content

[Future] Audit and Enforce Tool Definition Stability #69

Description

@frankbria

Summary

Audit tool definition stability during task execution to prevent cache invalidation and model confusion from mid-task tool changes.

Background: State of the Art

From Philipp Schmid's 5 Practical Tips for Context Engineering:

"Manage Tools Statically: Avoid changing tool order or availability mid-task, if not explicitly needed. This might break context caching and can/will confuse models if used tools in the history are no longer defined."

Two problems arise from dynamic tool changes:

  1. Cache invalidation: Tool definitions are part of the prompt prefix. Changing them invalidates caching.
  2. Model confusion: If the model called tool_X earlier in the conversation but tool_X is no longer in the tool list, the model may hallucinate or reference unavailable capabilities.

The 12-Factor Agents framework also emphasizes: tools should be predictable and consistent within a task's lifecycle.

Current State in CodeFRAME

Each worker type (Backend, Frontend, Test, Review) presumably has role-specific tooling. Questions:

  1. Tool list consistency: Does a worker's tool list change during task execution?
  2. Cross-task tool changes: When a worker gets a new task, do available tools shift?
  3. Dynamic tool injection: Can the Lead Agent add/remove tools from workers mid-task?
  4. Tool ordering: Is the order of tool definitions consistent across calls?

Even if tools don't change, reordering tool definitions between calls can break caching.

Investigation Tasks

  1. Audit tool definition patterns

    • Log tool lists sent with each LLM call
    • Diff consecutive calls to identify any changes
    • Check both tool availability AND ordering
  2. Identify dynamic tool scenarios

    • Does context promotion/demotion affect tools?
    • Are tools added based on task content (e.g., "this task involves DB, add SQL tools")?
    • Do quality gates modify available tools?
  3. Implement tool stability guarantees

    • Freeze tool list at task start
    • Ensure consistent ordering (alphabetical, or fixed priority order)
    • If tools must change, do so only at explicit task boundaries
  4. Handle legitimate dynamic cases

    • If some tools ARE task-dependent, document the pattern
    • Consider "tool profiles" per task type, selected at start, frozen during execution
    • Log tool changes for debugging

Success Criteria

  • Documented tool stability audit results
  • Identified any mid-task tool changes
  • Implemented tool list freezing (if changes found)
  • Verified consistent tool ordering across all LLM calls
  • Measured cache hit improvement (if applicable)

Implementation Notes

Tool ordering convention: Pick a deterministic order (alphabetical by name, or priority-based) and enforce it in the context builder.

Tool profiles: If workers need different tools for different task types:

TOOL_PROFILES = {
    "backend_api": ["file_read", "file_write", "test_run", "lint"],
    "backend_db": ["file_read", "file_write", "sql_query", "migration_run"],
    "frontend_component": ["file_read", "file_write", "npm_run", "browser_preview"],
}
# Select profile at task start, freeze for duration

History consistency: If a tool was used earlier in conversation history, it should remain in the tool list even if "not needed" for current step, until task completes.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    FutureDeferred - beyond v1/v2 scope, consider for future versionscontext-engineeringContext window management and optimizationenhancementNew feature or requestpriority:mediumtooling

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions