Response parser and split up class diagrams

This commit is contained in:
2024-11-01 11:38:28 +01:00
parent 165279ecc7
commit d80171de15
6 changed files with 932 additions and 177 deletions

407
readme.md
View File

@@ -267,7 +267,100 @@ This architecture allows for:
- Human-in-the-loop operation for testing and development
- Collection of human feedback for reinforcement learning
### Standard Agent Flow
### Diagrams
#### Core classes
```mermaid
classDiagram
class SystemMetrics {
+SystemMetrics(sample_interval float)
+generate_context(context_usage float) ElementTree
+stop() void
-monitor_loop() void
}
class LLMEngine {
+LLMEngine(model_path str)
+set_model_path(model_path str) void
+infer(system_prompt str, main_context str) Iterator~str~
}
class BaseAgent {
<<abstract>>
#working_memory: WorkingMemory
#metrics: SystemMetrics
#llm: LLMEngine
#parser: ResponseParser
#validator: XMLValidator
#io_buffer: IOBuffer
#compile_context() str
}
class WorkingMemory {
-entries: List~Entry~
+WorkingMemory()
+add_entry(entry Entry) void
+remove_entry(id str) void
+clear() void
+get_entry(id str) Optional~Entry~
+get_entries() List~Entry~
+get_entries_count() int
+get_entries_by_type(type Type) List~Entry~
+update() void
+generate_context() List~ElementTree~
}
class XMLValidator {
+XMLValidator(schema str)
+validate(xml str) Optional~str~
+get_valid_root_elements() Set~str~
}
class ResponseParser {
-io_buffer: IOBuffer
+ResponseParser(io_buffer IOBuffer)
+parse(xml str) Union~Command, Entry~
}
class Entry {
<<abstract>>
+id: str
+timestamp: datetime
+Entry(id str, timestamp datetime)
+update() void*
+generate_context() ElementTree*
+cleanup() void*
}
class IOBuffer {
<<interface>>
+read() str*
+write(content str) void*
+buffer_length() int*
}
class Command {
<<abstract>>
+execute(memory WorkingMemory) CommandResult*
}
SystemMetrics "1" --* "1" BaseAgent
LLMEngine "1" --* "1" BaseAgent
XMLValidator "1" --* "1" BaseAgent
BaseAgent "1" *-- "1" IOBuffer
BaseAgent "1" *-- "1" WorkingMemory
BaseAgent "1" *-- "1" ResponseParser
WorkingMemory "1" *-- "*" Entry
ResponseParser ..> Entry
ResponseParser ..> Command
```
#### Standard Agent Flow
```mermaid
stateDiagram-v2
@@ -287,7 +380,74 @@ stateDiagram-v2
}
```
### Web Agent Flow
#### Web Agent
```mermaid
classDiagram
class BaseAgent {
<<abstract>>
#working_memory: WorkingMemory
#metrics: SystemMetrics
#llm: LLMEngine
#parser: ResponseParser
#validator: XMLValidator
#io_buffer: IOBuffer
#compile_context() str
}
class StandardAgent {
+StandardAgent(model_path str, system_prompt str, action_schema str)
+run() void
}
class WebAgent {
-current_state: WebAgentState
+WebAgent(model_path str, system_prompt str, action_schema str)
+get_current_state() WebAgentState
+proceed() void
+add_state_change_handler(handler func) void
}
class WebAgentState {
<<enumeration>>
UPDATE
CONTEXT_APPROVAL
INFERENCE
RESPONSE_APPROVAL
}
class WebServer {
-agent: WebAgent
-clients: List~WebSocket~
+WebServer(agent WebAgent)
-broadcast_state_change() void
}
class WebIOBuffer {
-stdin_buffer: str
-stdout_buffer: str
+WebIOBuffer()
+read() str
+write(content str) void
+buffer_length() int
+append_stdin(content str) void
+get_stdout() str
+clear_stdout() void
}
BaseAgent <|-- WebAgent
BaseAgent <|-- StandardAgent
WebServer "1" *-- "1" WebIOBuffer
WebServer "1" *-- "1" WebAgent
WebAgent "1" *-- "1" WebAgentState
```
#### Web Agent Flow
```mermaid
stateDiagram-v2
@@ -314,226 +474,169 @@ stateDiagram-v2
}
```
### Class Diagram
#### Entry classes
```mermaid
classDiagram
direction LR
class BaseAgent {
<<abstract>>
#working_memory WorkingMemory
#metrics SystemMetrics
#llm LLMEngine
#parser ResponseParser
#validator XMLValidator
#io_buffer IOBuffer
#compile_context() str
}
class LLMEngine {
+LLMEngine(model_path str)
+set_model_path(model_path str)
+inference(context str) Iterator~str~
}
class StandardAgent {
+run()
}
class WebAgent {
-current_state WebAgentState
+get_current_state() WebAgentState
+proceed()
+add_state_change_handler(handler func())
}
class WebAgentState {
<<enumeration>>
UPDATE
CONTEXT_APPROVAL
INFERENCE
RESPONSE_APPROVAL
}
class WorkingMemory {
+WorkingMemory()
-entries List~Entry~
+add_entry(entry Entry)
+remove_entry(id str)
+update()
+generate_context() List~ElementTree~
}
class SystemMetrics {
+generate_context(entries List~ElementTree~) ElementTree
}
class XMLValidator {
-schema ElementTree
+XMLValidator(schema str)
+validate(xml str) Optional~str~
}
class ResponseParser {
-io_buffer IOBuffer
+ResponseParser(io_buffer IOBuffer)
+parse(xml str) Command | Entry
}
class Entry {
<<abstract>>
+id str
+timestamp datetime
+id: str
+timestamp: datetime
+Entry(id str, timestamp datetime)
+update()*
+update() void*
+generate_context() ElementTree*
+cleanup() void*
}
class SingleShotEntry {
+script str
+stdout str
+stderr str
+exit_code int
+script: str
+stdout: str
+stderr: str
+exit_code: Optional~int~
+SingleShotEntry(script str, id str, timestamp datetime)
+update()
+update() void
+generate_context() ElementTree
}
class RepeatEntry {
+script str
+stdout str
+stderr str
+exit_code int
+script: str
+stdout: str
+stderr: str
+exit_code: Optional~int~
+RepeatEntry(script str, id str, timestamp datetime)
+update()
+update() void
+generate_context() ElementTree
}
class BackgroundEntry {
+script str
+stdout str
+stderr str
+process Process
+script: str
+stdout: str
+stderr: str
+process: Optional~Process~
-accumulated_stdout: str
-accumulated_stderr: str
-exit_code: Optional~int~
+BackgroundEntry(script str, id str, timestamp datetime)
+update()
+update() void
+generate_context() ElementTree
+cleanup() void
}
class ReasoningEntry {
+content str
+content: str
+ReasoningEntry(content str, id str, timestamp datetime)
+update()
+update() void
+generate_context() ElementTree
}
class ParseErrorEntry {
+content str
+error str
+content: str
+error: str
+ParseErrorEntry(content str, error str, id str, timestamp datetime)
+update()
+update() void
+generate_context() ElementTree
}
class ReadEntry {
+content str
+content: str
+io_buffer: IOBuffer
+ReadEntry(io_buffer IOBuffer, id str, timestamp datetime)
+update()
+update() void
+generate_context() ElementTree
}
class WriteEntry {
+content str
+content: str
+io_buffer: IOBuffer
+WriteEntry(content str, io_buffer IOBuffer, id str, timestamp datetime)
+update()
+update() void
+generate_context() ElementTree
}
ReasoningEntry --|> Entry
ParseErrorEntry --|> Entry
ReadEntry --|> Entry
Entry <|-- WriteEntry
Entry <|-- SingleShotEntry
Entry <|-- RepeatEntry
Entry <|-- BackgroundEntry
```
#### IO Buffer classes
```mermaid
classDiagram
class IOBuffer {
<<interface>>
+read() str*
+write(content str)*
+write(content str) void*
+buffer_length() int*
}
class StandardIOBuffer {
+StandardIOBuffer()
+read() str
+write(content str)
+write(content str) void
+buffer_length() int
}
class WebIOBuffer {
-stdin_buffer str
-stdout_buffer str
-stdin_buffer: str
-stdout_buffer: str
+WebIOBuffer()
+read() str
+write(content str)
+write(content str) void
+buffer_length() int
+append_stdin(content str)
+append_stdin(content str) void
+get_stdout() str
+clear_stdout()
+clear_stdout() void
}
IOBuffer <|.. WebIOBuffer
IOBuffer <|.. StandardIOBuffer
```
#### Command classes
```mermaid
classDiagram
direction LR
class Command {
<<abstract>>
+execute(memory WorkingMemory) CommandResult*
}
class DeleteCommand {
+DeleteCommand(id str)
+execute(memory WorkingMemory) CommandResult
}
class StopCommand {
+StopCommand()
+execute(memory WorkingMemory) CommandResult
}
class CommandResult {
+should_stop bool
+success bool
+message str
+CommandResult(should_stop bool, success bool, message str)
+message: str
+success: bool
+should_stop: bool
+CommandResult(message str, success bool, should_stop bool)
+static success() CommandResult
+static failure(message str) CommandResult
+static stop() CommandResult
}
class Command {
<<abstract>>
+execute(memory &WorkingMemory) CommandResult*
}
class DeleteCommand {
+id str
+DeleteCommand(id str)
+execute(memory &WorkingMemory) CommandResult
}
class StopCommand {
+execute(memory &WorkingMemory) CommandResult
}
class WebServer {
-agent WebAgent
-clients List~WebSocket~
+WebServer(agent WebAgent)
-broadcast_state_change()
}
BaseAgent <|-- WebAgent
BaseAgent <|-- StandardAgent
BaseAgent "1" *-- "1" IOBuffer
BaseAgent "1" *-- "1" WorkingMemory
BaseAgent "1" *-- "1" SystemMetrics
BaseAgent "1" *-- "1" XMLValidator
BaseAgent "1" *-- "1" LLMEngine
BaseAgent "1" *-- "1" ResponseParser
WebServer "1" *-- "1" WebIOBuffer
WebServer "1" *-- "1" WebAgent
WebAgent "1" *-- "1" WebAgentState
WorkingMemory "1" *-- "*" Entry
Entry <|-- ReasoningEntry
Entry <|-- ParseErrorEntry
Entry <|-- ReadEntry
Entry <|-- WriteEntry
Entry <|-- SingleShotEntry
Entry <|-- RepeatEntry
Entry <|-- BackgroundEntry
Command <|-- DeleteCommand
Command <|-- StopCommand
Command -- CommandResult
IOBuffer <|.. WebIOBuffer
IOBuffer <|.. StandardIOBuffer
```