@@ -148,83 +148,113 @@ uuid = { version = "1", features = ["v4"] } # Session IDs
148148
149149## 4. API Design
150150
151- ### 4.1 Simple API (User-Facing)
151+ > ** Philosophy** : Match Python SDK's simplicity — the simplest use case should be the shortest code.
152+
153+ ### 4.1 One-Liner (Simplest)
154+
155+ ``` rust
156+ use praisonai :: Agent ;
157+
158+ // Equivalent to Python: Agent(instructions="Be helpful")
159+ let agent = Agent :: simple (" Be helpful" )? ;
160+ let response = agent . chat (" Hello!" ). await ? ;
161+ ```
162+
163+ ### 4.2 Builder Pattern (More Control)
152164
153165``` rust
154- // Basic usage - 5 lines
155166use praisonai :: Agent ;
156167
157168let agent = Agent :: new ()
158- . instructions (" Be helpful" )
169+ . name (" assistant" )
170+ . instructions (" You are a helpful AI assistant" )
159171 . build ()? ;
160172
161- let response = agent . chat (" Hello!" ). await ? ;
173+ let response = agent . chat (" What is 2+2?" ). await ? ;
174+ // Also available: agent.start() and agent.run() as aliases
162175```
163176
164- ### 4.2 With Tools
177+ ### 4.3 With Tools
165178
166179``` rust
167180use praisonai :: {Agent , tool};
168181
169- #[tool(description = " Search the web for information " )]
182+ #[tool(description = " Search the web" )]
170183async fn search (query : String ) -> String {
171184 format! (" Results for: {}" , query )
172185}
173186
174187let agent = Agent :: new ()
175- . name (" researcher" )
176- . instructions (" Use tools to help users" )
188+ . instructions (" Use search to help users" )
177189 . tool (search )
178190 . build ()? ;
191+
192+ let response = agent . chat (" Find info about Rust" ). await ? ;
179193```
180194
181- ### 4.3 Multi-Agent Workflows
195+ ### 4.4 Multi-Agent Team
182196
183197``` rust
184198use praisonai :: {Agent , AgentTeam , Process };
185199
186- let researcher = Agent :: new (). name (" researcher" ). build ()? ;
187- let writer = Agent :: new (). name (" writer" ). build ()? ;
188- let editor = Agent :: new (). name (" editor" ). build ()? ;
200+ // Build team with builder pattern
201+ let team = AgentTeam :: new ()
202+ . agent (Agent :: simple (" Research topics thoroughly" )? )
203+ . agent (Agent :: simple (" Write engaging content" )? )
204+ . agent (Agent :: simple (" Edit for clarity" )? )
205+ . process (Process :: Sequential ) // or Parallel, Hierarchical
206+ . build ();
189207
190- let team = AgentTeam :: builder ()
191- . agents (vec! [researcher , writer , editor ])
192- . process (Process :: Sequential )
193- . build ()? ;
194-
195- let result = team . start (" Write an article about AI" ). await ? ;
208+ let result = team . start (" Write about AI safety" ). await ? ;
196209```
197210
198- ### 4.4 Workflow Patterns (AgentFlow)
211+ ### 4.5 Workflow Patterns (AgentFlow)
199212
200213``` rust
201- use praisonai :: {AgentFlow , Pattern };
202-
203- // Route to different agents based on input
204- let flow = AgentFlow :: builder ()
205- . pattern (Pattern :: Route {
206- router : my_router_fn ,
207- routes : vec! [research_agent , write_agent ],
208- })
209- . build ()? ;
214+ use praisonai :: {Agent , AgentFlow , FlowStep , Route , Parallel , Repeat };
215+ use std :: sync :: Arc ;
216+
217+ let agent = Arc :: new (Agent :: simple (" Be helpful" )? );
218+
219+ // Simple agent step
220+ let flow = AgentFlow :: new ()
221+ . agent (Agent :: simple (" Process the input" )? )
222+ . run (" Hello" ). await ? ;
223+
224+ // Route based on condition
225+ let flow = AgentFlow :: new ()
226+ . step (FlowStep :: Route (Route {
227+ condition : Box :: new (| input | input . contains (" urgent" )),
228+ if_true : Arc :: clone (& agent ),
229+ if_false : None ,
230+ }));
210231
211232// Parallel execution
212- let flow = AgentFlow :: builder ()
213- . pattern ( Pattern :: Parallel {
233+ let flow = AgentFlow :: new ()
234+ . step ( FlowStep :: Parallel ( Parallel {
214235 agents : vec! [agent1 , agent2 , agent3 ],
215- })
216- . build ()? ;
236+ }));
217237
218- // Loop until condition
219- let flow = AgentFlow :: builder ()
220- . pattern ( Pattern :: Loop {
221- agent : refiner_agent ,
222- condition : | result | result . score < 0.9 ,
223- max_iterations : 5 ,
224- })
225- . build () ? ;
238+ // Repeat N times
239+ let flow = AgentFlow :: new ()
240+ . step ( FlowStep :: Repeat ( Repeat {
241+ agent : Arc :: clone ( & agent ) ,
242+ times : 3 ,
243+ }));
244+
245+ let result = flow . run ( " Input prompt " ) . await ? ;
226246```
227247
248+ ### 4.6 Progressive Disclosure Summary
249+
250+ | Level | Code | Use Case |
251+ | -------| ------| ----------|
252+ | ** Simplest** | ` Agent::simple("instructions")? ` | Quick prototyping |
253+ | ** Basic** | ` Agent::new().instructions(...).build()? ` | Most apps |
254+ | ** With Tools** | ` Agent::new()...tool(fn).build()? ` | Tool-using agents |
255+ | ** Team** | ` AgentTeam::new().agent(...).build() ` | Multi-agent |
256+ | ** Flows** | ` AgentFlow::new().step(...) ` | Complex patterns |
257+
228258---
229259
230260## 5. CLI Usage
0 commit comments