ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
KillBash tool - Terminate shell sessions
|
||||
"""
|
||||
|
||||
from typing import Dict, Any
|
||||
from .base import BaseTool
|
||||
|
||||
|
||||
class KillBashTool(BaseTool):
|
||||
"""Kills a running background bash shell by its ID"""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return "KillBash"
|
||||
|
||||
def _execute_impl(self, params: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Kill a shell session
|
||||
|
||||
- Kills a running background bash shell by its ID
|
||||
- Takes a shell_id parameter identifying the shell to kill
|
||||
- Returns a success or failure status
|
||||
"""
|
||||
shell_id = params["shell_id"]
|
||||
|
||||
if shell_id in self.state.shell_sessions:
|
||||
try:
|
||||
session = self.state.shell_sessions[shell_id]
|
||||
session.kill()
|
||||
del self.state.shell_sessions[shell_id]
|
||||
return {
|
||||
"shell_id": shell_id,
|
||||
"status": "terminated"
|
||||
}
|
||||
except Exception as e:
|
||||
return {"error": f"Error killing shell: {str(e)}"}
|
||||
|
||||
for session in self.state.shell_sessions.values():
|
||||
if shell_id in session.background_processes:
|
||||
try:
|
||||
proc = session.background_processes.pop(shell_id)
|
||||
if isinstance(proc, int):
|
||||
import os
|
||||
import signal
|
||||
try:
|
||||
os.kill(proc, signal.SIGTERM)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
else:
|
||||
session._terminate_process(proc)
|
||||
return {
|
||||
"shell_id": shell_id,
|
||||
"status": "terminated"
|
||||
}
|
||||
except Exception as e:
|
||||
return {"error": f"Error killing shell: {str(e)}"}
|
||||
|
||||
return {"error": f"Shell session not found: {shell_id}"}
|
||||
|
||||
Reference in New Issue
Block a user