Spaces:
Paused
Paused
| # π PygmyClaw Multi-Agent System β Architecture & Progress | |
| --- | |
| # π Overview | |
| This project is evolving into a **multi-agent AI command center** capable of: | |
| * Code generation & execution | |
| * Task routing (code / research / image) | |
| * Persistent sessions | |
| * Memory + history tracking | |
| * Hugging Face dataset logging | |
| * Autonomous workflows (future) | |
| --- | |
| # π― Vision | |
| > A unified AI system that can **think, act, remember, and improve over time** | |
| --- | |
| # π§ System Architecture | |
| ## High-Level Flow | |
| ``` | |
| User Prompt | |
| β | |
| Agent Router | |
| β | |
| Agent Executor (LLM) | |
| β | |
| Output Parser | |
| β | |
| Execution Layer (Code / Tools) | |
| β | |
| Session Manager (Save State) | |
| β | |
| HF Upload (Persistence) | |
| β | |
| Final Response | |
| ``` | |
| --- | |
| # π§± Core Components | |
| ## 1. `session_manager.py` | |
| ### Responsibility: | |
| * Manage session lifecycle | |
| * Store: | |
| * `workspace.json` | |
| * `history.json` | |
| ### Key Methods: | |
| ```python | |
| create_session() | |
| load_session(session_id) | |
| append_history(data) | |
| update_workspace(key, value) | |
| get_history() | |
| ``` | |
| ### Structure: | |
| ``` | |
| /workspace/hf/sessions/ | |
| βββ sess_xxxx/ | |
| βββ workspace.json | |
| βββ history.json | |
| ``` | |
| --- | |
| ## 2. `agent_router.py` | |
| ### Responsibility: | |
| Route user intent β correct agent type | |
| ### Logic: | |
| ```python | |
| "code" β coding agent | |
| "research" β research agent | |
| "image" β image agent | |
| default β command agent | |
| ``` | |
| ### Example: | |
| | Input | Routed To | | |
| | ------------------- | --------- | | |
| | "write python code" | code | | |
| | "who is elon musk" | research | | |
| | "generate image" | image | | |
| --- | |
| ## 3. `agent_executor.py` | |
| ### Responsibility: | |
| Wrapper around **PygmyClaw LLM** | |
| ### Features: | |
| * Injects **system prompts** | |
| * Controls behavior per agent type | |
| ### Example: | |
| ```python | |
| if agent_type == "code": | |
| return """ | |
| - Only return Python code | |
| - No JSON | |
| - Must be executable | |
| """ | |
| ``` | |
| --- | |
| ## 4. `run_llm()` (Core Brain) | |
| ### Responsibilities: | |
| * Call executor | |
| * Log output | |
| * Save to session | |
| * Upload to HF | |
| ### Flow: | |
| ``` | |
| Prompt β LLM β Response | |
| β | |
| Save history | |
| β | |
| Upload session | |
| ``` | |
| --- | |
| ## 5. `run_agent()` | |
| ### Responsibilities: | |
| * Route task | |
| * Call LLM | |
| * Extract code | |
| * Execute if needed | |
| ### Flow: | |
| ``` | |
| Prompt | |
| β | |
| Router β agent_type | |
| β | |
| LLM | |
| β | |
| Code Extract | |
| β | |
| Execute (if code) | |
| ``` | |
| --- | |
| ## 6. Code Execution Layer | |
| ### Current: | |
| ```python | |
| def run_code(code): | |
| write β temp file | |
| execute β python3 file | |
| ``` | |
| ### Issues solved: | |
| * Syntax errors handled | |
| * Execution isolated | |
| * Logging added | |
| --- | |
| ## 7. Hugging Face Upload | |
| ### Dataset: | |
| ``` | |
| rahul7star/pyclaw2 | |
| ``` | |
| ### Structure: | |
| ``` | |
| sessions/ | |
| βββ sess_xxx/ | |
| βββ workspace.json | |
| βββ history.json | |
| ``` | |
| ### Upload Logic: | |
| ```python | |
| upload_session(session_id) | |
| ``` | |
| --- | |
| # π Current System Flow (Detailed) | |
| ``` | |
| User Input | |
| β | |
| route_task() | |
| β | |
| AgentExecutor.run() | |
| β | |
| LLM Output | |
| β | |
| extract_code() | |
| β | |
| run_code() (if needed) | |
| β | |
| SessionManager.append_history() | |
| β | |
| upload_session() | |
| β | |
| Return result | |
| ``` | |
| --- | |
| # β What We Have Built So Far | |
| ## β Core System | |
| * β Multi-agent routing | |
| * β LLM execution wrapper | |
| * β Code extraction & execution | |
| * β Session persistence | |
| * β HF dataset integration | |
| * β Command system (REPL) | |
| --- | |
| ## β Stability Fixes | |
| * Fixed session initialization errors | |
| * Fixed missing `session_id` | |
| * Fixed upload path issues | |
| * Fixed PygmyClaw API mismatches | |
| * Fixed shell execution fallback | |
| * Fixed malformed LLM outputs (partial) | |
| --- | |
| ## β Working Features | |
| * Generate & run Python code | |
| * Save execution history | |
| * Persist sessions across runs | |
| * Upload sessions to HF | |
| * Basic autonomous agent loop | |
| --- | |
| # β οΈ Known Limitations | |
| * β LLM sometimes returns invalid code | |
| * β No retry/fix loop yet | |
| * β Tools not fully functional | |
| * β No argument parsing for tools | |
| * β No model switching (yet) | |
| --- | |
| # π§ Design Philosophy | |
| ## 1. Local-First Execution | |
| * Prefer running code locally over LLM calls | |
| ## 2. Structured Memory | |
| * Everything stored in session files | |
| ## 3. Deterministic Flow | |
| * Avoid unpredictable LLM outputs when possible | |
| ## 4. Modular Agents | |
| * Each agent has a clear responsibility | |
| --- | |
| # π Next Steps (Roadmap) | |
| --- | |
| ## π₯ Phase 1 (Current β Stabilization) | |
| * [ ] Improve code validation before execution | |
| * [ ] Add retry loop for failed code | |
| * [ ] Improve logging & debugging | |
| --- | |
| ## π₯ Phase 2 (Next) | |
| ### Multi-Model Routing | |
| ``` | |
| Code β Code LLM | |
| Research β Reasoning LLM | |
| Image β Diffusion model | |
| ``` | |
| --- | |
| ## π₯ Phase 3 | |
| ### Tool System (Deferred) | |
| * Convert code β reusable tools | |
| * Tool execution engine | |
| * Tool selection logic | |
| --- | |
| ## π₯ Phase 4 | |
| ### Autonomous Intelligence | |
| * Self-improving agent | |
| * Task decomposition | |
| * Planning + execution loop | |
| --- | |
| # π§ Future Architecture (Target) | |
| ``` | |
| ββββββββββββββββ | |
| β USER UI β | |
| ββββββββ¬ββββββββ | |
| β | |
| ββββββββββββββββ | |
| β ROUTER β | |
| ββββββββ¬ββββββββ | |
| β | |
| ββββββββββββββββΌβββββββββββββββ | |
| β β β | |
| Code Agent Research Agent Image Agent | |
| β β β | |
| ββββββββ Executor Layer ββββββ | |
| β | |
| Execution Engine | |
| β | |
| Session Manager | |
| β | |
| HF Dataset Store | |
| ``` | |
| --- | |
| # π‘ Key Insight | |
| You are building: | |
| > β NOT just a chatbot | |
| > β BUT a **persistent AI system with memory, execution, and evolution** | |
| --- | |
| # π§ͺ Debugging Tips | |
| * Check logs: | |
| ``` | |
| /workspace/api.log | |
| ``` | |
| * Check session: | |
| ``` | |
| /workspace/hf/sessions/ | |
| ``` | |
| * Verify upload: | |
| * HF dataset repo | |
| --- | |
| # π Summary | |
| ## Current State: | |
| β Functional multi-agent system | |
| β Code execution working | |
| β Session persistence working | |
| β Needs stabilization | |
| --- | |
| ## Next Milestone: | |
| π **Multi-model intelligence layer** | |
| --- | |
| # π Final Thought | |
| Once stable, this system becomes: | |
| > π§ A self-building AI platform β not just an interface | |
| --- | |