1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! # Automaton
//!
//! Zebflow's autonomous agent infrastructure. An independent module with no
//! platform or pipeline dependencies — usable as a standalone library.
//!
//! Zebtune is the runtime instance: a goal-directed agent that can plan,
//! use tools, validate progress, replan, and synthesize answers.
//! Target capability: on par with Perplexity, Claude Code, or Cursor.
//!
//! ---
//!
//! ## Architecture: 5-Layer Model
//!
//! ```text
//! ┌──────────────────────────────────────────────────────────────┐
//! │ AGENTS reasoning — how the automaton thinks │
//! │ ├── zebtune full autonomous: plan→act→validate→replan │
//! │ └── tool_caller single-pass structured tool sequence │
//! ├──────────────────────────────────────────────────────────────┤
//! │ PLANNING first-class goal decomposition layer │
//! │ └── basic/ HierarchicalPlan, SubGoal, ValidationResult│
//! ├──────────────────────────────────────────────────────────────┤
//! │ MEMORY first-class context retention layer │
//! │ └── basic/ ConversationHistory, TokenUsage │
//! ├──────────────────────────────────────────────────────────────┤
//! │ INTELLIGENCE AI-native capabilities (not LLM reasoning) │
//! │ └── (planned: tts, stt, ocr, vectorize, classify, regress) │
//! ├──────────────────────────────────────────────────────────────┤
//! │ INFRA plumbing: LLM clients, REPL, shell tools │
//! │ ├── llm_interface LlmCall — single LLM interface (call + call_with_tools) │
//! │ ├── http_client OpenAiHttpClient + AnthropicClient + factories │
//! │ ├── llm.rs re-exports factories (backward-compat module path) │
//! │ ├── model.rs AutomatonContext, Objective, Plan, Error │
//! │ ├── shell_tools ToolRegistry: ls, pwd, python │
//! │ └── repl.rs interactive REPL mode │
//! └──────────────────────────────────────────────────────────────┘
//! ```
//!
//! ---
//!
//! ## Two Agents
//!
//! ### [`agents::zebtune::ZebtuneAgent`] — Full Autonomous Agent
//!
//! Goal → strategic plan → execution loop → validation → replanning → synthesis.
//!
//! ```text
//! Phase 1: Strategic Planning [TODO M6]
//! LLM decomposes goal → HierarchicalPlan (subgoals + validation criteria)
//!
//! Phase 2: Execution Loop
//! LLM turn → detect tool request → execute → feed result back → repeat
//! TODO M7: upgrade from text-parsing (RUN:) to native function calling
//!
//! Phase 3: Validation [TODO M6]
//! LLM checks if subgoal criteria met → pass/fail with confidence score
//!
//! Phase 4: Adaptive Replanning [TODO M6]
//! On failure: LLM generates alternative plan for the failed subgoal
//!
//! Phase 5: Synthesis
//! Final answer assembled from chain + execution trace
//! ```
//!
//! Exposed as pipeline node `n.ai.agent.zebtune`.
//!
//! ### [`agents::tool_caller::ToolCallerAgent`] — Simple Tool Sequence Agent
//!
//! Goal + tool definitions → LLM native function calling → execute sequence → answer.
//!
//! ```text
//! - No strategic planning phase
//! - Uses OpenAI tools API (structured function calls, not text parsing)
//! - Suitable for deterministic task completion with known tools upfront
//! ```
//!
//! Exposed as pipeline node `n.ai.agent.tool_caller`.
//!
//! ---
//!
//! ## Infrastructure Note
//!
//! `llm.rs` is a thin re-export facade for `http_client` factory functions — NOT an agent.
//! `llm_interface.rs` defines `LlmCall` — the single LLM interface used by all agents.
//!
//! ---
//!
//! ## Milestone Roadmap
//!
//! | Milestone | Focus |
//! |-----------|-------|
//! | M6 | Strategic planning: goal decomposition, validation, replanning |
//! | M7 | Native function calling: replace RUN: text parsing in ZebtuneAgent ✅ DONE |
//! | M7 | Tool expansion: file ops, shell allowlist, web fetch, git, code |
//! | M8 | Memory: graph/, vector/, episodic/, semantic/ backends |
//! | M9 | Config: security policy, deployment profiles, user prefs |
//! | M10 | Cost optimization: model routing, batching, context management |
//!
//! ---
//!
//! ## Security Model
//!
//! Allowlist-only. No tool runs without explicit registration.
//! Shell: allowlisted commands only (no `rm -rf`, `dd`, etc.).
//! Web: domain allowlist.
//! Step budget: hard cap on LLM+tool iterations per run.
// ── Public API re-exports ────────────────────────────────────────────────────
// Core types (used by lib.rs, bin/zebtune.rs, platform)
pub use AutomatonEngine;
pub use ;
pub use AutomatonEngineRegistry;
// REPL utilities (used by bin/zebtune.rs)
pub use ;
// Shell tool registry (used by zebtune pipeline node)
pub use ;
// Engine implementations
pub use NoopAutomatonEngine;
// Agents
pub use ToolCallerAgent;
pub use ZebtuneAgent;
// Re-export llm module so `zebflow::automaton::llm::client_from_env()` keeps working
pub use llm;