Skip to content

feat(labs): add adaptive team orchestration - #1

Open
ferponse wants to merge 1 commit into
mainfrom
cursor/magentic-orchestration-5616
Open

ferponse wants to merge 1 commit into
mainfrom
cursor/magentic-orchestration-5616

Conversation

@ferponse

Copy link
Copy Markdown
Owner

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

This pull request is on the fork. It does not close the upstream issue by itself. The branch is based on current google/adk-python main so it can be proposed upstream later.

Problem:

ADK can already route work with a Workflow, ctx.run_node, sub-agent transfer, and AgentTool. It does not ship the open-ended team loop from issue google#8167: a coordinator that writes a plan, checks progress in a structured way, picks the next specialist, notices a stall, replans within a limit, optionally pauses for a person to accept the plan, and then writes one answer. Applications otherwise rebuild that bookkeeping themselves.

Solution:

adaptive_team(...) in google.adk.labs.adaptive_team returns a normal Workflow. One driver node, with rerun_on_resume=True, runs the loop in Python and calls the coordinator and the specialists through ctx.run_node.

The shape is a labs helper rather than a new agent runtime or a class named after Magentic. ADK 2.x already treats imperative ctx.run_node loops as the orchestration surface (Workflow graphs, dynamic nodes, RequestInput, output_schema). A helper that returns a Workflow reuses resumability, event streaming, and session state instead of adding a second executor. Labs keeps the API experimental (FeatureName.ADAPTIVE_TEAM, on by default, one warning) so the ledger fields can still change.

This is an original implementation inspired by the publicly described Magentic-One pattern (a coordinator, a task plan, a per-round progress check, stall handling, an optional human plan review, and a final answer). Prompts, schemas, class names, and control flow were written for ADK. No Microsoft source was copied.

Behavior:

  • The coordinator writes a TaskPlan, then a RoundAssessment each round, then the final answer.
  • The assessment names the next specialist and the assignment. That specialist is invoked with ctx.run_node.
  • A round is stalled when the assessment says so, when the same specialist is given the same assignment again, or when the name is not on the roster.
  • stall_limit stalled rounds in a row replace the plan, up to replan_limit. After that the coordinator writes a best-effort answer. max_rounds bounds specialist turns.
  • review_plan=True pauses with the existing RequestInput / PlanDecision path before a plan is executed, and again after a replacement. A rejection spends one replacement.
  • The ledger is a TeamSnapshot in session state (team_state_key). It is scoped to the invocation, so a review resume continues and a new user message starts over. Run ids are stable, so a resume replays finished model calls.
  • Coordinator events set custom_metadata["adaptive_team"]["kind"] to plan, replan, progress, or answer. Specialist events keep the specialist as the author. The workflow output is the answer text.
  • The manager's instruction is extra guidance. The helper supplies the phase instructions and does not call the manager's tools, so each phase can return one object.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

pytest tests/unittests/labs/adaptive_team/test_adaptive_team.py tests/unittests/features -q

  • adaptive team: 13 passed (delegation and final answer, a second user turn, stall then replan, replan budget, round limit, unknown specialist, repeated assignment, empty task, plan review on resumable and non-resumable runs, rejected plan, invalid configuration, feature disabled)
  • tests/unittests/features: 43 passed

The tests use ADK's MockModel / InMemoryRunner. mypy on src/google/adk/labs/adaptive_team reported no errors. pylint on the new package rated 10.00/10.

Manual End-to-End (E2E) Tests:

No hosted model was called. Importing contributing/samples/workflows/adaptive_team/agent.py builds a Workflow named energy_brief. The loop itself is covered by the mock-model tests above, including pause and resume.

adk web contributing/samples/workflows/adaptive_team

Try: Compare the energy use of electric and gas heating for a small apartment, and name the bigger uncertainty.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Open questions for maintainers:

  1. Is google.adk.labs the right home until the ledger schema settles, or should this be a public Workflow builder under google.adk.workflow?
  2. Should a rejected plan review share replan_limit with stall replans, as it does here, or have its own budget?
  3. Should the coordinator be allowed to call its own tools during planning? They are dropped today so structured output stays a single object.
  4. Stall detection is both the model's stalled flag and a mechanical check for a repeated assignment or an unknown name. Is that the policy you want, or should the model be the only judge?
  5. The public name is adaptive_team, not Magentic. Happy to rename if a different word fits the rest of the API.
  6. Participants are any BaseAgent. Should that be narrowed to LlmAgent?
Open in Web Open in Cursor 

Add an experimental workflow helper that plans a task, selects one
specialist at a time, replans when progress stalls, and can pause for
a person to accept the plan. The loop is an original ADK workflow on
top of ctx.run_node, structured output, and RequestInput. It is
inspired by the publicly described Magentic-One pattern
(google#8167).

Co-authored-by: Ferran Pons Serra <ferponse@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/magentic-orchestration-5616 branch from 95eb7fc to 48a580f Compare November 16, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant