MCPcopy Create free account
hub / github.com/modelscope/ms-agent / send_input

Method send_input

webui/backend/agent_runner.py:139–198  ·  view source on GitHub ↗

Send input to the agent

(self, text: str)

Source from the content-addressed store, hash-verified

137 pass
138
139 async def send_input(self, text: str):
140 """Send input to the agent"""
141 # Check if process is still alive and stdin is available
142 if not self.process:
143 print('[Runner] ERROR: Process is None, cannot send input')
144 if self.on_error:
145 self.on_error({
146 'message':
147 'Agent process is not running. Please start a new conversation.',
148 'type': 'input_error'
149 })
150 return
151
152 # Check if process has exited
153 if self.process.returncode is not None:
154 print(
155 f'[Runner] ERROR: Process has exited with code {self.process.returncode}, cannot send input'
156 )
157 if self.on_error:
158 self.on_error({
159 'message':
160 'Agent process has terminated. Please start a new conversation.',
161 'type': 'input_error'
162 })
163 return
164
165 # Check if stdin is available
166 if not self.process.stdin:
167 print('[Runner] ERROR: Process stdin is None, cannot send input')
168 if self.on_error:
169 self.on_error({
170 'message':
171 'Cannot send input: process stdin is not available.',
172 'type': 'input_error'
173 })
174 return
175
176 print(f'[Runner] Sending input to agent: {text[:100]}...')
177 self._waiting_for_input = False # Reset waiting flag when sending input
178 self._waiting_input_sent = False # Reset so it can be sent again after next completion
179 self.is_running = True # Ensure process is marked as running
180 # Reset chat mode collection state for next response
181 self._collecting_assistant_output = False
182 self._chat_response_buffer = ''
183
184 try:
185 self.process.stdin.write((text + '\n').encode())
186 await self.process.stdin.drain()
187 print('[Runner] Input sent successfully')
188 except (BrokenPipeError, RuntimeError, OSError) as e:
189 print(f'[Runner] ERROR: Failed to send input: {e}')
190 if self.on_error:
191 self.on_error({
192 'message':
193 f'Failed to send input: Process may have terminated. Error: {str(e)}',
194 'type': 'input_error'
195 })
196 # Mark process as not running

Callers 1

send_inputFunction · 0.80

Calls 2

writeMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected