Commit 71b72b9
authored
feat(subagent): add planner mode for task delegation (#753)
* feat(subagent): add output schema support with Pydantic validation
- Add optional output_schema parameter to subagent() function
- Validate subagent outputs against provided Pydantic schemas
- Modify return prompt to include schema when provided
- Add comprehensive tests for schema validation logic
- Enables structured outputs for planner pattern (Issue #39)
This is foundation work for implementing the Manus-style planner pattern,
allowing subagents to return structured, validated outputs instead of
generic JSON responses.
Co-authored-by: Bob <bob@superuserlabs.org>
* feat(subagent): add planner mode for task delegation
- Add mode parameter (executor/planner) to subagent()
- Add subtasks parameter for planner mode
- Implement _run_planner() to spawn multiple executor subagents
- Each subtask gets its own executor with optional output schema
- Fix closure issue with loop variables in thread function
This implements Phase 1 of the planner pattern from Issue #39,
enabling efficient multi-step task delegation as seen in Manus agent.
Co-authored-by: Bob <bob@superuserlabs.org>
* test(subagent): fix type annotations and remove unused variable
- Add SubtaskDef import for proper typing
- Type annotate subtasks lists in tests
- Remove unused initial_count variable
Co-authored-by: Bob <bob@superuserlabs.org>
* docs(subagent): add planner mode examples
Add examples demonstrating both executor and planner modes:
- Executor mode: single task delegation (existing)
- Planner mode: multi-task delegation with subtasks
Co-authored-by: Bob <bob@superuserlabs.org>
* refactor(subagent): remove Pydantic dependency per maintainer feedback
- Remove Pydantic-based output schema validation
- Simplify to prompt-based approach (model + good prompts)
- Keep planner mode functionality (core value)
- Delete schema validation tests
- Update remaining tests to not use Pydantic
Addresses feedback from PR #753 and #751 that gptme should remain
provider-independent and rely on model capability + prompts rather
than strict schema enforcement.
Co-authored-by: Bob <bob@superuserlabs.org>
* refactor(subagent): use logger instead of print statements
- Replace print with logger.error for error messages (lines 65, 68)
- Replace print with logger.info for informational messages (line 218)
- Update docstring to clarify async execution and immediate None return
Addresses automated review feedback from Ellipsis on PR #753.
* fix(subagent): add blank line between import groups
Fixes lint error I001 (unsorted imports) by adding blank line
between first-party imports (gptme) and relative imports (..prompts).
Co-authored-by: Bob <bob@superuserlabs.org>
* docs(subagent): fix Sphinx documentation warnings
- Use string literal for SubtaskDef type annotation
- Reformat Returns section to avoid class reference misinterpretation
Fixes build failure in PR #753.
Co-authored-by: Bob <bob@superuserlabs.org>
* fix(subagent): remove string literal from SubtaskDef type hint for Sphinx
Sphinx autodoc was failing to resolve the string reference list["SubtaskDef"].
Since SubtaskDef is defined before its use, no forward reference needed.
Fixes build failure in PR #753.
* docs(subagent): add SubtaskDef to nitpick_ignore list
Fix Sphinx build error where SubtaskDef reference could not be resolved.
TypedDict classes need to be added to nitpick_ignore to prevent warnings.
Co-authored-by: Bob <bob@superuserlabs.org>
* feat(subagent): add parallel/sequential execution modes and complete tool integration
Addresses Erik's feedback on PR #753:
- Add execution_mode parameter (parallel/sequential) to planner mode
- Replace JSON return format with complete tool usage
- Update status() method to detect complete tool calls
- Add tests for both execution modes
Benefits:
- Sequential mode waits for each subtask before starting next
- Parallel mode (default) runs all subtasks concurrently
- Complete tool provides natural task completion with full log access
- Cleaner API aligned with gptme's tool-based architecture
Co-authored-by: Bob <bob@superuserlabs.org>
* feat(subagent): add Phase 3 context sharing modes
Implement three context sharing modes for subagent tool:
- full: Complete context (agent identity, tools, workspace) - default
- instructions-only: Minimal context with just user prompt
- selective: Choose specific context components
Features:
- New context_mode parameter (full/instructions-only/selective)
- New context_include parameter for selective mode
- Support for component selection: agent, tools, workspace
- Updated examples and documentation
- 9 new test cases for context modes
Context modes enable token-efficient task delegation:
- instructions-only: For simple, well-defined tasks
- selective: For tasks needing specific context
- full: For complex tasks requiring all context
Addresses Phase 3 in enhance-subagent-planner-pattern task.
Co-authored-by: Bob <bob@superuserlabs.org>
* fix(subagent): move context_mode validation to main thread
Move context_mode='selective' validation from run_subagent() (background
thread) to subagent() (main thread) so pytest.raises() can catch it properly.
Also add type assertion for context_include to satisfy mypy after validation.
Fixes test_context_mode_selective_requires_context_include.
Co-authored-by: Bob <bob@superuserlabs.org>
* fix(subagent): propagate context_mode to planner executors
Fixes the critical issue identified in Greptile review where planner
mode ignored context_mode parameter and always used full context.
Changes:
- Add context_mode and context_include parameters to _run_planner()
- Pass these parameters from subagent() when calling _run_planner()
- Replace hardcoded get_prompt() with context-aware message building
- Use same context-building logic as executor mode
Executors spawned by planner now correctly respect:
- 'instructions-only': Minimal context with complete tool only
- 'selective': Custom context components (agent, tools, workspace)
- 'full': Complete context (default, backward compatible)
Addresses: #753 (Greptile confidence score 2/5)1 parent 630c0cc commit 71b72b9
File tree
3 files changed
+555
-46
lines changed- docs
- gptme/tools
- tests
3 files changed
+555
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | | - | |
| 13 | + | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 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 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
74 | 269 | | |
75 | 270 | | |
76 | 271 | | |
| |||
87 | 282 | | |
88 | 283 | | |
89 | 284 | | |
90 | | - | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
91 | 328 | | |
92 | 329 | | |
93 | 330 | | |
| |||
100 | 337 | | |
101 | 338 | | |
102 | 339 | | |
| 340 | + | |
| 341 | + | |
103 | 342 | | |
104 | 343 | | |
105 | 344 | | |
| |||
139 | 378 | | |
140 | 379 | | |
141 | 380 | | |
142 | | - | |
| 381 | + | |
143 | 382 | | |
144 | 383 | | |
145 | 384 | | |
146 | 385 | | |
147 | 386 | | |
148 | 387 | | |
149 | 388 | | |
| 389 | + | |
150 | 390 | | |
151 | 391 | | |
152 | 392 | | |
153 | 393 | | |
154 | 394 | | |
155 | 395 | | |
156 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
157 | 429 | | |
158 | 430 | | |
159 | 431 | | |
| |||
0 commit comments