GuiAgentLoopCore Architecture Documentation Version: 1.0
GuiAgentLoopCore is organized into distinct layers with clear responsibilities:
┌─────────────────────────────────────────────────────────────┐
│ Application Layer │
│ (User's Application) │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Backend Layer │
│ (Gradio UI, Future: Streamlit, React, etc.) │
│ - Event handling │
│ - UI rendering │
│ - I/O conversion │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Core Layer (★Main Focus★) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Interpreter │ │
│ │ - State management (INIT → RUNNING → STOP) │ │
│ │ - Session management │ │
│ │ - Agent coordination │ │
│ │ - Message routing │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ │
│ │ Agent │ │ Message │ │ State │ │
│ │ │ │ │ │ Machine │ │
│ └──────────┘ └──────────┘ └──────────────────┘ │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Agent Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ AGENT_ │ │ LLM_ │ │ SUPERVISOR │ │
│ │ EXECUTOR │ │ PLANNER │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
│ - Role-based execution │
│ - Tool calling │
│ - Structured chat │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Utility Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Stream │ │ Converter │ │ Memory │ │
│ │ Wrapper │ │ │ │ Buffer │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
Location: gui_agent_loop_core/core/interpreter_manager.py
Responsibilities:
- State management (STATE_INIT, STATE_RUNNING, STATE_STOP)
- Session lifecycle management
- Agent coordination and task distribution
- Message routing between users, agents, and system
- AutoChat trigger management
Key Methods:
change_state_running(): Transition to RUNNING statecreate_session(): Initialize new session with unique UUIDprocess_message(): Route message to appropriate handlerauto_chat(): Trigger continuation when in STATE_STOP
Invariants:
- INV-STATE-001: State transitions are monotonic
- INV-AUTO-001: AutoChat only triggers in STATE_STOP
- INV-SESSION-001: Sessions have unique UUIDs
Location: gui_agent_loop_core/schema/agent/
Responsibilities:
- Agent role management (AgentName enum)
- Agent type handling (TOOL_CALLING, STRUCTURED_CHAT)
- Agent lifecycle (creation, execution, termination)
Agent Roles:
AGENT_EXECUTOR: Executes tool callsLLM_PLANNER: Plans task decompositionSUPERVISOR: Coordinates multiple agentsTHOUGHT: Handles reasoning tasksCREW: Manages agent teamsOTHER: Catch-all for undefined roles
Invariants:
- INV-AGENT-001: Agents have defined roles
Location: gui_agent_loop_core/schema/message/
Responsibilities:
- Message type validation
- Message structure enforcement
- Message transformation and flattening
Message Types (MessageTypeEnum):
MESSAGE: Standard text messageCODE: Code execution resultCONFIRMATION: User confirmation requestCONSOLE: Console outputIMAGE: Image contentFUNCTION: Function call/response
Invariants:
- INV-MSG-001: Only enumerated message types allowed
- INV-MESSAGE-001: Message history limited to MAX_MESSAGE_LENGTH=100
Location: gui_agent_loop_core/util/gui_agent_stream_wrapper.py
Responsibilities:
- Unified sync/async streaming interface
- Response aggregation
- Stream lifecycle management
Invariants:
- INV-STREAM-001: Supports both sync and async
Location: gui_agent_loop_core/converter/request_converter.py
Responsibilities:
- Request format conversion
- Dictionary flattening (recursive)
- Code content extraction (format/language fields)
Invariants:
- INV-CONVERTER-001: Uses MappingRule for structured transformations
Location: gui_agent_loop_core/connector_impl/
Responsibilities:
- Interface implementation for agent connections
- Abstract base class (InterpreterABC)
- Concrete implementations for different agent types
Invariants:
- INV-CONNECTOR-001: Must implement InterpreterABC interface
Location: gui_agent_loop_core/memory/ (planned)
Responsibilities:
- Conversation history management
- Sliding window (k=10, AUTO decision)
- Message retrieval and filtering
Invariants:
- INV-MEM-001: Maximum 100 messages (soft limit)
User Input (Backend)
│
├─► I/O Conversion
│ └─► RequestConverter (flatten, extract code)
│
├─► Interpreter (state: RUNNING)
│ │
│ ├─► Agent Selection (based on role)
│ │
│ ├─► Agent Execution
│ │ └─► LLM API Call
│ │
│ └─► Response Collection
│ └─► StreamWrapper (sync/async)
│
└─► Response Formatting
└─► Backend → User
INIT
│ user sends message
├─► RUNNING
│ │
│ ├─► Agent executes
│ ├─► Response sent
│ │
│ └─► STOP
│ │
│ ├─► AutoChat? (if enabled)
│ │ └─► RUNNING (loop)
│ │
│ └─► Wait for user input
│ └─► RUNNING
Includes:
- State management
- Session management
- Message routing
Excludes:
- UI rendering (Backend's responsibility)
- LLM execution (Agent's responsibility)
Includes:
- Role definition
- Task execution
- LLM interaction
Excludes:
- Session management (Interpreter's responsibility)
- UI rendering (Backend's responsibility)
Includes:
- UI component rendering
- Event handling
- I/O format conversion
Excludes:
- Conversation logic (Interpreter's responsibility)
- Agent management (Interpreter's responsibility)
- Implement the server interface
- Handle UI-specific event conversion
- Call Interpreter methods for logic
- Format responses for UI
Example: See gui_agent_loop_core/backend/server_impl_gradio.py
- Add to
AgentNameenum inschema/core/schema.py - Implement agent-specific logic
- Update
.concept/ontology.ymlwith new term if needed - Add tests for the new agent
- Add to
MessageTypeEnuminschema/message/schema.py - Update message handlers
- Add tests for the new type
- Document in
.concept/invariants.yml
Rationale:
- Excellent LLM library support
- Type hints for safety
- Async/await for streaming
Rationale:
- Compile-time type checking
- IDE autocomplete support
- Prevents invalid values
Rationale:
- Global uniqueness
- No centralized coordination needed
- Security (unpredictable)
Rationale:
- Predictable behavior
- Easy to reason about
- Testable
This architecture incorporates several AUTO decisions that reflect provisional specifications. These decisions are tracked in .concept/ambiguities.yml and may evolve as the project matures.
- AUTO:Memory.window:k10: Conversation memory uses rolling window of size k=10
- AUTO:Memory.specs:provisional: Window size k=10 (rolling) + max length 100 (hard limit)
- Status: Draft, subject to change based on performance testing
- AUTO:Backend.primary:gradio: Gradio is the primary backend implementation
- AUTO:Backend.deployment:security: Backend launches on 0.0.0.0 with allowed_paths security restrictions
- Affects: Security architecture and deployment configuration
- Related Invariant: INV-BACKEND-001, INV-BACKEND-002
- AUTO:State.timer:3sec: State is auto-updated every 3 seconds via Gradio timer
- Affects: Timer-based polling mechanism in Backend layer
- Related Invariant: INV-STATE-002, INV-BACKEND-002
- AUTO:State.transition:auto_on_input: User input automatically transitions to RUNNING
- AUTO:Connector.layer:domain: Connector is a canonical domain concept
- Affects: How connectors are abstracted and integrated
- Related Invariant: INV-CONNECTOR-001
- AUTO:Session.jwt:algorithm_hs256: HS256 algorithm is sufficiently secure (provisional)
- Affects: Session token encoding/decoding
- Related Invariant: INV-SESSION-002
Note: These AUTO decisions are marked as "provisional" and may be refined. See AGENTS.md for complete AUTO decision documentation.
Related Documents:
- SYSTEM_CONSTITUTION.md - Constitutional constraints
- PURPOSE.md - Project purpose and objectives
.concept/mappings.yml- Concept-to-code mappings.concept/ambiguities.yml- AUTO decisions tracking