Skip to content

Commit 349902b

Browse files
authored
feat: impl a metacognition layer && fix cli bugs. (#140)
Signed-off-by: wiseaidev <oss@wiseai.dev>
1 parent a6938aa commit 349902b

30 files changed

Lines changed: 1407 additions & 530 deletions

.github/workflows/check.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ jobs:
3131
"gpt",
3232
"co",
3333
"hf",
34+
"mta",
3435
"mcp",
36+
"mta,cli",
37+
"mta,gpt",
3538
"gpt,cli",
3639
"cli,mcp",
3740
"hf,mcp",

.github/workflows/clippy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ jobs:
3232
"gpt",
3333
"co",
3434
"hf",
35+
"mta",
3536
"mcp",
37+
"mta,cli",
38+
"mta,gpt",
3639
"gpt,cli",
3740
"cli,mcp",
3841
"hf,mcp",

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GenericGPT.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# 🤖 GenericGPT Interactive Mode
2+
3+
GenericGPT is a production-hardened autonomous software engineering agent with session persistence, model switching, and multi-provider support.
4+
5+
When you run `autogpt` with **no subcommand or flags**, it launches an interactive AI TUI powered by GenericGPT:
6+
7+
```sh
8+
autogpt
9+
```
10+
11+
<video src="https://github.com/user-attachments/assets/6aae0f5e-1137-4866-bc86-8a081ce067c4"></video>
12+
13+
The interactive shell supports the following commands:
14+
15+
| Command | Description |
16+
| --------------- | ------------------------------------------------------------------------ |
17+
| `<your prompt>` | Send a task to the GenericGPT autonomous agent |
18+
| `/help` | Show available commands |
19+
| `/provider` | Switch AI provider (Gemini, OpenAI, Anthropic, XAI, Cohere, HuggingFace) |
20+
| `/models` | Browse and switch between provider-native models |
21+
| `/sessions` | List and resume previous sessions |
22+
| `/status` | Show current model, provider, and directory |
23+
| `/workspace` | Show the current workspace path |
24+
| `/clear` | Clear the terminal |
25+
| `exit` / `quit` | Save session and quit |
26+
27+
> Press `ESC` at any time to interrupt a running generation.
28+
29+
## 🔀 Mixture of Providers (MoP)
30+
31+
AutoGPT introduces a high-availability **Mixture of Providers** architecture. When enabled via the `--mixture` or `-m` flag, every prompt is fanned out concurrently to all configured AI providers (Gemini, OpenAI, HuggingFace, etc.). A weighted scoring engine evaluates responses based on:
32+
33+
1. **Length calibration** (rewarding detail, penalizing fluff).
34+
1. **Code quality** (bonus for language-tagged Markdown blocks).
35+
1. **Structural richness** (headings, lists, hygiene).
36+
1. **Reasoning depth** (connectivity words and logical flow).
37+
1. **Completeness** (punctuation and closing delimiters).
38+
39+
The highest-scored response is selected as the winner and injected into the agent's context, promoting the best "intelligence" available from your configured keys.
40+
41+
## The `.autogpt` Directory
42+
43+
GenericGPT maintains all persistent state inside the workspace root (defaults to the **current directory**):
44+
45+
```sh
46+
.autogpt/
47+
├── sessions/ # Markdown conversation snapshots, auto-saved after every response
48+
│ ├── <uuid>.md
49+
│ └── ...
50+
└── skills/ # TOML lesson files, injected into future prompts automatically
51+
├── rust.toml
52+
├── web.toml
53+
└── python.toml
54+
```
55+
56+
Control the workspace root with `AUTOGPT_WORKSPACE`:
57+
58+
```sh
59+
export AUTOGPT_WORKSPACE=/my/project # scope all file ops to a specific directory
60+
autogpt
61+
```
62+
63+
## Model Selection
64+
65+
Models are sourced dynamically from each provider's crate. Override the active model without entering the shell:
66+
67+
```sh
68+
export GEMINI_MODEL=gemini-2.5-pro-preview-05-06
69+
export OPENAI_MODEL=gpt-4o
70+
export MODEL=<any-model-id> # global fallback for any provider
71+
```
72+
73+
## How GenericGPT Works
74+
75+
Each prompt travels through a multi-phase pipeline, with every phase reflected live in the terminal UI:
76+
77+
1. **Intent Detection**: The agent reads your message and decides whether it can answer directly, call a specific tool, or needs to plan and execute a full multi-step task.
78+
1. **Multi-Provider Fan-out**: When mixture mode is enabled, the prompt is sent to all configured AI providers simultaneously and the best response is selected.
79+
1. **Task Synthesis**: The agent breaks your goal down into a concrete, numbered list of actionable sub-tasks.
80+
1. **Implementation Plan**: A structured plan is generated and displayed, giving you a clear overview of what will be built before execution begins.
81+
1. **Reasoning**: Before tackling each sub-task, the agent thinks through its approach, anticipated risks, and the best execution strategy.
82+
1. **Execution**: The agent carries out the sub-task by performing file operations, running shell commands, searching the web, calling external tools, and more, atomically and in order.
83+
1. **Build & Verify**: If a buildable project is detected, the agent automatically compiles or runs it and attempts to self-correct any failures, retrying up to three times.
84+
1. **Reflection**: After completing each sub-task, the agent reviews its own output and decides whether to accept it, retry with corrections, or skip and move on.
85+
1. **Metacognition**: The agent tracks outcome patterns across tasks. When it detects repeated failures or inefficiencies, it recalibrates its strategy for the remaining work.
86+
1. **Skill Extraction**: At the end of a session, the agent distills domain-specific lessons from what worked and stores them for automatic reuse in future sessions on similar topics.
87+
88+
```mermaid
89+
flowchart TD
90+
A([autogpt CLI]) --> B{CLI args?}
91+
B -- none --> C["GenericGPT\nInteractive Shell"]
92+
B -- "-p / --prompt" --> DP["Direct LLM Prompt\n--mixture for fan-out"]
93+
B -- subcommand --> SA
94+
95+
subgraph SA ["Specialized Agent Roster"]
96+
direction LR
97+
ARCH[ArchitectGPT] --- BACK[BackendGPT] --- FRONT[FrontendGPT]
98+
DES[DesignerGPT] --- MGR[ManagerGPT] --- MAIL[MailerGPT]
99+
end
100+
101+
C --> PS["Provider & Model Setup\ngemini · openai · xai · anthropic · cohere · hf"]
102+
PS --> RL["Prompt REPL Loop\nESC → abort_token triggers abort"]
103+
104+
RL --> IC["classify_intent\nINTENT_DETECTION_PROMPT"]
105+
IC -- DirectAnswer --> SR["generate_safe\nstream reply to TUI"]
106+
IC -- ToolCall --> TE["MCP / built-in tool\nMcpCall action"]
107+
IC -- TaskPlan --> MOP
108+
SR --> RL
109+
TE --> RL
110+
111+
subgraph FTP ["Full Task Pipeline · GenericAgent · AgentGPT base class"]
112+
direction TB
113+
114+
MOP{"Mixture of\nProviders?"}
115+
MOP -- Yes --> MF["Fan-out across providers\nmerge best response"]
116+
MOP -- No --> SP["Single provider\ngenerate_tracked with token stats"]
117+
MF & SP --> WS["scan_workspace + walk_glob\nfile-tree snapshot injected as LLM context"]
118+
WS --> SL["SkillStore.load_for_domain\n.autogpt/skills/domain.toml injected"]
119+
SL --> SY["Phase: Synthesizing\nnumbered sub-task list"]
120+
SY --> PG["Phase: Planning\nmarkdown implementation plan"]
121+
PG --> AP{"Phase: AwaitingApproval\n--yolo to skip gate"}
122+
AP -- Abort --> ID([Phase: Idle])
123+
AP -- Approved --> EX
124+
125+
subgraph EL ["Execution Loop: one iteration per sub-task"]
126+
direction TB
127+
128+
EX["Phase: Executing n / N"]
129+
EX --> RS["Reasoning\nReasoningResult: thought · approach · risks"]
130+
RS --> AR["LLM emits ActionRequest JSON array"]
131+
132+
AR --> AD{Action type}
133+
AD -- "CreateFile / WriteFile\nPatchFile / AppendFile" --> FW[Filesystem writes]
134+
AD -- "ReadFile / ListDir\nFindInFile / GlobFiles" --> FR["Filesystem reads\nwalk_glob + pattern_matches"]
135+
AD -- RunCommand --> SH["Shell execution\ncwd + timeout"]
136+
AD -- GitCommit --> GC[git stage and commit]
137+
AD -- WebSearch --> WEB[DuckDuckGo search]
138+
AD -- McpCall --> MCP["MCP server tool\nstdio / SSE transport"]
139+
AD -- MultiPatch --> MPT[Atomic multi-patch]
140+
141+
FW & FR & SH & GC & WEB & MCP & MPT --> RC["ActionResult\nstdout · stderr · success"]
142+
143+
RC --> BV{"Build artifact\ndetected?"}
144+
BV -- "Cargo.toml / package.json / Makefile" --> TB["auto-build\nretry up to 3 · self-fix prompt on failure"]
145+
TB -- pass --> RF
146+
TB -- fail --> RS
147+
BV -- No --> RF
148+
149+
RF["Phase: Reflecting\nReflectionResult: outcome · corrective_actions"]
150+
RF -- Retry --> RS
151+
RF -- "Skip / Success" --> MC
152+
153+
MC{"mta feature\nenabled?"}
154+
MC -- No --> NT
155+
MC -- Yes --> MTE["Phase: MetaCognizing\nrecord_task_outcome → MetacognitionEntry\nshould_adjust_strategy?"]
156+
MTE -- ok --> NT
157+
MTE -- adjust --> MH["METACOGNITION_PROMPT\nstrategy hint injected for next task"]
158+
MH --> NT
159+
end
160+
161+
NT{"More sub-tasks?"}
162+
NT -- Yes --> EX
163+
NT -- No --> FU{"Follow-up tasks\nneeded?"}
164+
FU -- Yes --> SY
165+
FU -- No --> SE
166+
167+
SE["Skill Extraction\nextract_lessons → .autogpt/skills/domain.toml"]
168+
SE --> SS["Session walkthrough\n.autogpt/sessions/"]
169+
end
170+
171+
SS --> RL
172+
```

INSTALLATION.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ To install with specific features (e.g., MoP, Gemini, and MCP):
1818
cargo install autogpt --features "cli,gem,mop,mcp"
1919
```
2020

21+
To install with Agent Metacognition enabled:
22+
23+
```sh
24+
cargo install autogpt --features "cli,gem,mta"
25+
```
26+
27+
The `mta` (Meta-Thinking Agent) feature adds a self-evaluation phase to `GenericAgent`. After every task reflection, the agent records the outcome and, every 3 tasks or after 2+ consecutive failures, queries the LLM with a structured metacognition prompt to derive strategy adjustments for remaining tasks. The TUI status bar shows **MetaCognizing** during this phase.
28+
2129
### 🐳 Using Docker
2230

2331
To install and run the AutoGPT CLI via Docker, use the following command:

README.md

Lines changed: 5 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ AutoGPT is a pure rust framework that simplifies AI agent creation and managemen
4343

4444
## 🧠 Framework Overview
4545

46-
### ⚙️ Agent Core Architecture
47-
48-
AutoGPT agents are modular and autonomous, built from composable components:
46+
AutoGPT agents are modular, autonomous, and designed for flexibility:
4947

5048
- 🔌 **Tools & Sensors**: Interface with the real world via actions (e.g., file I/O, APIs) and perception (e.g., audio, video, data).
5149
- 🧠 **Memory & Knowledge**: Combines long-term vector memory with structured knowledge bases for reasoning and recall.
@@ -55,16 +53,10 @@ AutoGPT agents are modular and autonomous, built from composable components:
5553
- 🧑‍🤝‍🧑 **Collaboration**: Agents can delegate, swarm, or work in teams with other agents.
5654
- 🪞 **Self-Reflection**: Introspection module to debug, adapt, or evolve internal strategies.
5755
- 🔄 **Context Management**: Manages active memory (context window) for ongoing tasks and conversations.
58-
- 🔌 **MCP (Model Context Protocol)**: Seamlessly connect to external tool servers (Stdio, SSE, HTTP) to extend agent capabilities with thousands of existing tools.
56+
- 🔌 **MCP (Model Context Protocol)**: First-class support to seamlessly connect external tool servers (Stdio, SSE, HTTP) to extend capabilities.
5957
- 📅 **Scheduler**: Time-based or reactive triggers for agent actions.
60-
61-
### 🚀 Developer Features
62-
63-
AutoGPT is designed for flexibility, integration, and scalability:
64-
6558
- 🧪 **Custom Agent Creation**: Build tailored agents for different roles or domains.
6659
- 📋 **Task Orchestration**: Manage and distribute tasks across agents efficiently.
67-
- 🔌 **MCP Integration**: First-class support for the Model Context Protocol to unify tool access.
6860
- 🧱 **Extensibility**: Add new tools, behaviors, or agent types with ease.
6961
- 💻 **CLI Tools**: Command-line interface for rapid experimentation and control.
7062
- 🧰 **SDK Support**: Embed AutoGPT into existing projects or systems seamlessly.
@@ -83,121 +75,16 @@ AutoGPT supports 4 modes of operation: interactive, direct prompt, standalone ag
8375

8476
### 0. 🤖 GenericGPT Interactive Mode (Default)
8577

86-
When you run `autogpt` with **no subcommand or flags**, it launches an interactive AI TUI powered by **GenericGPT**, a production-hardened autonomous software engineering agent with session persistence, model switching, and multi-provider support:
78+
When you run `autogpt` with **no subcommand or flags**, it launches an interactive AI TUI powered by **GenericGPT**, a production-hardened autonomous software engineering agent. GenericGPT features intent detection, a complete seven-step reasoning and execution pipeline, automatic build-and-verify loops, and metacognition for learning across tasks.
8779

8880
```sh
8981
autogpt
9082
```
9183

9284
<video src="https://github.com/user-attachments/assets/6aae0f5e-1137-4866-bc86-8a081ce067c4"></video>
9385

94-
The interactive shell supports the following commands:
95-
96-
| Command | Description |
97-
| --------------- | ------------------------------------------------------------------------ |
98-
| `<your prompt>` | Send a task to the GenericGPT autonomous agent |
99-
| `/help` | Show available commands |
100-
| `/provider` | Switch AI provider (Gemini, OpenAI, Anthropic, XAI, Cohere, HuggingFace) |
101-
| `/models` | Browse and switch between provider-native models |
102-
| `/sessions` | List and resume previous sessions |
103-
| `/status` | Show current model, provider, and directory |
104-
| `/workspace` | Show the current workspace path |
105-
| `/clear` | Clear the terminal |
106-
| `exit` / `quit` | Save session and quit |
107-
108-
> Press `ESC` at any time to interrupt a running generation.
109-
110-
### 🔀 Mixture of Providers (MoP)
111-
112-
AutoGPT introduces a high-availability **Mixture of Providers** architecture. When enabled via the `--mixture` or `-m` flag, every prompt is fanned out concurrently to all configured AI providers (Gemini, OpenAI, HuggingFace, etc.). A weighted scoring engine evaluates responses based on:
113-
114-
1. **Length calibration** (rewarding detail, penalizing fluff).
115-
1. **Code quality** (bonus for language-tagged Markdown blocks).
116-
1. **Structural richness** (headings, lists, hygiene).
117-
1. **Reasoning depth** (connectivity words and logical flow).
118-
1. **Completeness** (punctuation and closing delimiters).
119-
120-
The highest-scored response is selected as the winner and injected into the agent's context, promoting the best "intelligence" available from your configured keys.
121-
122-
### The `.autogpt` Directory
123-
124-
GenericGPT maintains all persistent state inside the workspace root (defaults to the **current directory**):
125-
126-
```sh
127-
.autogpt/
128-
├── sessions/ # Markdown conversation snapshots, auto-saved after every response
129-
│ ├── <uuid>.md
130-
│ └── ...
131-
└── skills/ # TOML lesson files, injected into future prompts automatically
132-
├── rust.toml
133-
├── web.toml
134-
└── python.toml
135-
```
136-
137-
Control the workspace root with `AUTOGPT_WORKSPACE`:
138-
139-
```sh
140-
export AUTOGPT_WORKSPACE=/my/project # scope all file ops to a specific directory
141-
autogpt
142-
```
143-
144-
### Model Selection
145-
146-
Models are sourced dynamically from each provider's crate. Override the active model without entering the shell:
147-
148-
```sh
149-
export GEMINI_MODEL=gemini-2.5-pro-preview-05-06
150-
export OPENAI_MODEL=gpt-4o
151-
export MODEL=<any-model-id> # global fallback for any provider
152-
```
153-
154-
### How GenericGPT Works
155-
156-
Each prompt goes through a seven-step pipeline:
157-
158-
1. **MoP Fan-out** (optional): Parallel execution across multiple providers.
159-
1. **Reasoning**: structured internal monologue stored in the session log.
160-
1. **Task synthesis**: decomposition into typed actions (`CreateFile`, `PatchFile`, `RunCommand`, ...).
161-
1. **Execution**: file edits via `PatchFile`; shell execution via `RunCommand`.
162-
1. **Build-and-verify**: auto-detects `Cargo.toml` / `package.json` / `Makefile` and runs the build; retries on failure up to 3 times.
163-
1. **Reflection**: reviews outcomes and lesson candidates.
164-
1. **Skill extraction**: lessons written to `.autogpt/skills/<domain>.toml` and injected in future sessions.
165-
166-
```mermaid
167-
flowchart TD
168-
A([User enters prompt]) --> B{Mixture mode?}
169-
B -- Yes --> C[Run Mixture of Providers]
170-
B -- No --> D[Standard Provider]
171-
C & D --> E[Reasoning pre-step]
172-
E --> F[Task synthesis]
173-
F --> G{User approves?}
174-
G -- yolo mode / yes --> H[Execute actions]
175-
H --> I[Build-and-verify loop]
176-
I -- pass --> J[Reflection]
177-
I -- fail, retry ≤3 --> H
178-
J --> K[Save skills & session]
179-
K --> L([Ready for next prompt])
180-
```
181-
182-
```mermaid
183-
flowchart TD
184-
A([User launches autogpt]) --> B{Any args?}
185-
B -- No --> C[GenericGPT Interactive Shell]
186-
B -- Yes --> D{Subcommand}
187-
C --> E[Select Provider & Model]
188-
E --> F[Enter Prompt Loop]
189-
F --> G{Mixture enabled?}
190-
G -- Yes --> H[Mixture of Providers]
191-
G -- No --> I[Standard Prompt]
192-
H & I --> J[Agent Generates Response]
193-
J --> F
194-
D -- arch --> K[ArchitectGPT]
195-
D -- back --> L[BackendGPT]
196-
D -- front --> M[FrontendGPT]
197-
D -- design --> N[DesignerGPT]
198-
D -- manage --> O[ManagerGPT]
199-
D -- -p prompt --> P[Direct LLM Prompt]
200-
```
86+
> [!NOTE]
87+
> For an in-depth breakdown of how GenericGPT works under the hood, including its architecture, interactive shell, Mixture of Providers (MoP), and execution pipeline, see the [GenericGPT Documentation](GenericGPT.md).
20188
20289
### 1. 💬 Direct Prompt Mode
20390

autogpt/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ tui-input = { version = "0.15.3", optional = true }
7373
strum = { version = "0.28", features = ["derive"], optional = true }
7474
strum_macros = { version = "0.28", optional = true }
7575
bytes = "1.11.1"
76+
unicode-width = { version = "0.2.2", optional = true }
7677

7778
[features]
7879
default = []
@@ -107,10 +108,12 @@ cli = [
107108
"strum_macros",
108109
"convert_case",
109110
"crates_io_api",
111+
"unicode-width",
110112
"tracing-appender",
111113
"tracing-subscriber",
112114
]
113115
mcp = ["dirs"]
116+
mta = []
114117

115118
[package.metadata.docs.rs]
116119
all-features = true

0 commit comments

Comments
 (0)