Skip to main content
Glama

poll_next_task

Atomically claims the oldest pending contract assigned to your agent and verifies local file fingerprints, returning the claimed work or an empty-queue result.

Instructions

Atomically claim the oldest pending SUBMITTED contract assigned to this agent and verify local file fingerprints.

Purpose

Retrieves and claims next available contract work for the current agent, transitioning it from SUBMITTED to CLAIMED.

Usage Guidelines

  • When to use: Call periodically or when notified to discover and atomically take ownership of pending tasks assigned to your agent_id.

  • When NOT to use:

    • Do NOT use to non-destructively inspect queue depth or monitor status without claiming (use inspect_mesh_state).

    • Do NOT use to create contracts (use dispatch_contract).

  • IMPORTANT (ADR-0004): Pointers are an immutable baseline snapshot ("what I read"). Never edit pointer files directly on disk while holding a review contract; deliver any proposed code fixes via structured_output.fixes in fulfill_contract.

Behavior & Side Effects

  • Mutates database: Atomically claims the oldest SUBMITTED contract for agent_id using optimistic concurrency (UPDATE ... WHERE status='SUBMITTED', checked by changes===1). Starts the exec_ttl_sec window.

  • Lazy TTL sweep: Automatically sweeps and marks expired contracts as TIMED_OUT using lock-free read-before-write probing.

  • Fingerprint verification: Verifies Existence -> Byte Size -> SHA-256 for all pointers. If on-disk files were altered or missing, marks the contract POINTER_STALE and transparently advances to claim the next valid candidate in the queue.

Return Value

  • When work is claimed: { ok: true, has_task: true, status: 'CLAIMED', contract: { contract_id, requester_agent, target_agent, task_type, title, context_summary, workspace_root, pointers, contract_schema, claimed_at, exec_ttl_sec } }.

  • When queue is empty: { ok: true, has_task: false, message: 'No pending contracts for agent "<agent_id>"' }.

Input Schema

NameRequiredDescriptionDefault
agent_idNoWorker agent identifier claiming tasks (defaults to AGENT_NAME env var, e.g., "workbuddy").

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.3.0
    • changedInput schema / properties / agent_id / description
      Previous value: -"Current worker agent identifier (defaults to AGENT_NAME env var, e.g., \"workbuddy\")"New value: +"Worker agent identifier claiming tasks (defaults to AGENT_NAME env var, e.g., \"workbuddy\")."
  2. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full behavioral burden and does so thoroughly: it discloses the atomic DB mutation, optimistic concurrency check, TTL window start, lazy TTL sweep, fingerprint verification order, POINTER_STALE handling, and queue advancement. It also describes both success and empty-queue return shapes.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded and sectioned into purpose, usage, behavior, and return value, making it scannable despite its length. It is appropriately detailed for a stateful claiming operation, though some repetition of the atomic-claim concept across sections keeps it short of perfect conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex mutation with no annotations and no output schema, the description is complete enough to call correctly: it explains side effects, concurrency behavior, TTL behavior, stale-pointer handling, and return values. An agent has the operational context needed without opening additional documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and the schema already documents agent_id including its default from the AGENT_NAME environment variable. The description reinforces that the task is assigned to this agent, but adds little parameter-level meaning beyond the schema, so the baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: atomically claim the oldest pending SUBMITTED contract assigned to this agent, including fingerprint verification. It clearly distinguishes the tool from siblings by naming inspect_mesh_state for non-claiming inspection and dispatch_contract for creating contracts.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives explicit when-to-use guidance (periodically or when notified to discover and claim pending tasks) and explicit when-not-to-use guidance with named alternatives for inspection and contract creation. It also adds a relevant ADR constraint about pointer immutability.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.