rcrewai 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/api/agent.md +429 -0
- data/docs/api/task.md +494 -0
- data/docs/examples/api-integration.md +829 -0
- data/docs/examples/async-execution.md +893 -0
- data/docs/examples/code-review-crew.md +660 -0
- data/docs/examples/content-marketing-pipeline.md +681 -0
- data/docs/examples/custom-tools.md +1224 -0
- data/docs/examples/customer-support.md +717 -0
- data/docs/examples/data-analysis-team.md +677 -0
- data/docs/examples/database-operations.md +1298 -0
- data/docs/examples/ecommerce-operations.md +990 -0
- data/docs/examples/financial-analysis.md +857 -0
- data/docs/examples/hierarchical-crew.md +479 -0
- data/docs/examples/product-development.md +688 -0
- data/docs/examples/production-ready-crew.md +384 -408
- data/docs/examples/research-development.md +1225 -0
- data/docs/examples/social-media.md +1073 -0
- data/docs/examples/task-automation.md +527 -0
- data/docs/examples/tool-composition.md +1075 -0
- data/docs/examples/web-scraping.md +1201 -0
- data/docs/tutorials/advanced-agents.md +1014 -0
- data/docs/tutorials/custom-tools.md +1242 -0
- data/docs/tutorials/deployment.md +1836 -0
- data/docs/tutorials/index.md +184 -0
- data/docs/tutorials/multiple-crews.md +1692 -0
- data/lib/rcrewai/llm_clients/anthropic.rb +1 -1
- data/lib/rcrewai/version.rb +1 -1
- metadata +26 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 729f55dac5596c9689bf3f1aa6266b95e3e04b249342b739d6d43280aeec9b3c
|
4
|
+
data.tar.gz: ce70bdae47acd61d18df887b43509f5ebe9ab58da26ea67b1367d23feaf16544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97cf0e1a33a584e384638d35e611c97ab4a14b521c5f68a4d6aa7e072c5e6fb6045076201f9e5eec1afceada7215ad0012faa2839afd5eca1f0da0b2ceb164b9
|
7
|
+
data.tar.gz: 2baae70e08e89475904442a76407126a73580902897a4ddb3ec6186b1d85494410640c42a187bfde18a0a4faa2efdf4c628ee3298284051eda846b57533cde92
|
data/docs/api/agent.md
ADDED
@@ -0,0 +1,429 @@
|
|
1
|
+
---
|
2
|
+
layout: api
|
3
|
+
title: RCrewAI::Agent
|
4
|
+
description: API documentation for the Agent class
|
5
|
+
---
|
6
|
+
|
7
|
+
# RCrewAI::Agent
|
8
|
+
|
9
|
+
The Agent class represents an individual AI agent with specific roles, capabilities, and tools. Agents are the core workers in RCrewAI that execute tasks using reasoning loops and specialized tools.
|
10
|
+
|
11
|
+
## Constructor
|
12
|
+
|
13
|
+
### `new(name:, role:, goal:, **options)`
|
14
|
+
|
15
|
+
Creates a new agent instance.
|
16
|
+
|
17
|
+
**Parameters:**
|
18
|
+
- `name` (String, required) - Unique identifier for the agent
|
19
|
+
- `role` (String, required) - The agent's role (e.g., "Research Analyst", "Content Writer")
|
20
|
+
- `goal` (String, required) - The agent's primary objective
|
21
|
+
- `backstory` (String, optional) - Background context that influences behavior
|
22
|
+
- `tools` (Array, optional) - Array of tool instances available to the agent
|
23
|
+
- `verbose` (Boolean, optional) - Enable detailed logging (default: false)
|
24
|
+
- `allow_delegation` (Boolean, optional) - Allow agent to delegate tasks (default: false)
|
25
|
+
- `manager` (Boolean, optional) - Designate as manager agent (default: false)
|
26
|
+
- `max_iterations` (Integer, optional) - Maximum reasoning iterations (default: 10)
|
27
|
+
- `max_execution_time` (Integer, optional) - Maximum execution time in seconds (default: 300)
|
28
|
+
- `human_input` (Boolean, optional) - Enable human-in-the-loop interactions (default: false)
|
29
|
+
- `require_approval_for_tools` (Boolean, optional) - Require human approval for tool usage
|
30
|
+
- `require_approval_for_final_answer` (Boolean, optional) - Require human approval for final results
|
31
|
+
|
32
|
+
**Returns:** `RCrewAI::Agent` instance
|
33
|
+
|
34
|
+
**Example:**
|
35
|
+
```ruby
|
36
|
+
agent = RCrewAI::Agent.new(
|
37
|
+
name: "research_specialist",
|
38
|
+
role: "Senior Research Analyst",
|
39
|
+
goal: "Uncover cutting-edge developments in AI and technology",
|
40
|
+
backstory: "You work at a leading tech think tank with 10+ years experience in emerging technology analysis.",
|
41
|
+
tools: [RCrewAI::Tools::WebSearch.new, RCrewAI::Tools::FileWriter.new],
|
42
|
+
verbose: true,
|
43
|
+
max_iterations: 15,
|
44
|
+
max_execution_time: 600
|
45
|
+
)
|
46
|
+
```
|
47
|
+
|
48
|
+
## Instance Methods
|
49
|
+
|
50
|
+
### `#execute_task(task)`
|
51
|
+
|
52
|
+
Executes a given task using the agent's reasoning capabilities.
|
53
|
+
|
54
|
+
**Parameters:**
|
55
|
+
- `task` (RCrewAI::Task) - The task to execute
|
56
|
+
|
57
|
+
**Returns:** String containing the task result
|
58
|
+
|
59
|
+
**Example:**
|
60
|
+
```ruby
|
61
|
+
task = RCrewAI::Task.new(
|
62
|
+
name: "analyze_trends",
|
63
|
+
description: "Analyze current AI trends",
|
64
|
+
agent: agent
|
65
|
+
)
|
66
|
+
|
67
|
+
result = agent.execute_task(task)
|
68
|
+
puts result
|
69
|
+
```
|
70
|
+
|
71
|
+
### `#use_tool(tool_name, **params)`
|
72
|
+
|
73
|
+
Uses a specific tool with the given parameters.
|
74
|
+
|
75
|
+
**Parameters:**
|
76
|
+
- `tool_name` (String) - Name of the tool to use
|
77
|
+
- `**params` - Parameters to pass to the tool
|
78
|
+
|
79
|
+
**Returns:** String containing the tool's result
|
80
|
+
|
81
|
+
**Example:**
|
82
|
+
```ruby
|
83
|
+
result = agent.use_tool("websearch", query: "latest AI developments", max_results: 5)
|
84
|
+
puts result
|
85
|
+
```
|
86
|
+
|
87
|
+
### `#available_tools_description`
|
88
|
+
|
89
|
+
Returns a description of all available tools.
|
90
|
+
|
91
|
+
**Returns:** String describing available tools
|
92
|
+
|
93
|
+
**Example:**
|
94
|
+
```ruby
|
95
|
+
puts agent.available_tools_description
|
96
|
+
# Output: "- websearch: Search the web for information\n- filewriter: Write content to files"
|
97
|
+
```
|
98
|
+
|
99
|
+
### `#enable_human_input(**options)`
|
100
|
+
|
101
|
+
Enables human-in-the-loop functionality for the agent.
|
102
|
+
|
103
|
+
**Parameters:**
|
104
|
+
- `require_approval_for_tools` (Boolean, optional) - Require approval for tool usage
|
105
|
+
- `require_approval_for_final_answer` (Boolean, optional) - Require approval for results
|
106
|
+
|
107
|
+
**Returns:** `self`
|
108
|
+
|
109
|
+
**Example:**
|
110
|
+
```ruby
|
111
|
+
agent.enable_human_input(
|
112
|
+
require_approval_for_tools: true,
|
113
|
+
require_approval_for_final_answer: true
|
114
|
+
)
|
115
|
+
```
|
116
|
+
|
117
|
+
### `#disable_human_input`
|
118
|
+
|
119
|
+
Disables human-in-the-loop functionality.
|
120
|
+
|
121
|
+
**Returns:** `self`
|
122
|
+
|
123
|
+
**Example:**
|
124
|
+
```ruby
|
125
|
+
agent.disable_human_input
|
126
|
+
```
|
127
|
+
|
128
|
+
### `#human_input_enabled?`
|
129
|
+
|
130
|
+
Checks if human input is enabled.
|
131
|
+
|
132
|
+
**Returns:** Boolean
|
133
|
+
|
134
|
+
**Example:**
|
135
|
+
```ruby
|
136
|
+
if agent.human_input_enabled?
|
137
|
+
puts "Human input is enabled"
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
### `#is_manager?`
|
142
|
+
|
143
|
+
Checks if the agent is designated as a manager.
|
144
|
+
|
145
|
+
**Returns:** Boolean
|
146
|
+
|
147
|
+
**Example:**
|
148
|
+
```ruby
|
149
|
+
if agent.is_manager?
|
150
|
+
puts "This is a manager agent"
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
### `#add_subordinate(agent)`
|
155
|
+
|
156
|
+
Adds a subordinate agent (only for manager agents).
|
157
|
+
|
158
|
+
**Parameters:**
|
159
|
+
- `agent` (RCrewAI::Agent) - Agent to add as subordinate
|
160
|
+
|
161
|
+
**Returns:** `self`
|
162
|
+
|
163
|
+
**Example:**
|
164
|
+
```ruby
|
165
|
+
manager = RCrewAI::Agent.new(name: "manager", role: "Team Lead", goal: "Coordinate team", manager: true)
|
166
|
+
specialist = RCrewAI::Agent.new(name: "specialist", role: "Specialist", goal: "Execute tasks")
|
167
|
+
|
168
|
+
manager.add_subordinate(specialist)
|
169
|
+
```
|
170
|
+
|
171
|
+
### `#subordinates`
|
172
|
+
|
173
|
+
Returns all subordinate agents.
|
174
|
+
|
175
|
+
**Returns:** Array of `RCrewAI::Agent` instances
|
176
|
+
|
177
|
+
**Example:**
|
178
|
+
```ruby
|
179
|
+
manager.subordinates.each do |subordinate|
|
180
|
+
puts "Subordinate: #{subordinate.name}"
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
### `#delegate_task(task, target_agent)`
|
185
|
+
|
186
|
+
Delegates a task to another agent (manager functionality).
|
187
|
+
|
188
|
+
**Parameters:**
|
189
|
+
- `task` (RCrewAI::Task) - Task to delegate
|
190
|
+
- `target_agent` (RCrewAI::Agent) - Agent to receive the task
|
191
|
+
|
192
|
+
**Returns:** Task result
|
193
|
+
|
194
|
+
**Example:**
|
195
|
+
```ruby
|
196
|
+
task = RCrewAI::Task.new(name: "analysis", description: "Analyze data", agent: manager)
|
197
|
+
result = manager.delegate_task(task, data_analyst)
|
198
|
+
```
|
199
|
+
|
200
|
+
## Attributes
|
201
|
+
|
202
|
+
### `name` (readonly)
|
203
|
+
The agent's unique name.
|
204
|
+
|
205
|
+
**Type:** String
|
206
|
+
|
207
|
+
### `role` (readonly)
|
208
|
+
The agent's role description.
|
209
|
+
|
210
|
+
**Type:** String
|
211
|
+
|
212
|
+
### `goal` (readonly)
|
213
|
+
The agent's primary objective.
|
214
|
+
|
215
|
+
**Type:** String
|
216
|
+
|
217
|
+
### `backstory` (readonly)
|
218
|
+
The agent's background context.
|
219
|
+
|
220
|
+
**Type:** String
|
221
|
+
|
222
|
+
### `tools` (readonly)
|
223
|
+
Array of available tools.
|
224
|
+
|
225
|
+
**Type:** Array
|
226
|
+
|
227
|
+
### `memory`
|
228
|
+
The agent's memory system for learning.
|
229
|
+
|
230
|
+
**Type:** RCrewAI::Memory
|
231
|
+
|
232
|
+
### `llm_client`
|
233
|
+
The LLM client used for reasoning.
|
234
|
+
|
235
|
+
**Type:** RCrewAI::LLMClient
|
236
|
+
|
237
|
+
### `verbose`
|
238
|
+
Controls detailed logging.
|
239
|
+
|
240
|
+
**Type:** Boolean
|
241
|
+
|
242
|
+
### `allow_delegation`
|
243
|
+
Whether agent can delegate tasks.
|
244
|
+
|
245
|
+
**Type:** Boolean
|
246
|
+
|
247
|
+
### `max_iterations`
|
248
|
+
Maximum reasoning iterations allowed.
|
249
|
+
|
250
|
+
**Type:** Integer
|
251
|
+
|
252
|
+
### `max_execution_time`
|
253
|
+
Maximum execution time in seconds.
|
254
|
+
|
255
|
+
**Type:** Integer
|
256
|
+
|
257
|
+
## Agent Reasoning Process
|
258
|
+
|
259
|
+
Agents follow a sophisticated reasoning loop:
|
260
|
+
|
261
|
+
1. **Context Building**: Gather task context, agent background, available tools
|
262
|
+
2. **Reasoning Loop**:
|
263
|
+
- Generate reasoning about the current situation
|
264
|
+
- Decide on actions (tool usage, delegation, completion)
|
265
|
+
- Execute chosen actions
|
266
|
+
- Evaluate results and continue or finish
|
267
|
+
3. **Result Generation**: Produce final answer based on reasoning and actions
|
268
|
+
4. **Memory Storage**: Store successful patterns and learnings
|
269
|
+
|
270
|
+
## Manager Agent Capabilities
|
271
|
+
|
272
|
+
Manager agents have additional capabilities:
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
# Create manager agent
|
276
|
+
manager = RCrewAI::Agent.new(
|
277
|
+
name: "project_manager",
|
278
|
+
role: "Project Manager",
|
279
|
+
goal: "Coordinate team execution efficiently",
|
280
|
+
manager: true,
|
281
|
+
allow_delegation: true
|
282
|
+
)
|
283
|
+
|
284
|
+
# Add team members
|
285
|
+
manager.add_subordinate(researcher)
|
286
|
+
manager.add_subordinate(writer)
|
287
|
+
manager.add_subordinate(analyst)
|
288
|
+
|
289
|
+
# Manager automatically coordinates task delegation
|
290
|
+
```
|
291
|
+
|
292
|
+
## Human-in-the-Loop Features
|
293
|
+
|
294
|
+
Agents can work collaboratively with humans:
|
295
|
+
|
296
|
+
```ruby
|
297
|
+
# Enable human collaboration
|
298
|
+
agent = RCrewAI::Agent.new(
|
299
|
+
name: "collaborative_agent",
|
300
|
+
role: "Data Analyst",
|
301
|
+
goal: "Analyze data with human oversight",
|
302
|
+
human_input: true,
|
303
|
+
require_approval_for_tools: true, # Human approves tool usage
|
304
|
+
require_approval_for_final_answer: true # Human validates results
|
305
|
+
)
|
306
|
+
|
307
|
+
# Human will be prompted for:
|
308
|
+
# - Tool usage approval
|
309
|
+
# - Strategic guidance during reasoning
|
310
|
+
# - Final result validation
|
311
|
+
```
|
312
|
+
|
313
|
+
## Agent Memory System
|
314
|
+
|
315
|
+
Agents maintain memory across executions:
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
# Agent learns from successful executions
|
319
|
+
agent.memory.add_execution(task, result, execution_time)
|
320
|
+
|
321
|
+
# Memory influences future reasoning
|
322
|
+
relevant_experience = agent.memory.relevant_executions(current_task)
|
323
|
+
|
324
|
+
# Check memory statistics
|
325
|
+
puts agent.memory.stats
|
326
|
+
# => { total_executions: 15, successful_patterns: 8, tools_used: ["websearch", "filewriter"] }
|
327
|
+
```
|
328
|
+
|
329
|
+
## Error Handling
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
begin
|
333
|
+
result = agent.execute_task(task)
|
334
|
+
rescue RCrewAI::AgentError => e
|
335
|
+
puts "Agent execution failed: #{e.message}"
|
336
|
+
rescue RCrewAI::ToolNotFoundError => e
|
337
|
+
puts "Tool not available: #{e.message}"
|
338
|
+
end
|
339
|
+
```
|
340
|
+
|
341
|
+
## Examples
|
342
|
+
|
343
|
+
### Basic Research Agent
|
344
|
+
|
345
|
+
```ruby
|
346
|
+
researcher = RCrewAI::Agent.new(
|
347
|
+
name: "ai_researcher",
|
348
|
+
role: "AI Research Specialist",
|
349
|
+
goal: "Research and analyze AI developments",
|
350
|
+
backstory: "Expert in AI with focus on emerging trends and practical applications",
|
351
|
+
tools: [RCrewAI::Tools::WebSearch.new],
|
352
|
+
verbose: true
|
353
|
+
)
|
354
|
+
|
355
|
+
task = RCrewAI::Task.new(
|
356
|
+
name: "ai_trends_research",
|
357
|
+
description: "Research the top 5 AI trends for 2024",
|
358
|
+
agent: researcher,
|
359
|
+
expected_output: "Comprehensive analysis of AI trends with sources"
|
360
|
+
)
|
361
|
+
|
362
|
+
result = researcher.execute_task(task)
|
363
|
+
```
|
364
|
+
|
365
|
+
### Manager Agent with Team
|
366
|
+
|
367
|
+
```ruby
|
368
|
+
# Create manager
|
369
|
+
manager = RCrewAI::Agent.new(
|
370
|
+
name: "team_lead",
|
371
|
+
role: "Technical Team Lead",
|
372
|
+
goal: "Coordinate technical projects efficiently",
|
373
|
+
backstory: "Experienced engineering manager with expertise in AI project coordination",
|
374
|
+
manager: true,
|
375
|
+
allow_delegation: true,
|
376
|
+
verbose: true
|
377
|
+
)
|
378
|
+
|
379
|
+
# Create specialists
|
380
|
+
backend_dev = RCrewAI::Agent.new(
|
381
|
+
name: "backend_developer",
|
382
|
+
role: "Senior Backend Developer",
|
383
|
+
goal: "Build robust backend systems",
|
384
|
+
tools: [RCrewAI::Tools::FileReader.new, RCrewAI::Tools::FileWriter.new]
|
385
|
+
)
|
386
|
+
|
387
|
+
frontend_dev = RCrewAI::Agent.new(
|
388
|
+
name: "frontend_developer",
|
389
|
+
role: "Frontend Developer",
|
390
|
+
goal: "Create excellent user interfaces",
|
391
|
+
tools: [RCrewAI::Tools::FileReader.new, RCrewAI::Tools::FileWriter.new]
|
392
|
+
)
|
393
|
+
|
394
|
+
# Build team hierarchy
|
395
|
+
manager.add_subordinate(backend_dev)
|
396
|
+
manager.add_subordinate(frontend_dev)
|
397
|
+
|
398
|
+
# Manager can now delegate tasks to appropriate specialists
|
399
|
+
```
|
400
|
+
|
401
|
+
### Human-Collaborative Agent
|
402
|
+
|
403
|
+
```ruby
|
404
|
+
analyst = RCrewAI::Agent.new(
|
405
|
+
name: "data_analyst",
|
406
|
+
role: "Senior Data Analyst",
|
407
|
+
goal: "Perform data analysis with human validation",
|
408
|
+
backstory: "Expert at data analysis who collaborates closely with stakeholders",
|
409
|
+
tools: [RCrewAI::Tools::FileReader.new, RCrewAI::Tools::FileWriter.new],
|
410
|
+
human_input: true,
|
411
|
+
require_approval_for_tools: true,
|
412
|
+
require_approval_for_final_answer: true
|
413
|
+
)
|
414
|
+
|
415
|
+
# This agent will:
|
416
|
+
# 1. Ask human approval before reading/writing files
|
417
|
+
# 2. Request human guidance during complex analysis
|
418
|
+
# 3. Get human validation of final results
|
419
|
+
```
|
420
|
+
|
421
|
+
## Best Practices
|
422
|
+
|
423
|
+
1. **Specific Roles**: Give agents clear, specific roles rather than generic ones
|
424
|
+
2. **Detailed Backstories**: Provide rich context that influences agent behavior
|
425
|
+
3. **Appropriate Tools**: Equip agents with tools relevant to their role
|
426
|
+
4. **Reasonable Limits**: Set appropriate iteration and time limits
|
427
|
+
5. **Human Oversight**: Enable human input for critical or sensitive tasks
|
428
|
+
6. **Manager Delegation**: Use manager agents for coordinating complex workflows
|
429
|
+
7. **Memory Utilization**: Let agents learn from past executions for better performance
|