shell_agent = Agent( name="ShellCommander", role="Shell Command Specialist", goal="Execute shell commands efficiently and safely.", backstory="Expert in command-line operations and automation.", tools=[execute_command, list_processes, kill_process, get_system_info], self_reflect=False)
4
Define Task
Define the shell task:
Copy
shell_task = Task( description="List and organize files in the current directory.", expected_output="Organized file structure with detailed listing.", agent=shell_agent, name="file_organization")
# Find and kill zombie processesfor process in list_processes(): if process['name'] == 'zombie_process': result = kill_process( process['pid'], force=True ) print(f"Kill result: {result['message']}")
Command Execution:
Copy
# Run a series of maintenance commandscommands = [ "apt-get update", "apt-get upgrade -y", "apt-get autoremove -y"]for cmd in commands: result = execute_command( cmd, timeout=300, shell=True ) if result['success']: print(f"Command succeeded: {cmd}") else: print(f"Command failed: {result['stderr']}")