Repository navigation
Fix: Generic type parameters not preserved when subclassing AtomicAgent - #187
Merged
Merged
Conversation
When subclassing AtomicAgent with a custom constructor, the generic type parameters weren't being preserved. This caused input_schema and output_schema to fall back to BasicChatInputSchema/BasicChatOutputSchema instead of using the actual types specified. Added __init_subclass__ to capture the generic parameters at class creation time, following the same pattern used in BasePrompt, BaseTool, and BaseResource. The schema properties now use a three-level fallback: 1. Class attributes (from __init_subclass__) 2. Instance __orig_class__ (for direct instantiation) 3. Default schemas (for untyped usage) Added test case to verify subclassing with custom constructors works correctly.
Owner
Author
|
Fixes #185 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When you subclass
AtomicAgentwith a custom constructor, the generic type parameters get lost. Theinput_schemaandoutput_schemaproperties end up returningBasicChatInputSchemaandBasicChatOutputSchemainstead of the types you actually specified.Example that was broken:
The issue is that
__orig_class__only gets set for direct instantiation, not when subclassing.Solution
Added
__init_subclass__to capture the generic parameters at class creation time. This is the same approach already used byBasePrompt,BaseTool, andBaseResource, so it's consistent with the codebase.The schema properties now check in this order:
__init_subclass__) - handles subclassing__orig_class__- handles direct instantiationTesting
test_subclass_with_custom_constructor()to verify the fixNotes
This is backward compatible - doesn't break any existing usage patterns. Direct instantiation still works the same way it did before.