This project implements an autonomous CLI agent that can read, write, and execute code using proper CLI commands. It utilizes a language model to generate plans and execute steps based on user input.
To run the agent, execute the following command:
python3 cli_agent.py "textfile.txt has some grammatic errors. Fix the file."- File reading and writing capabilities
- Code execution support
- Directory management functions
- Interactive planning and execution process
- Rich console output formatting
typer: For building the command-line interfacerich: For enhanced console output formattingollama: For interacting with the language modelsubprocess: For executing shell commands
The agent will prompt you for a query, generate a goal, create a plan, and then execute the steps one by one.
DESTRUCTIVE_COMMANDS: A list of commands that could potentially cause harm if executedLLM_MODEL: The default language model used for generating plans and explanationsSYSTEM_PROMPT: The initial prompt given to the language model
ask_llm: Interacts with the language model to get responsesexecute_command: Executes or simulates CLI commandsgenerate_plan: Creates a step-by-step plan to achieve a goalparse_steps: Extracts individual steps from the generated planexecute_step: Determines the next CLI command to execute for a given stepmain: Orchestrates the entire process, including querying, planning, and execution
- Destructive command detection: The agent will stop execution if a destructive command is encountered
- Simulated execution: Allows for testing without actually running potentially harmful commands
To contribute to this project:
- Fork the repository
- Clone your forked copy
- Set up a virtual environment and install dependencies
- Write tests and make changes
- Commit your changes and push to your branch
- Open a pull request
This project is licensed under the MIT License. See the LICENSE file for details.
This project was inspired by the concept of autonomous agents and utilizes open-source libraries for natural language processing and console output formatting.