File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4030,15 +4030,15 @@ def run(
40304030 >>> agent.run("Describe this image", img=img_base64)
40314031 """
40324032
4033- # # If interactive mode is enabled and no task is provided, prompt the user
4034- # if self.interactive and (
4035- # task is None
4036- # or (isinstance(task, str) and task.strip() == "")
4037- if (
4038- task is None
4039- or isinstance ( task , str )
4040- and task . strip () == ""
4041- ) :
4033+ empty_task = task is None or (
4034+ isinstance ( task , str ) and task . strip () == ""
4035+ )
4036+ if empty_task and not self . interactive :
4037+ raise ValueError (
4038+ "A non-empty task is required when interactive mode is disabled."
4039+ )
4040+
4041+ if self . interactive and empty_task :
40424042 # Always show prompt when asking for initial task, even if print_on is False
40434043 self .pretty_print (
40444044 "Interactive mode enabled. Please enter your initial task:" ,
Original file line number Diff line number Diff line change @@ -136,6 +136,19 @@ def test_run_with_stopping_condition(
136136 response = flow_with_condition .run ("Stop" )
137137 assert response is not None
138138
139+ @pytest .mark .parametrize ("task" , [None , "" , " " ])
140+ def test_noninteractive_empty_task_does_not_read_stdin (
141+ self , test_agent , task
142+ ):
143+ with (
144+ patch (
145+ "swarms.structs.agent.formatter.console.input" ,
146+ side_effect = AssertionError ("stdin must not be read" ),
147+ ),
148+ pytest .raises (ValueError , match = "non-empty task" ),
149+ ):
150+ test_agent .run (task )
151+
139152 def test_bulk_run (self , basic_flow ):
140153 """Test bulk run functionality"""
141154 inputs = [{"task" : "Test1" }, {"task" : "Test2" }]
You can’t perform that action at this time.
0 commit comments