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

Function send_input

webui/backend/websocket_handler.py:337–392  ·  view source on GitHub ↗

Send input to a running agent

(session_id: str, data: Dict[str, Any])

Source from the content-addressed store, hash-verified

335
336
337async def send_input(session_id: str, data: Dict[str, Any]):
338 """Send input to a running agent"""
339 if session_id not in agent_runners:
340 print(f'[WS] ERROR: Agent runner not found for session: {session_id}')
341 await connection_manager.send_to_session(
342 session_id, {
343 'type':
344 'error',
345 'message':
346 ('Agent is not running. The workflow may have completed. '
347 'Please start a new conversation or restart the agent.')
348 })
349 return
350
351 input_text = data.get('input', '')
352 print(f'[WS] Sending input to agent: {input_text[:100]}...')
353
354 # Check if process is still alive
355 runner = agent_runners[session_id]
356 if runner.process and runner.process.returncode is not None:
357 print(
358 f'[WS] ERROR: Process has exited with code {runner.process.returncode}'
359 )
360 await connection_manager.send_to_session(
361 session_id, {
362 'type':
363 'error',
364 'message':
365 'Agent process has terminated. The workflow completed. Please start a new conversation to continue.'
366 })
367 # Clean up the runner
368 del agent_runners[session_id]
369 return
370
371 # Update session status to running
372 session_manager.update_session(session_id, {'status': 'running'})
373 await connection_manager.send_to_session(session_id, {
374 'type': 'status',
375 'status': 'running'
376 })
377
378 # Add user message to session
379 session_manager.add_message(session_id, 'user', input_text, 'text')
380
381 # Send input to agent
382 try:
383 await runner.send_input(input_text)
384 except Exception as e:
385 print(f'[WS] ERROR: Failed to send input: {e}')
386 await connection_manager.send_to_session(
387 session_id, {
388 'type':
389 'error',
390 'message':
391 f'Failed to send input: {str(e)}. The process may have terminated.'
392 })
393
394

Callers 1

handle_session_messageFunction · 0.85

Calls 5

send_to_sessionMethod · 0.80
getMethod · 0.80
update_sessionMethod · 0.80
add_messageMethod · 0.80
send_inputMethod · 0.80

Tested by

no test coverage detected