211 lines
7.0 KiB
Markdown
211 lines
7.0 KiB
Markdown
# SIA - The Self Improving Agent
|
|
|
|
SIA is an agentic artificial intelligence system that autonomously completes complex tasks by writing and executing scripts.
|
|
It uses a Large Language Model (LLM) which operates in a loop, generating reasoning and actions based on an updating context.
|
|
Context, reasoning and actions are stored in a file for each iteration.
|
|
SIA can read past iterations to improve its reasoning and actions.
|
|
It can improve in two ways:
|
|
- By providing better reasoning or actions for a given context and update the LLM.
|
|
- By modifying its own source code.
|
|
|
|
## Working principles
|
|
|
|
High-level overview of the main components of SIA and how they work together.
|
|
|
|
### Scripts
|
|
|
|
Scripts can run in one of 3 modes: single-shot, background or repeat.
|
|
Their mode, status and output (stdout and stderr) stay in the context until they are explicitly removed.
|
|
In this way the agent manages what information is available in the context.
|
|
|
|
#### Single-shot
|
|
|
|
The script is executed once.
|
|
This is useful for most operations e.g. writing to or moving a file or downloading content from the internet.
|
|
The next iteration starts after all single shot scripts have finished.
|
|
|
|
#### Repeat
|
|
|
|
The script is restarted on each iteration.
|
|
This is useful for monitoring files or the file system.
|
|
commands like `head` and `tail` can be used to limit the data in context.
|
|
Similar to single-shot scripts, the next iteration starts after all repeat scripts have finished.
|
|
|
|
#### Background
|
|
|
|
The script is started and keeps running.
|
|
This is useful for long-running processes e.g. a web server or a communication channel.
|
|
Because output of a background script can grow long, it is often redirected to a file.
|
|
|
|
### LLM prompt
|
|
|
|
The main context is regenerated for each iteration.
|
|
It contains info about the system, the scripts and what happended in the previous iteration.
|
|
Together with the system prompt and available core actions it forms the prompt for the LLM.
|
|
|
|
The LLM generates reasoning and an XML structure with core actions.
|
|
If the structure cannot be parsed, the error is described and the LLM is asked to try again.
|
|
This can continue until the context overflows.
|
|
Only the first reasoning, last reasoning and last actions are shown in the new context.
|
|
All is stored on the file system.
|
|
|
|
### Core Actions
|
|
|
|
There are only a few core actions:
|
|
- Starting a script
|
|
- Stopping a script
|
|
- Stopping SIA
|
|
- Reading standard input
|
|
- Writing to standard output
|
|
|
|
Standard error is used by the core for debugging.
|
|
|
|
SIA typically runs in a Docker container.
|
|
When stopped, the latest container version is pulled.
|
|
This is how SIA can be updated.
|
|
|
|
SIA can also run SIA processes as script.
|
|
This can be used for testing updates to the LLM or core functionality.
|
|
|
|
### Use of XML
|
|
|
|
The context and actions are formatted as XML.
|
|
For the context this adds clear rules for escaping.
|
|
This is usefull in case a previous context is embedded.
|
|
|
|
The response starts with freeform reasoning followed by XML formatted actions.
|
|
In case the LLM makes a mistake it can start over.
|
|
Only the last XML block is evaluated.
|
|
|
|
Action results are added in the context in the previous_iteration section.
|
|
|
|
### Server for debuggin and human input
|
|
|
|
SIA can be started with an optional `--server` flag.
|
|
This starts a web server that can be used to interact with SIA.
|
|
It is made, specifically for reinforcement learning by human feedback.
|
|
The web interface takes over standard input and output.
|
|
It will display the context for editing before handing it to the LLM.
|
|
After each run of the LLM, before parsing, it will display the reasoning and actions.
|
|
It interactively displays if the actions can be parsed.
|
|
At any time, the user can write to the standard input of SIA.
|
|
|
|
## Architecture
|
|
|
|
An overview of the key components and their interactions.
|
|
|
|

|
|
|
|
### Modules
|
|
|
|
Modules execute core commands and provide data for the context template.
|
|
|
|
- System Module
|
|
- System information
|
|
- SIA stdio operations
|
|
- Stopping SIA (possibly triggering an update)
|
|
- Process Module
|
|
- Starting scripts
|
|
- Stopping scripts
|
|
- Managing process stdio and status
|
|
|
|
### Agent Core
|
|
|
|
The Agent Core runs the SIA main loop.
|
|
This loop consists of:
|
|
- Templating the context
|
|
- Running the LLM
|
|
- Parsing the LLM output
|
|
- Rerunning the LLM if the output cannot be parsed
|
|
- Executing the appropriate actions
|
|
|
|
### Server Core
|
|
|
|
The Server Core is an alternative for the Agent Core.
|
|
It runs a modified main loop and ues the WebSystem Module.
|
|
This is an extension of the System Module redirecting stdio to the web interface.
|
|
|
|
### LLM Engine
|
|
|
|
The LLM Engine does the LLM inference.
|
|
It takes a context and returns an iterator of tokens.
|
|
|
|
### Inference Result
|
|
|
|
An Inference Result object contains the resoning and parsed actions.
|
|
Parsing is part of the Inference Result constructor.
|
|
|
|
## Example iterations
|
|
|
|
### Clarifying a task
|
|
|
|
This example shows how to work with standard IO, run simple scripts and monitor files.
|
|
|
|
#### Context
|
|
|
|
```xml
|
|
<context>
|
|
<system
|
|
time="2024-10-18T12:00:00Z"
|
|
cpu="12"
|
|
gpu="26"
|
|
memory_used="9556302234"
|
|
memory_total="17179869184"
|
|
disk_used="244434939904"
|
|
disk_total="273145991168"
|
|
context="3"
|
|
stdin="0"
|
|
/>
|
|
<containers/>
|
|
<previous>
|
|
<reasoning>
|
|
There is data available on the standard input channel. I should read it. I have no other running tasks to tend to.
|
|
</reasoning>
|
|
<actions>
|
|
<read_stdin>
|
|
<![CDATA[Remind me to feed the cat tomorrow morning]]>
|
|
</read_stdin>
|
|
</actions>
|
|
</previous>
|
|
<files>
|
|
<file name="/" type="dir" index="0">
|
|
<![CDATA[
|
|
drwxr-xr-x 1 sia 197121 0 2024-10-16 23:02:16.486152500 +0200 tasks/
|
|
drwxr-xr-x 1 sia 197121 0 2024-10-16 22:35:31.806079500 +0200 user/
|
|
]]>
|
|
</file>
|
|
<file name="/tasks" type="dir" index="1">
|
|
</file>
|
|
<file name="/user" type="dir">
|
|
<![CDATA[
|
|
-rw-r--r-- 1 sia 197121 71 2024-10-16 22:41:23.223580300 +0200 general_info.txt
|
|
]]>
|
|
</file>
|
|
<file name="/user/general_info.txt" type="file" index="2">
|
|
<![CDATA[
|
|
Name: John (I don't know his last name)
|
|
Location: Somewhere in Belgium
|
|
]]>
|
|
</file>
|
|
</files>
|
|
</context>
|
|
```
|
|
|
|
#### LLM response
|
|
|
|
```xml
|
|
John did not specify an exact time. I'll suggest 9am. He also did not specify how to be reminded. I'll ask but if he doesn't respond I'll assume a text message on standard output is fine. I'll write down this task in a file so I can keep it in context. I can write simple files with busybox:latest and echo but I will need to use sh -c to do the redirect.
|
|
<actions>
|
|
<write_stdout message="I'll remind you to feed the cat tomorrow morning at 9am. Is a message on the standard output ok?"/>
|
|
<start_container image="busybox:latest" timeout="1000">
|
|
<command>sh</command>
|
|
<argtument>-c</argument>
|
|
<argument><![CDATA[echo 'Remind John to feed the cat on 2024-10-18T09:00:00+02:00. Use standard output.' > /tasks/reminder.txt]]></argument>
|
|
<volumes>
|
|
<volume>/tasks:/tasks</volume>
|
|
</volumes>
|
|
</start_container>
|
|
<monitor_file path="/tasks/reminder.txt"/>
|
|
</actions>
|
|
```
|