Skip to content

feat: 1.2.0 multi-agent coordination methods + usage() fix → 0.2.0#6

Merged
ryanmcmillan merged 1 commit intomainfrom
feat/multi-agent-coordination
Apr 14, 2026
Merged

feat: 1.2.0 multi-agent coordination methods + usage() fix → 0.2.0#6
ryanmcmillan merged 1 commit intomainfrom
feat/multi-agent-coordination

Conversation

@ryanmcmillan
Copy link
Copy Markdown
Member

Summary

Brings the Python SDK in line with @delega-dev/mcp 1.2.0. Fixes a latent bug in `usage()` along the way.

New methods (sync + async, 1:1 with delega-mcp 1.2.0)

  • `tasks.assign(task_id, agent_id)` — `PUT /tasks/:id`. Pass `None` to unassign.
  • `tasks.delegate(...)` — existing method, now accepts `project_id`, `labels`, `due_date`, `assigned_to_agent_id` kwargs (all optional, backward compatible).
  • `tasks.chain(task_id)` — `GET /tasks/:id/chain`. Returns `DelegationChain` dataclass. Client normalizes hosted `{root_id}` vs self-hosted `{root: Task}` shape divergence.
  • `tasks.update_context(task_id, context)` — `PATCH /tasks/:id/context`. Deep-merges. Normalizes hosted bare-dict vs self-hosted full-task response.
  • `tasks.find_duplicates(content, threshold=None)` — `POST /tasks/dedup`. Returns `DedupResult`.

Bug fix

`Delega.usage()` was hitting `/stats` instead of `/usage` since inception — silently returning stats data instead of quota. Now correctly calls `/usage` on hosted, raises `DelegaError` before any HTTP call on self-hosted (mirrors delega-mcp's client-side gate). Async `usage()` was already hitting `/usage` but lacked the gate; added.

Task model enriched

`Task.from_dict()` now surfaces `parent_task_id`, `root_task_id`, `delegation_depth`, `status`, `assigned_to_agent_id`, `created_by_agent_id`, `completed_by_agent_id`, `context`. Auto-parses the JSON-encoded context string that hosted returns (D1 text column) vs the dict self-hosted returns (SQLAlchemy JSON).

New dataclasses: `DelegationChain`, `DedupResult`, `DuplicateMatch` — all exported from the package root.

Version: 0.1.3 → 0.2.0

Minor bump. All additions are backward compatible (existing `delegate()` / `usage()` callers pass through unchanged; the endpoint correction in `usage()` is a semantic fix).

Test plan

  • `pytest` — 63/63 pass (53 pre-existing + 10 new covering every new method and both shape branches of `chain` / `update_context`)
  • `usage()` self-hosted gate verified (test confirms `urlopen` is never called)
  • HTTPClient `path_prefix` property added to both sync and async transports
  • Live smoke against api.delega.dev after release (requires rotated test creds — see clean-room validation from tonight's MCP work)

Release

Tag `v0.2.0` after merge — `.github/workflows/publish.yml` publishes to PyPI via OIDC and creates the GitHub Release.

Out of scope (follow-up)

  • Async test coverage for new methods. The async paths mirror sync line-for-line; a later PR can add async-specific tests (the repo currently has no async test coverage for existing methods either).

🤖 Generated with Claude Code

Brings the Python SDK in line with @delega-dev/mcp 1.2.0. Agents using
this SDK can now delegate, inspect chains, pass shared context, and
dedup — the surfaces that turn Delega from a task tracker into an
actual coordination layer.

New methods (sync + async):
- tasks.assign(task_id, agent_id) — PUT /tasks/:id with
  assigned_to_agent_id (None to unassign). For multi-agent handoffs
  use delegate() instead — assign() doesn't record a chain.
- tasks.chain(task_id) — GET /tasks/:id/chain. Returns
  DelegationChain dataclass. Client normalizes hosted {root_id}
  vs self-hosted {root: Task} shape divergence so root_id is
  always populated.
- tasks.update_context(task_id, context) — PATCH /tasks/:id/context.
  Deep-merges keys (not replace). Normalizes hosted bare-dict vs
  self-hosted full-task response; always returns the merged dict.
- tasks.find_duplicates(content, threshold=None) — POST /tasks/dedup.
  Returns DedupResult with DuplicateMatch entries.

Existing method updates:
- tasks.delegate() gains project_id / labels / due_date /
  assigned_to_agent_id kwargs matching the delega-mcp tool signature.
  Existing callers unaffected (all additions are optional kwargs).
- Delega.usage() BUG FIX: was hitting /stats, now correctly /usage.
  Raises DelegaError before any HTTP call on self-hosted backends
  (which don't expose /usage — mirrors the delega-mcp client gate).
  Async usage() also gets the gate.

Model updates:
- Task now surfaces parent_task_id, root_task_id, delegation_depth,
  status, assigned_to_agent_id, created_by_agent_id,
  completed_by_agent_id, context. from_dict() auto-parses the
  JSON-encoded context string that hosted returns (D1/SQLite text
  column) vs the dict self-hosted returns (SQLAlchemy JSON).
- New: DelegationChain, DedupResult, DuplicateMatch dataclasses.
  All exposed from the package root.

Test updates:
- 10 new unit tests covering all new methods and both shape branches
  of chain() and update_context(). Existing test_usage split into
  _hosted + _self_hosted_raises_before_fetch (asserts mock never
  called).
- HTTPClient.path_prefix property added to both sync and async
  transports so the usage gate can inspect the namespace.

Version: 0.1.3 → 0.2.0 (minor — new methods, usage() endpoint
change is a semantic fix not a signature change).

63/63 pytest tests passing.

Out of scope (follow-up): async test coverage for the new methods.
The async paths are line-by-line mirrors of sync; a later PR can
add async-specific tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@ryanmcmillan ryanmcmillan merged commit b4df89f into main Apr 14, 2026
5 checks passed
@ryanmcmillan ryanmcmillan deleted the feat/multi-agent-coordination branch April 14, 2026 17:27
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