Add Magentic agent-workflow builder (implements #564)#565
Draft
PratikDhanave wants to merge 1 commit into
Draft
Conversation
NewMagenticWorkflowBuilder(agents...) builds a manager-orchestrated multi-agent workflow. A dedicated orchestrator agent (WithManager) maintains a task ledger and, each round, evaluates a JSON progress ledger to decide whether the request is satisfied, whether progress has stalled, and which participant speaks next. It re-plans on stalls (WithMaximumStallCount) and stops after exhausting its reset budget (WithMaximumResetCount) or the round cap (WithMaximumRoundCount). Reuses the group-chat host and GroupChatManager machinery: the orchestrator drives SelectNextAgent and ShouldTerminate, with the ledger checkpoint- persisted as manager state. Unparseable orchestrator output and unknown next-speaker names degrade gracefully rather than failing the run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the Magentic builder proposed in #564 — the last unimplemented agent-workflow builder per
docs/dotnet-go-sdk-feature-comparison.md("Handoff and Magentic builders are not yet implemented"). Handoff is #545; this is its sibling.Filed as a draft to anchor the design discussion in #564 — the four design questions there (orchestrator handle, ledger-prompt customization, stall/reset semantics, scope) are still open, and I would rather converge on the API with you before polishing. The core orchestration is implemented and tested.
API (matches the existing
New…WorkflowBuilderconventions)How it works
It is a thin wrapper over
NewGroupChatWorkflowBuilder. AmagenticManagersuppliesGroupChatManager.SelectNextAgentandShouldTerminate:{is_request_satisfied, is_progress_being_made, is_in_loop, next_speaker, instruction}, which decides routing and termination.OnCheckpoint/OnCheckpointRestored, matching the round-robin manager.next_speakerends the run rather than routing to a non-participant.Scope / open question (ties to #564 Q1/Q3)
This PR implements orchestrator-driven selection + termination + re-planning, which is the reviewable core. Per-turn instruction injection to the selected speaker is intentionally deferred: the group-chat host broadcasts only to non-speakers, so cleanly handing the orchestrator’s
instructionto the chosen agent needs either a small host hook or a manager-supplied preamble — a design choice I’d like your steer on (#564). Theinstructionfield is already parsed and part of the ledger.Tests
magentic_test.go(white-box, matching the package convention) covers: builder validation (missing manager, no agents), routing to the selected speaker then terminating onis_request_satisfied, stall→re-plan→reset-budget termination (bounded, not round-capped), unknown-speaker graceful termination, and progress-ledger JSON parsing (plain, fenced-with-prose, and non-JSON). Full package green;gofumpt/vetclean.