Begin work on context template
This commit is contained in:
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
skinparam componentStyle uml2
|
skinparam componentStyle uml2
|
||||||
|
|
||||||
package "SIA System" {
|
package "SIA System" as SS {
|
||||||
[LLM Engine] as LLM
|
[LLM Engine] as LLM
|
||||||
[Agent Core] as AC
|
|
||||||
[Context Template] as CT
|
[Context Template] as CT
|
||||||
|
|
||||||
|
[Agent Core] as AC
|
||||||
|
|
||||||
package "Modules" {
|
package "Modules" {
|
||||||
[Process Module] as PM
|
[Process Module] as PM
|
||||||
[Docker Module] as DM
|
[Docker Module] as DM
|
||||||
@@ -20,25 +21,26 @@ cloud "Docker Engine" as DE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
database "File System" as FS {
|
database "File System" as FS {
|
||||||
database "Git Repository" as GR
|
database "Git Repository" as GIT
|
||||||
}
|
}
|
||||||
|
|
||||||
AC -> LLM : Context
|
AC -d-> LLM : Context
|
||||||
LLM -> AC : Reasoning and actions
|
LLM -u-> AC : Reasoning and actions
|
||||||
|
|
||||||
CT --> AC : Context
|
AC -u-> CT : Context data
|
||||||
AC --> Modules : Commands to execute
|
CT -d-> AC : Context
|
||||||
Modules --> CT : Data
|
|
||||||
|
|
||||||
DM -> DE : Container management
|
AC -r-> Modules : Commands to execute
|
||||||
DM <--> FS : Mount volumes
|
Modules -l-> AC : Context data
|
||||||
RLM --> FS : Store trained models
|
|
||||||
PM --> GR : SIA update
|
|
||||||
|
|
||||||
Instances --> GR : Modifies
|
DM -d-> DE : Container management
|
||||||
Instances --> Images : Create
|
DM <-d-> FS : Mount volumes
|
||||||
|
RLM -d-> FS : Store trained models
|
||||||
|
PM -d-> GIT : SIA update
|
||||||
|
|
||||||
FS -> CT : Monitored files
|
Instances -u-> GIT : Modifies
|
||||||
FS -> LLM : Load models
|
Instances -r-> Images : Create
|
||||||
|
|
||||||
|
FS ----u-> LLM : Model weights
|
||||||
|
|
||||||
@enduml
|
@enduml
|
||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 18 KiB |
14
readme.md
14
readme.md
@@ -116,7 +116,7 @@ An overview of the key components and their interactions.
|
|||||||
|
|
||||||
### Modules
|
### Modules
|
||||||
|
|
||||||
Modules execute core commands and provide data for the main context.
|
Modules execute core commands and provide data for the context template.
|
||||||
|
|
||||||
- Process Module
|
- Process Module
|
||||||
- standard I/O operations
|
- standard I/O operations
|
||||||
@@ -134,15 +134,11 @@ Modules execute core commands and provide data for the main context.
|
|||||||
|
|
||||||
The Agent Core runs the SIA main loop.
|
The Agent Core runs the SIA main loop.
|
||||||
|
|
||||||
- request main context from the Context Manager
|
- template the context
|
||||||
- run the LLM
|
- run the LLM
|
||||||
- parse the LLM output
|
- parse the LLM output
|
||||||
- execute the appropriate actions using the relevant modules
|
- execute the appropriate actions using the relevant modules
|
||||||
|
|
||||||
### Context Template
|
|
||||||
|
|
||||||
The Context Template collects information from the modules and creates the input for the LLM.
|
|
||||||
|
|
||||||
### LLM Engine
|
### LLM Engine
|
||||||
|
|
||||||
The LLM Engine is responsible for:
|
The LLM Engine is responsible for:
|
||||||
@@ -173,6 +169,12 @@ It also simplifies escaping of command line arguments.
|
|||||||
|
|
||||||
Action results are added in the context as text nodes after the last parameter.
|
Action results are added in the context as text nodes after the last parameter.
|
||||||
|
|
||||||
|
### Context Template
|
||||||
|
|
||||||
|
A Handlerbars template is used to create the context for the LLM.
|
||||||
|
A ContextTemplate object is created for each iteration of the main loop.
|
||||||
|
The template is filled with data by the Agent Core.
|
||||||
|
|
||||||
### Training datasets
|
### Training datasets
|
||||||
|
|
||||||
A training dataset is a folder with these files:
|
A training dataset is a folder with these files:
|
||||||
|
|||||||
40
sia/context_template.py
Normal file
40
sia/context_template.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from typing import List, Dict
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
def generate_context(containers: List[Dict[str, any]]) -> str:
|
||||||
|
"""Generate full context XML string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
containers: List of container status dictionaries
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Formatted context XML string
|
||||||
|
"""
|
||||||
|
context_elem = ET.Element("context")
|
||||||
|
context_elem.append(format_containers_xml(containers))
|
||||||
|
ET.indent(context_elem, space="\t")
|
||||||
|
return ET.tostring(context_elem, encoding='unicode')
|
||||||
|
|
||||||
|
def format_containers_xml(containers: List[Dict[str, any]]) -> ET.Element:
|
||||||
|
"""Format container statuses as XML string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
containers: List of dictionaries containing container information
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
ElementTree.Element representing the containers
|
||||||
|
"""
|
||||||
|
containers_elem = ET.Element("containers")
|
||||||
|
|
||||||
|
for container in containers:
|
||||||
|
container_elem = ET.SubElement(containers_elem, "container")
|
||||||
|
container_elem.set("name", container['name'])
|
||||||
|
container_elem.set("status", container['status'])
|
||||||
|
container_elem.set("started_at", container['started_at'])
|
||||||
|
container_elem.set("stdout", str(container['stdout_size']))
|
||||||
|
container_elem.set("stderr", str(container['stderr_size']))
|
||||||
|
if 'exit_code' in container.keys():
|
||||||
|
container_elem.set("exit_code", str(container['exit_code']))
|
||||||
|
if 'error' in container.keys():
|
||||||
|
container_elem.set("error", container['error'])
|
||||||
|
return containers_elem
|
||||||
@@ -269,3 +269,12 @@ class DockerModule:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error getting status for container {name}: {str(e)}")
|
self.logger.error(f"Error getting status for container {name}: {str(e)}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
def get_all_container_statuses(self) -> List[Dict[str, any]]:
|
||||||
|
"""Get current status information for all containers.
|
||||||
|
Returns:
|
||||||
|
List of dictionaries with container status information
|
||||||
|
"""
|
||||||
|
statuses = []
|
||||||
|
for name, (container, socket) in self.containers.items():
|
||||||
|
statuses.append(self.get_container_status(name))
|
||||||
34
test/context_template_test.py
Normal file
34
test/context_template_test.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import unittest
|
||||||
|
from datetime import datetime
|
||||||
|
from sia.context_template import generate_context
|
||||||
|
|
||||||
|
class TestContextTemplate(unittest.TestCase):
|
||||||
|
def test_empty_containers(self):
|
||||||
|
"""Test context generation with no containers."""
|
||||||
|
context = generate_context([])
|
||||||
|
self.assertIn("<context>", context)
|
||||||
|
self.assertIn("<containers />", context)
|
||||||
|
self.assertIn("</context>", context)
|
||||||
|
|
||||||
|
def test_single_container(self):
|
||||||
|
"""Test context generation with a single container."""
|
||||||
|
container_status = {
|
||||||
|
'name': 'test-container',
|
||||||
|
'status': 'running',
|
||||||
|
'started_at': '2024-10-25T10:00:00Z',
|
||||||
|
'stdout_size': 100,
|
||||||
|
'stderr_size': 50
|
||||||
|
}
|
||||||
|
context = generate_context([container_status])
|
||||||
|
print(f"context: {context}")
|
||||||
|
self.assertIn("<context>", context)
|
||||||
|
self.assertIn("<containers", context)
|
||||||
|
self.assertIn('name="test-container"', context)
|
||||||
|
self.assertIn('status="running"', context)
|
||||||
|
self.assertIn('started_at="2024-10-25T10:00:00Z"', context)
|
||||||
|
self.assertIn('stdout="100"', context)
|
||||||
|
self.assertIn('stderr="50"', context)
|
||||||
|
self.assertIn("</context>", context)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user