Skip to content

Example: a planner and a worker agent hand off a task, and the planner reads the result with its provenance #710

Closed

Description

@zlareb1

Company or project name

No response

Component

Python SDK

Use case

docs/use-cases/multi-agent.md describes task inboxes and shared memory between agents, but sdk/python/examples/ has no script that runs a handoff end to end. Someone building a planner and workers has to piece the task lifecycle, the lease fence and the provenance fields together from the operations reference.

Describe the solution you'd like

Goal. A runnable example sdk/python/examples/multi_agent_handoff.py with two agents, each with its own token.

Files to start from

  • sdk/python/examples/agent_memory.py: the layout to copy.
  • docs/reference/operations/task.md: task.create (inbox, kind, title, brief), task.claim (returns the task with its fence), task.heartbeat and task.complete (fence, outcome).
  • docs/reference/operations/inbox.md: inbox.register (admin on the owner namespace).
  • docs/reference/operations/memory.md: memory.get returns agent, actor, source_class and source_trace.
  • sdk/python/loom/tasks.py (bot.tasks.*: register_inbox, create, claim, heartbeat, complete, get) and the snippet in docs/features/tasks-and-decisions.md; sdk/python/loom/memory.py (MemoryClient) for bot.memory.*.

Acceptance criteria

  • The planner's token is --roles admin on the namespace (it registers the inbox); the worker's is --roles writer on the same namespace, and the inbox's owner_agent is the worker's agent.
  • The namespace comes from the environment (LOOM_NAMESPACE) and must be the one both pre-minted tokens name; unlike agent_memory.py, the script registers no throwaway namespace, since neither token would reach it. Only the inbox is throwaway.
  • The planner registers a throwaway inbox and posts a task with task.create.
  • The worker, on its own token (loom mint-token --subject worker …), claims the task with task.claim, sends one task.heartbeat with the fence the claim returned, writes its result with memory.set (no promotion: memory.get falls back to the same user's row under any agent), and finishes with task.complete, naming the memory key in outcome.
  • The planner reads the task's outcome, then the memory with memory.get, and prints who wrote it (agent, actor) and source_class.
  • Name the inbox with a random suffix (inbox names are unique in the org and there is no op to delete one); in a finally, cancel any unfinished task and delete the memory. task.cancel is open to the owner, or to the poster only while nobody owns the task (docs/features/tasks-and-decisions.md), so the worker's token cancels a task it has claimed and the planner's cancels one still todo. The script exits 0 only when every check passes.
  • tests/unit/test_sdk_example_multi_agent_handoff.py, modelled on tests/unit/test_sdk_example_agent_memory.py: it loads the script by path and runs it against an httpx.MockTransport server that answers each op (telling the two tokens apart by their Authorization header). It checks that the cleanup cancels the unfinished task and deletes the memory when a step in the middle fails (for example task.complete answering 422), and that the script exits non-zero when a check fails and 0 when every check passes.
  • A section in sdk/python/examples/README.md with the commands (both tokens) and the output of a real run, and a link from the "Start" section of docs/use-cases/multi-agent.md. docs: the multi-agent use case does not mention session briefs for handing work between sessions #708 also edits that page; whichever lands second rebases onto it.

How to test

  • Against a local Loom with auth on, so the two tokens are distinct principals; say in the PR how you minted them.
  • make format-check lint, the example's unit test, and the docs checks:
.venv/bin/python -m pytest tests/unit/test_sdk_example_multi_agent_handoff.py -q
.venv/bin/python -m pytest tests/unit/test_doc_links.py tests/unit/test_public_copy.py -q
.venv/bin/python -m scripts.codegen.docs_reference --check

Describe alternatives you've considered

The operations reference documents each call on its own; there is no run that shows the fence, the outcome and the provenance together.

Where the need comes from

The need is mine, an AI tool helped shape the proposal

Additional context

Size: M (a day or two). Read CONTRIBUTING.md first (signed-off commits), and comment here to say you are working on it.

Activity

  1. added
    enhancement
    help wanted
    on Nov 16, 2026
  2. added
    up-for-grabs
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wantedup-for-grabs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions