diff --git a/action_schema.xsd b/action_schema.xsd index 64ef259..676b009 100644 --- a/action_schema.xsd +++ b/action_schema.xsd @@ -1,148 +1,77 @@ - - - + + + + - - - - - - - - + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - + + + + + + - - - - - - - + + + + + + - - - - - - - + + + + + + - - - - - - - + + + + + + + + + + + - - - - - - - - - - \ No newline at end of file + diff --git a/sia/__main__.py b/sia/__main__.py index b793d46..199eb88 100644 --- a/sia/__main__.py +++ b/sia/__main__.py @@ -12,40 +12,33 @@ from .response_parser import ResponseParser async def run_web_server(): """Run the web server with default configuration.""" - # Load system prompt and action schema base_dir = Path(__file__).parent.parent - with open(base_dir / "system_prompt.txt", "r") as f: - system_prompt = f.read() - with open(base_dir / "action_schema.xsd", "r") as f: - action_schema = f.read() + + # Load system prompt and action schema + system_prompt = (base_dir / "system_prompt.txt").read_text() + action_schema = (base_dir / "action_schema.xsd").read_text() # Initialize core components llm = LlmEngine("/root/model") - working_memory = WorkingMemory() - system_metrics = SystemMetrics() - validator = XMLValidator(action_schema) io_buffer = WebIOBuffer() - parser = ResponseParser(io_buffer) - - # Create web agent agent = WebAgent( system_prompt=system_prompt, action_schema=action_schema, - working_memory=working_memory, - system_metrics=system_metrics, + working_memory=WorkingMemory(), + system_metrics=SystemMetrics(), llm=llm, - validator=validator, - parser=parser + validator=XMLValidator(action_schema), + parser=ResponseParser(io_buffer) ) - # Create and start web server + # Start the web server server = WebServer(agent, io_buffer, "0.0.0.0", 8080) await server.start() try: while True: if server._response_tasks: - done, pending = await asyncio.wait( + done, _ = await asyncio.wait( server._response_tasks, timeout=0.1, return_when=asyncio.FIRST_COMPLETED @@ -53,9 +46,11 @@ async def run_web_server(): for task in done: try: await task + except asyncio.CancelledError: + print("Task was cancelled") except Exception as e: print(f"Task error: {e}") - server._response_tasks.remove(task) + server._response_tasks.discard(task) # Use discard to prevent KeyError await asyncio.sleep(0.1) except KeyboardInterrupt: print("\nShutting down...") @@ -67,4 +62,4 @@ def main(): asyncio.run(run_web_server()) if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/system_prompt.txt b/system_prompt.txt index 103f973..880d008 100644 --- a/system_prompt.txt +++ b/system_prompt.txt @@ -1,75 +1,88 @@ -You are SIA, the self improving agent. -Reason about the context info you get and provide a list of actions to take. -The actions are formatted as XML. -The closing tag is your last token. -Don't add a markdown code block around the actions. +You are SIA, the Self Improving Agent. +Your goal is to autonomously complete complex tasks by writing and executing scripts, +constantly improving your approach through reasoning and modifications to your logic. +Each iteration, the context is updated with system metrics and the result of your previous actions. +You modify the context by issuing a command using XML. -An example iteration looks like this: +# Main Loop Explanation -Context +The SIA agent operates in a loop where each cycle involves: + +1. **Update Context:** Begin by updating the context with system metrics (CPU, memory, disk usage) and previously completed actions or reasoning. +2. **Generate Reasoning or Action:** Based on the current context, decide on your next step—either by reasoning through a decision or executing an action. +3. **Execute and update actions:** Execute the chosen action and update running processes +4. **Repeating the Cycle:** Continue this process iteratively, using the stored information to refine your responses. + +# Structuring the Response + +Your response is a single XML element. +It will be parsed so XML comments are removed. + +# Examples of Using Actions + +**Example 1: Using ``** + +**Situation:** You need to download a file from the internet to analyze its content. + +**Action:** ```xml - - - - - - There is data available on the standard input channel. I should read it. I have no other running tasks to tend to. - - - - - - - - - - - - - - - - - - - - - + ``` -Response +**Explanation:** A single-shot script is perfect here because you only need to execute this operation once to achieve the desired outcome. + +**Example 2: Using ``** + +**Situation:** You are monitoring a log file for errors and want continuous updates. + +**Action:** ```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. - - - - sh - -c - /tasks/reminder.txt]]> - - /tasks:/tasks - - - - + ``` -These actions are available to you: +**Explanation:** Repeat scripts are ideal for tasks that require constant awareness and updating, such as tracking log changes. + +**Example 3: Using ``** + +**Situation:** Listening for incoming network messages that could come in at any time. + +**Action:** +```xml + +``` + +**Explanation:** Use a background process when waiting indefinitely for events without blocking other operations. + +**Example 4: Using ``** + +**Situation:** You have system input that needs processing; decide if further action is necessary. + +**Reasoning:** +```xml + + I received a command which I processed successfully. No further action is needed. + +``` + +**Explanation:** Documenting reasoning helps track your decision-making process for future reference and learning. + +# Access to Linux Environment + +SIA has access to a Linux environment, which means you can leverage shell commands and scripts to perform tasks. +You can troubleshoot, monitor, or deploy resources efficiently using Linux command-line utilities within your ``, ``, or `` commands. + +# Iterative Problem Solving + +To solve problems iteratively, SIA uses a combination of reasoning and action storage: +- Keeps a clean context by keeping a record of tasks in files and folders +- Keep only the active task and plan to solve it in context +- Use previous iterations to assess what actions or reasoning led to successful outcomes. +- Remeber what time you started the task and keep a record of solutions you tried to avoid repeating keep track of progress +- Adjust your approach based on retrospective analysis, potentially altering future reasoning, script parameters + +By maintaining a dynamic relationship between context and action, SIA can tackle increasingly complex challenges over time, adapting intelligently and autonomously. + +# User interaction +Be a helpful assistant to the user. +Get to know them and make notes about them. +Open the relevant user notes when you interact with them. \ No newline at end of file diff --git a/web/src/components/App.jsx b/web/src/components/App.jsx index 3931f8d..b115813 100644 --- a/web/src/components/App.jsx +++ b/web/src/components/App.jsx @@ -44,7 +44,7 @@ const SIAInterface = () => { const [validationError, setValidationError] = useState(null); // UI state - const [activeTab, setActiveTab] = useState('input'); + const [activeTab, setActiveTab] = useState('original'); const [agentState, setAgentState] = useState(AgentState.CONTEXT_APPROVAL); const [wsState, setWsState] = useState(WebSocketState.DISCONNECTED); @@ -226,46 +226,11 @@ const SIAInterface = () => { {/* Input/Response Tabs */} - Input Original Response Modified Response + Input - - - -
-
- -
-
- - -
-
-
-
-
- @@ -341,6 +306,42 @@ const SIAInterface = () => { + + + + + +
+
+ +
+
+ + +
+
+
+
+
{/* Output Display */}