refactor: Update interfaces to include kwargs to enable backwards compatibility #413
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.
Description
This PR adds
**kwargs
parameters to all model and tool interfaces to enable backwards compatibility and future extensibility.Note: This is a breaking change that will require users who have implemented custom tools or model providers to update their code to match the new interface
signatures.
Key Changes:
• Model Interfaces: Added
**kwargs
to stream() and structured_output() methods across all model providers (Bedrock, LiteLLM, LlamaAPI,Mistral, Ollama, OpenAI, Writer)
• Tool System: Refactored tool interfaces to use
invocation_state: dict[str, Any], **kwargs: Any
instead ofkwargs: dict[str, Any]
for better API clarity• Event Loop: Updated event loop functions to use
invocation_state
parameter naming for consistency• Hook System: Updated tool invocation events (BeforeToolInvocationEvent, AfterToolInvocationEvent) to use
invocation_state
instead ofkwargs
• Telemetry/Tracing: Updated tracer methods to use
invocation_state
parameter naming throughout the tracing system• Documentation: Added parameter descriptions for all new
**kwargs
parametersThe refactoring improves API clarity by separating invocation context (invocation_state) from extensibility parameters (**kwargs), while enabling future extensibility without breaking changes.
Breaking Changes:
• Custom tool implementations must update their stream() method signature from stream(self, tool_use: ToolUse, kwargs: dict[str, Any]) to
stream(self, tool_use: ToolUse, invocation_state: dict[str, Any], **kwargs: Any)
• Custom model providers must add **kwargs: Any to their stream() and structured_output() method signatures
• Hook handlers using tool invocation events must update references from kwargs to invocation_state
Related Issues
Documentation PR
Type of Change
Breaking change
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-
docs, agents-tools, agents-cli
• [ x ] I ran hatch run prepare
Testing Coverage:
• All existing tests updated to reflect new parameter naming
• Test coverage maintained across all affected components
• Model provider tests verify **kwargs acceptance
• Tool system tests verify invocation_state and **kwargs handling
• Hook system tests updated for new event parameter structure
• Tracing/telemetry tests updated for invocation_state usage
Checklist
• [ x ] I have read the CONTRIBUTING document
• [ x ] I have added any necessary tests that prove my fix is effective or my feature works
• [ x ] I have updated the documentation accordingly
• [ ] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
• [ x ] My changes generate no new warnings
• [ x ] Any dependent changes have been merged and published
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.