99from pydantic import BaseModel , Field , create_model
1010
1111from sgr_deep_research .core .models import AgentStatesEnum
12- from sgr_deep_research .settings import get_config
1312
1413if TYPE_CHECKING :
1514 from sgr_deep_research .core .models import ResearchContext
1615
16+
1717logger = logging .getLogger (__name__ )
1818logger .setLevel (logging .INFO )
19- config = get_config ()
2019
2120
2221class BaseTool (BaseModel ):
@@ -136,6 +135,10 @@ class NextStepToolStub(ReasoningTool, ABC):
136135 function : T = Field (description = "Select the appropriate tool for the next step" )
137136
138137
138+ class DiscriminantToolMixin (BaseModel ):
139+ tool_name_discriminator : str = Field (..., description = "Tool name discriminator" )
140+
141+
139142class NextStepToolsBuilder :
140143 """SGR Core - Builder for NextStepTool with dynamic union tool function type on
141144 pydantic models level."""
@@ -144,19 +147,12 @@ class NextStepToolsBuilder:
144147 def _create_discriminant_tool (cls , tool_class : Type [T ]) -> Type [BaseModel ]:
145148 """Create discriminant version of tool with tool_name as instance
146149 field."""
147- tool_name = tool_class .tool_name
148150
149- discriminant_tool = create_model (
151+ return create_model (
150152 f"{ tool_class .__name__ } WithDiscriminant" ,
151- __base__ = tool_class ,
152- tool_name_discriminator = (
153- Literal [tool_name ], # noqa
154- Field (default = tool_name , description = "Tool name discriminator" ),
155- ),
156- )
157- discriminant_tool .__call__ = tool_class .__call__
158-
159- return discriminant_tool
153+ __base__ = (tool_class , DiscriminantToolMixin ), # the order matters here
154+ tool_name_discriminator = (Literal [tool_class .tool_name ], Field (..., description = "Tool name discriminator" )),
155+ ) # noqa
160156
161157 @classmethod
162158 def _create_tool_types_union (cls , tools_list : list [Type [T ]]) -> Type :
0 commit comments