Skip to content

Commit e8097d6

Browse files
authored
feat: impl llms collab && add new examples && update docs. (#141)
Signed-off-by: wiseaidev <oss@wiseai.dev>
1 parent 0c57d21 commit e8097d6

33 files changed

Lines changed: 7770 additions & 84 deletions

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.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ iac-rs = { version = "0.0.8", path = "./iac-rs" }
2525
chrono = "0.4.41"
2626
derivative = "2.2.0"
2727
duckduckgo = "0.3.1"
28+
phf = { version = "0.13.1", features = ["macros"] }
2829

2930
[profile.release]
3031
opt-level = "z"

INSTALLATION.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,82 @@ async fn main() {
342342
}
343343
```
344344

345+
#### 🤝 Collaborative Multi-Provider Agent (SDK: `col` feature)
346+
347+
Attach a [`CollabPool`] to `AutoGPT` so the orchestrator executes agents
348+
sequentially in round-robin provider order. Each entry in `agents![...]`
349+
corresponds to one entry in the pool's provider list.
350+
351+
```rust
352+
use autogpt::prelude::*;
353+
354+
#[tokio::main]
355+
async fn main() {
356+
let persona = "Lead Architect";
357+
let behavior = "Design a microservices architecture for an e-commerce platform.";
358+
359+
let pool = CollabPool::from_providers(vec![
360+
"gemini".to_string(),
361+
"openai".to_string(),
362+
]);
363+
364+
let agent_a = ArchitectGPT::new(persona, behavior).await;
365+
let agent_b = ArchitectGPT::new(persona, behavior).await;
366+
367+
let autogpt = AutoGPT::default()
368+
.with(agents![agent_a, agent_b])
369+
.with_collab_pool(pool)
370+
.build()
371+
.expect("Failed to build AutoGPT");
372+
373+
match autogpt.run().await {
374+
Ok(response) => println!("{}", response),
375+
Err(err) => eprintln!("Agent error: {:?}", err),
376+
}
377+
}
378+
```
379+
380+
> [!NOTE]
381+
> **How it works**: `AutoGPT::run()` picks a random starting provider via
382+
> [`CollabSelection::Random`], then executes each agent in the `agents![...]`
383+
> list sequentially mapped to pool providers in round-robin order.
384+
> Enable `CollabSelection::Explicit(name)` to always start from a specific
385+
> provider.
386+
387+
#### 🧠 Agent Metacognition SDK (`mta` feature)
388+
389+
The `mta` feature embeds a [`MetacognitionEngine`] inside every [`AgentGPT`]
390+
that records task outcomes and injects strategy context into prompts.
391+
392+
```rust
393+
use autogpt::prelude::*;
394+
395+
#[tokio::main]
396+
async fn main() {
397+
let persona = "Research Analyst";
398+
let behavior = "Summarise research papers.";
399+
400+
let mut agent = AgentGPT::new_borrowed(persona, behavior);
401+
402+
agent.record_task_outcome("parse pdf", "success", 0);
403+
agent.record_task_outcome("extract sections", "failed", 2);
404+
405+
println!("{}", agent.metacognition_context());
406+
println!("Should adjust? {}", agent.should_adjust_strategy());
407+
}
408+
```
409+
410+
| Method | Description |
411+
| --------------------------------------------- | --------------------------------------------------- |
412+
| `record_task_outcome(task, outcome, retries)` | Record a task result and generate an insight entry |
413+
| `metacognition_context()` | Returns the LLM-injectable strategy context string |
414+
| `should_adjust_strategy()` | `true` when the engine recommends a strategy change |
415+
| `consecutive_failures()` | Number of consecutive failing tasks |
416+
417+
The engine triggers automatically inside `GenericAgent` every 3 tasks or
418+
after 2+ consecutive failures, querying the LLM to produce strategy
419+
adjustments. The TUI status bar shows **MetaCognizing** during this phase.
420+
345421
## 🛠️ CLI Usage
346422

347423
The CLI provides a convenient means to interact with the code generation ecosystem. The `autogpt` crate bundles two binaries in a single package:
@@ -501,6 +577,35 @@ This opens a conversational AI shell where you can:
501577
- Press `ESC` to interrupt a running generation.
502578
- Type `exit` or `quit` to save the session and close.
503579

580+
#### 🤝 Collaborative Multi-Provider Mode (`--collab`, requires `col + cli`)
581+
582+
Collab mode spawns one `GenericAgent` per configured provider (all providers
583+
with an API key set in the environment) and distributes the task across them
584+
in round-robin order with per-model fallback:
585+
586+
```sh
587+
# Build with collab support:
588+
cargo run --features "cli,col,gem,oai,xai" --bin autogpt -- --collab
589+
590+
# Or install:
591+
cargo install autogpt --features "cli,col,gem,oai"
592+
autogpt --collab
593+
```
594+
595+
**Provider discovery**: Any provider feature compiled in whose API key env var
596+
is set at runtime is automatically added to the pool (e.g. `GEMINI_API_KEY`,
597+
`OPENAI_API_KEY`, `XAI_API_KEY`).
598+
599+
**Fallback behaviour**:
600+
601+
| Event | Action |
602+
| --------------------------------- | --------------------------------------------- |
603+
| Rate-limit / quota error | Rotate to next model within the same provider |
604+
| All models for provider exhausted | Remove provider from pool, route to next |
605+
| All providers exhausted | Log `⚠ All collab providers exhausted.` |
606+
607+
The TUI logs the active pool and each routing step with `🤝`/`🔀` prefixes.
608+
504609
#### ⚡ Direct Prompt Mode
505610

506611
For a quick one-shot non-interactive prompt:

autogpt/Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ auto-derive = { workspace = true }
3737
chrono = { workspace = true }
3838
derivative = { workspace = true }
3939
duckduckgo = { workspace = true }
40+
phf = { workspace = true }
4041
iac-rs = { workspace = true, optional = true }
4142

4243
uuid = { version = "=1.23.1", features = ["v4"] }
@@ -79,17 +80,20 @@ unicode-width = { version = "0.2.2", optional = true }
7980
default = []
8081
gpt = []
8182
mop = []
82-
img = ["getimg"]
83+
mta = []
84+
col = []
85+
mcp = ["dirs"]
8386
git = ["git2"]
8487
gem = ["gems"]
8588
xai = ["x-ai"]
8689
net = ["iac-rs"]
90+
img = ["getimg"]
8791
mail = ["nylas"]
92+
co = ["cohere-rust"]
8893
oai = ["openai_dive"]
8994
mem = ["pinecone-sdk"]
90-
cld = ["anthropic-ai-sdk"]
91-
co = ["cohere-rust"]
9295
hf = ["api_huggingface"]
96+
cld = ["anthropic-ai-sdk"]
9397
cli = [
9498
"clap",
9599
"dirs",
@@ -112,8 +116,6 @@ cli = [
112116
"tracing-appender",
113117
"tracing-subscriber",
114118
]
115-
mcp = ["dirs"]
116-
mta = []
117119

118120
[package.metadata.docs.rs]
119121
all-features = true

autogpt/INSTALLATION.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,82 @@ async fn main() {
342342
}
343343
```
344344

345+
#### 🤝 Collaborative Multi-Provider Agent (SDK: `col` feature)
346+
347+
Attach a [`CollabPool`] to `AutoGPT` so the orchestrator executes agents
348+
sequentially in round-robin provider order. Each entry in `agents![...]`
349+
corresponds to one entry in the pool's provider list.
350+
351+
```rust
352+
use autogpt::prelude::*;
353+
354+
#[tokio::main]
355+
async fn main() {
356+
let persona = "Lead Architect";
357+
let behavior = "Design a microservices architecture for an e-commerce platform.";
358+
359+
let pool = CollabPool::from_providers(vec![
360+
"gemini".to_string(),
361+
"openai".to_string(),
362+
]);
363+
364+
let agent_a = ArchitectGPT::new(persona, behavior).await;
365+
let agent_b = ArchitectGPT::new(persona, behavior).await;
366+
367+
let autogpt = AutoGPT::default()
368+
.with(agents![agent_a, agent_b])
369+
.with_collab_pool(pool)
370+
.build()
371+
.expect("Failed to build AutoGPT");
372+
373+
match autogpt.run().await {
374+
Ok(response) => println!("{}", response),
375+
Err(err) => eprintln!("Agent error: {:?}", err),
376+
}
377+
}
378+
```
379+
380+
> [!NOTE]
381+
> **How it works**: `AutoGPT::run()` picks a random starting provider via
382+
> [`CollabSelection::Random`], then executes each agent in the `agents![...]`
383+
> list sequentially mapped to pool providers in round-robin order.
384+
> Enable `CollabSelection::Explicit(name)` to always start from a specific
385+
> provider.
386+
387+
#### 🧠 Agent Metacognition SDK (`mta` feature)
388+
389+
The `mta` feature embeds a [`MetacognitionEngine`] inside every [`AgentGPT`]
390+
that records task outcomes and injects strategy context into prompts.
391+
392+
```rust
393+
use autogpt::prelude::*;
394+
395+
#[tokio::main]
396+
async fn main() {
397+
let persona = "Research Analyst";
398+
let behavior = "Summarise research papers.";
399+
400+
let mut agent = AgentGPT::new_borrowed(persona, behavior);
401+
402+
agent.record_task_outcome("parse pdf", "success", 0);
403+
agent.record_task_outcome("extract sections", "failed", 2);
404+
405+
println!("{}", agent.metacognition_context());
406+
println!("Should adjust? {}", agent.should_adjust_strategy());
407+
}
408+
```
409+
410+
| Method | Description |
411+
| --------------------------------------------- | --------------------------------------------------- |
412+
| `record_task_outcome(task, outcome, retries)` | Record a task result and generate an insight entry |
413+
| `metacognition_context()` | Returns the LLM-injectable strategy context string |
414+
| `should_adjust_strategy()` | `true` when the engine recommends a strategy change |
415+
| `consecutive_failures()` | Number of consecutive failing tasks |
416+
417+
The engine triggers automatically inside `GenericAgent` every 3 tasks or
418+
after 2+ consecutive failures, querying the LLM to produce strategy
419+
adjustments. The TUI status bar shows **MetaCognizing** during this phase.
420+
345421
## 🛠️ CLI Usage
346422

347423
The CLI provides a convenient means to interact with the code generation ecosystem. The `autogpt` crate bundles two binaries in a single package:
@@ -501,6 +577,35 @@ This opens a conversational AI shell where you can:
501577
- Press `ESC` to interrupt a running generation.
502578
- Type `exit` or `quit` to save the session and close.
503579

580+
#### 🤝 Collaborative Multi-Provider Mode (`--collab`, requires `col + cli`)
581+
582+
Collab mode spawns one `GenericAgent` per configured provider (all providers
583+
with an API key set in the environment) and distributes the task across them
584+
in round-robin order with per-model fallback:
585+
586+
```sh
587+
# Build with collab support:
588+
cargo run --features "cli,col,gem,oai,xai" --bin autogpt -- --collab
589+
590+
# Or install:
591+
cargo install autogpt --features "cli,col,gem,oai"
592+
autogpt --collab
593+
```
594+
595+
**Provider discovery**: Any provider feature compiled in whose API key env var
596+
is set at runtime is automatically added to the pool (e.g. `GEMINI_API_KEY`,
597+
`OPENAI_API_KEY`, `XAI_API_KEY`).
598+
599+
**Fallback behaviour**:
600+
601+
| Event | Action |
602+
| --------------------------------- | --------------------------------------------- |
603+
| Rate-limit / quota error | Rotate to next model within the same provider |
604+
| All models for provider exhausted | Remove provider from pool, route to next |
605+
| All providers exhausted | Log `⚠ All collab providers exhausted.` |
606+
607+
The TUI logs the active pool and each routing step with `🤝`/`🔀` prefixes.
608+
504609
#### ⚡ Direct Prompt Mode
505610

506611
For a quick one-shot non-interactive prompt:

autogpt/src/agents.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub mod agent;
1515
pub mod architect;
1616
#[cfg(feature = "gpt")]
1717
pub mod backend;
18+
#[cfg(feature = "col")]
19+
pub mod collab;
1820
#[cfg(feature = "gpt")]
1921
pub mod designer;
2022
#[cfg(feature = "gpt")]

0 commit comments

Comments
 (0)