Repository navigation
Description
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 itsfence),task.heartbeatandtask.complete(fence,outcome).docs/reference/operations/inbox.md:inbox.register(admin on the owner namespace).docs/reference/operations/memory.md:memory.getreturnsagent,actor,source_classandsource_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) forbot.memory.*.
Acceptance criteria
- The planner's token is
--roles adminon the namespace (it registers the inbox); the worker's is--roles writeron the same namespace, and the inbox'sowner_agentis the worker's agent. - The namespace comes from the environment (
LOOM_NAMESPACE) and must be the one both pre-minted tokens name; unlikeagent_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 withtask.claim, sends onetask.heartbeatwith the fence the claim returned, writes its result withmemory.set(no promotion:memory.getfalls back to the same user's row under any agent), and finishes withtask.complete, naming the memory key inoutcome. - The planner reads the task's outcome, then the memory with
memory.get, and prints who wrote it (agent,actor) andsource_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.cancelis 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 stilltodo. The script exits 0 only when every check passes. tests/unit/test_sdk_example_multi_agent_handoff.py, modelled ontests/unit/test_sdk_example_agent_memory.py: it loads the script by path and runs it against anhttpx.MockTransportserver that answers each op (telling the two tokens apart by theirAuthorizationheader). It checks that the cleanup cancels the unfinished task and deletes the memory when a step in the middle fails (for exampletask.completeanswering 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.mdwith 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 --checkDescribe 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