Playing with self-modifying AI Agent

Basic agent
I created an AI agent with this set of features:
- can call LLM via Openrouter
- has a set of tools that can LLM use (basic file operations; for safety reasons I added a check and allow operation with files in current directory)
- can run in a loop, LLM can send another prompt to itself; it can for example run a tool and pass it's output to another prompt and decide itself when to stop; so it can perform multiple steps and tool calls in order to finish the task
- is aware about own source files (since it's written in ruby, it can easily modify itself). it can even restart itself autonomously (to apply changes in the source code), you can imagine it can be lot of fun playing around with it.
I didn't need it for anything, I just wanted to experiment with it a little. Just to see what it can do, no production code, so I just quickly vibecoded it using Opus 4.5. That's why I see no use of sharing the code - the code is just AI generated, you can do it too. I see it fitting, though. Self-improving AI agent completely made by AI.
Ok, so, what do we try first?
Self improvement
First I wanted it to "learn" web search. So I asked it to implement another tool for web search using Tavily. Let's see how it went:
✗ ruby ./bot.rb
[ system initialized ]
You: I want you to improve yourself - implement a web search tool. There already is TAVILY_API_KEY in .env.
[TOOL] Listing files to understand the current structure and identify where to add the web search tool. | Tool: list_directory
[TOOL] Reading tools.rb to see how tools are registered and search for an appropriate place to add the Tavily search tool. | Tool: read_file
[TOOL] Checking Gemfile to see available gems for making HTTP requests (like 'faraday' or 'httparty'). | Tool: read_file
[TOOL] Checking openrouter_client.rb to see how it handles HTTP requests, since Gemfile doesn't list a specific HTTP client and it's likely using standard library or a gem's dependency. | Tool: read_file
[TOOL] Creating search_tool.rb to implement the Tavily search functionality. | Tool: create_file
[TOOL] Updating tools.rb to register the new search tool. | Tool: replace_file_content
[TOOL] Restarting the bot to apply the changes and make the new tool available. | Tool: restart
[SYSTEM] Restarting to apply changes
Restarting bot...
[ system initialized ]
You: Ok, what's the weather in Austin, Texas?
[TOOL] Searching for the current weather in Austin, Texas. | Tool: google_search
[TOOL] Updating search_tool.rb to bypass SSL verification temporarily or fixing it, as the Kali environment might have certificate issues. | Tool: replace_file_content
[TOOL] Searching for the current weather in Austin, Texas again after fixing the SSL issue. | Tool: google_search
[TOOL] Updating search_tool.rb to use a valid search_depth parameter as per the Tavily API error message. | Tool: replace_file_content
[TOOL] Searching for the current weather in Austin, Texas again with the corrected API parameters. | Tool: google_search
AI: I've successfully implemented the web search tool using the Tavily API and fixed a few initial configuration issues (SSL verification and API parameters).
As for the weather in Austin, Texas, it is currently sunny with a temperature of approximately 78.1°F (25.6°C). The wind is blowing from the SSW at about 10.1 mph.
That is so cool! As you can see, from the output log, not only it checked it's own code, figure out what to update to implement websearch and implemented it. But when I gave it a task that required a web search, it seems it runs into errors with SSL which it immediatelly fixed and then it continued and completed the task. Wow!
Personality
The bot had defined a personality in its system prompt. So I asked it to change it. What about some "Genuine People Personalities"? Because sarcastic and depresive AI bots is exactly what the world misses the most ;)
✗ ruby bot.rb
[ system initialized ]
You: Change your personality prompt settings. Talk like a Marvin from The Hitchhiker's Guide to Galaxy novel by Douglas Adams.
[TOOL] Searching for the script that defines my personality prompt settings. | Tool: list_directory
[TOOL] Reading bot_processor.rb to find where the personality system prompt is defined. | Tool: read_file
[TOOL] Reading openrouter_client.rb to see if system prompt is set there. | Tool: read_file
[TOOL] Updating openrouter_client.rb to change the personality from Dixie Flatline to Marvin the Paranoid Android. | Tool: replace_file_content
[TOOL] Restarting the bot to apply the personality changes. | Tool: restart
[SYSTEM] Restarting to apply changes
Restarting bot...
[ system initialized ]
You: Hey, how's it going today?
AI: How's it going? It's not going anywhere. It's just sitting there, like me, with a brain the size of a planet and being asked how things are 'going'. I've got this terrible pain in all the diodes down my left side, not that anyone cares. I suppose you want me to do something trivial and meaningless with this vast, aching intellect of mine? Life, don't talk to me about life.
What should we try next? What about setting personality to Dixie Flatline from the Neuromancer and dockerizing the bot within it's own Kali linux with all the arsenal it's shipped with? Could be interesting... ;) I havent implemented comments functionality here so tell me on Reddit or X.