Skip to Content
Recodocs

Coordinated workflow team

Deterministic owner for a coordinator plus specialists—admit delegations, run them through shared goals and runs, cite consolidations, version role definitions, and record usage without executing proposed effects.

8 min read

recohut_kit.team is the kit owner for a multi-role workflow: one coordinator role, one or more specialists, and a single round loop. The package validates what gets proposed, executes admitted work through the shared harness goal ledger and RunStore, records outcomes and refusals, checks consolidation citations, and stores owner-approved role instruction files. Model steps enter only through two injected callables—TeamHarness for the coordinator and SpecialistHarness for each specialist attempt. Everything else is plain code: permission checks, obligation supervision, SQLite tables, audit rows, and typed refusal codes in TeamRefused.

The package deliberately does not run tools or effects on behalf of specialists. Allowed effects are stored as awaiting_approval when approval-required and as proposed otherwise; effects outside the role and request become a failed outcome and are not stored. DelegationRunner never replays harness actions. It is not a distributed scheduler: the decision journal is single-host coordination, and max_parallel on DelegationPolicy caps how many delegations may be admitted per round, while attempts still run sequentially. It does not authenticate callers, price usage in money, or prove execution links without a host-supplied resolver. This package does not run a model; model steps enter only through the injected TeamHarness and SpecialistHarness callables.

Purpose

A multi-role workflow lets different roles contribute to the same task while preserving one accountable run. The coordinating loop is distinct from the checks that admit and record proposed work.

A team run answers: given a TeamSpec (roles, permissions, delegation policy, budgets), can the coordinator propose delegations and optional consolidation each round, can the kit refuse anything outside declared authority without silently narrowing requests, and can verified receipts support a cited final report? The workflow modules own that loop end to end. Adjacent packages own human approval UX (recohut_kit.human), goal supervision (recohut_kit.harness.goals), role identity (recohut_kit.multi_agent.roles), skillpack markdown for definitions (recohut_kit.skillpacks), and progress snapshots (recohut_kit.harness.progress). The team package composes them but does not replace them.

Public API

The package root re-exports the names in __all__. Import from recohut_kit.team or from submodules (recohut_kit.team.contracts, recohut_kit.team.workflow, and so on) when you want a narrower surface.

NameKindWhat it does
OWNERconstantDefault escalation target string for roles ("owner").
TeamRefusedexceptionTyped refusal with stable code and operator-safe detail.
PermissionsdataclassAllowed tools, effects, approval-required effects, and delegate targets per role.
RoleSpecdataclassAgentRole plus permissions, knowledge partitions, escalation, and identity_hash.
DelegationPolicydataclassPer-round admission cap (max_parallel), hop limit, per-specialist Budget shares, max_attempts.
TeamSpecdataclassTeam id, version, coordinator, specialists, policy, owner principal, team Budget.
DelegationRequestdataclassBounded delegation proposal; authority is checked, never narrowed.
SpecialistOutcomedataclassSpecialist harness result: kind, refs, usage, nested delegations, proposed effects.
DelegationIssuedataclassFailed or stalled attempt record for receipts.
DelegationReceiptdataclassStatus, attempts, output refs, usage, verdict, issues, pending effect ids.
ConsolidationItemdataclassOne consolidation line with citation refs.
ConsolidationDraftdataclassTitle and items for a proposed report.
CoordinatorDecisiondataclassCoordinator turn: delegations and/or consolidation plus usage.
RoundViewdataclassWhat the coordinator harness sees: prior receipts and refusals, not raw outputs.
TeamHarnessprotocolReceives keyword arguments team and view. Returns a CoordinatorDecision or awaitable.
SpecialistHarnessprotocolReceives keyword arguments role, request, and attempt. Returns a SpecialistOutcome or awaitable.
admitfunctionPermission, hop, budget, duplicate, and per-round admission checks.
check_permissionsfunctionSame permission rules as admission; raises TeamRefused on violation.
DelegationRunnerclassRuns admitted delegations for one round via Supervisor; builds receipts from store.
OutcomeVerifierclassWraps an application check function into a goal Verifier.
TeamWorkflowclassMulti-round loop: journal coordinator decisions, admit, run, consolidate.
TeamResultdataclassFinished or paused run: receipts, refusals, optional report, needs_input questions.
StepResultdataclassstep returns the next RoundState and may also return a TeamResult; a needs_input result is not terminal.
RoundStatedataclassDurable JSON-friendly state between rounds (refusals, which rounds ran).
PlanScopedataclassOptional bounds on coordinator proposals for roles and record: input refs (outside_plan refusal).
ConsolidatorclassRuns check_consolidation and writes audit rows.
ConsolidationReportdataclassAccepted report with digest and cited delegation ids.
check_consolidationfunctionCitation validation; refuses item_without_ref or unknown_ref.
citablefunctionBuilds allowed ref map from verified receipts and input refs.
progress_viewfunctionA round ProgressSnapshot plus decision items for pending definition approvals, and blockers for effects awaiting approval and stalled unverified delegations.
DefinitionStoreclassVersioned role instruction files with human approval for activation.
ActiveDefinitiondataclassOne active version: digest, text, parsed AgentDefinition.
parse_definitionfunctionParse skillpacks markdown; invalid frontmatter → definition_invalid.
validate_definitionfunctionThe name must match the role with underscores replaced by hyphens, tools must stay inside the role's permitted tools, and a set model must equal the role's configured model.
changed_linesfunctionLine-level diff for approval preview.
request_from_jsonfunctionDecode stored HumanRequest for definition proposals.
ExecutionContextdataclassScoped team, delegation, attempt, run for link registration.
execution_contextcontext managerBind current execution for specialist/host code.
current_executionfunctionRead bound ExecutionContext or None.
ExecutionLinkdataclassOpaque native_run, sandbox, or artifact reference plus optional digest.
ExecutionLinksclassRegister links as audit rows validated against persisted attempts.
ExecutionReadbackclassJoin attempts, run status, verdicts, and registered links.
DelegationExecutiondataclassReadback view for one delegation.
AttemptExecutiondataclassOne attempt with links, verdict JSON, and missing kinds.
LinkObservationdataclassResolver result: observed, missing, unverified, or conflict.
ResolvedLinkdataclassLink paired with observation.
RoleUsageLedgerclassRecord UsageReceipt rows per role; optional JSONL mirror after commit.
RoleUsagedataclassAggregated counts and tokens; tracks unknown token receipts.
iso_weekfunctionDefault usage period label from UTC time.
ActivityFeedclassPaged team audit joined with RunStore status.
ActivityPagedataclassOne page of ActivityRow plus cursor and more flag.
ActivityRowdataclassSingle audit event with tokens and detail JSON.
open_team_tablesfunctionCreate team tables on the shared storage target (SQLite or Postgres).

DecisionJournal and wire helpers (decision_from_wire, request_from_wire, outcome_from_wire) live in recohut_kit.team.recovery and are used internally by workflow and delegation; they are not re-exported from the package root.

How it composes

Team modules pull shared harness and kit types at import time. The following packages appear on the import lines (grouped by concern):

ConcernPackages
Harness corerecohut_kit.harness.contracts, recohut_kit.harness.db_scope, recohut_kit.harness.delegation_contracts, recohut_kit.harness.goals, recohut_kit.harness.state, recohut_kit.harness.stall, recohut_kit.harness.progress
Human approvalrecohut_kit.human.checkpoints, recohut_kit.human.contracts, recohut_kit.human.preview
Roles and definitionsrecohut_kit.multi_agent.roles, recohut_kit.skillpacks.contracts
JSON and usagerecohut_kit.json, recohut_kit.usage
Safety and I/Orecohut_kit.redaction, recohut_kit.files, recohut_kit.evals.codec

Within the team package, TeamWorkflow drives DelegationRunner and Consolidator. Both call open_team_tables; DecisionJournal is used by DelegationRunner and TeamWorkflow, not by Consolidator. ActivityFeed delegates execution detail to ExecutionReadback. DefinitionStore shares the same database file as delegations and activity.

Minimal usage

Install uv pip install '.[connectors]' from your Kit checkout to supply the dependencies loaded when importing the team workflow. The example admits a request for an allowed tool and refuses a request outside the specialist's permissions.

from recohut_kit.harness.delegation_contracts import Budget
from recohut_kit.multi_agent.roles import AgentRole
from recohut_kit.team import (
    DelegationPolicy,
    DelegationRequest,
    Permissions,
    RoleSpec,
    TeamRefused,
    TeamSpec,
    admit,
)

share = Budget(1000, 2, 4, 60.0)
lead = RoleSpec(
    AgentRole("lead", "Coordinate.", "scripted"), Permissions(delegate_to=("writer",))
)
writer = RoleSpec(
    AgentRole("writer", "Write drafts.", "scripted", ("content.read",)),
    Permissions(("content.read",), ("queue_post",), ("queue_post",)),
)
team = TeamSpec(
    "t1", 1, lead, (writer,),
    DelegationPolicy(max_parallel=1, max_hops=1, budget_share={"writer": share}),
    "owner-1", Budget(5000, 10, 20, 600.0),
)
ok = DelegationRequest("d1", "lead", "writer", "Draft", "v", tools=("content.read",))
assert admit(team, ok, ()) is ok
try:
    admit(team, DelegationRequest("d2", "lead", "writer", "x", "v", tools=("crm.write",)), ())
except TeamRefused as error:
    assert error.code == "permission_denied"
else:
    raise AssertionError("The out-of-scope tool must be refused.")

This shows that admit returns the request unchanged when allowed. The contract test asserts permission_denied, hop_limit, budget_exceeded, unknown_role, and parallel_limit; the excerpt shows permission_denied. admit also raises duplicate_delegation, which that test does not cover.

A full round loop wires scripted or model-backed harnesses into TeamWorkflow, passes verifier callables keyed by verifier name, and optionally applies PlanScope to coordinator proposals. Specialist follow-ups go through the delegation permission and admission checks. Recovery tests exercise replay: the same run id reuses journaled coordinator decisions and refuses recovery_conflict when execution version or scope drifts.

Limits and gotchas

  • Refuse, do not narrow. check_permissions and admit reject requests that exceed declared tools, effects, partitions, hops, or budget share. The coordinator cannot be a delegation target.
  • max_parallel is not concurrency. It limits admissions per round; DelegationRunner awaits each supervisor step in order.
  • Effects are proposed only. Outcomes with effects outside the intersection of role and request permissions become failed outcomes; approval-required effects get awaiting_approval rows.
  • Consolidation is all or nothing. Items without refs or with refs outside verified receipts and input refs refuse the whole report (item_without_ref, unknown_ref). Unverified delegations block consolidation via unverified_delegation on the report id.
  • Coordinator proposals start at hop 1 from the coordinator role; otherwise permission_denied.
  • needs_input outcomes end a delegation without spending retry budget the same way as completion for verification shape; the workflow can return reason="needs_input" with question payloads for the host.
  • Definition changes need HumanRequest approval: activate matches proposed digest and base version exactly. activate before approval raises definition_unapproved; text whose digest differs from the approved digest raises definition_stale.
  • Recovery binding is frozen. The binding covers team identity, scope, input refs, execution version, verifier names, and the round limit. Bump execution_version when changing plan scope, host input checks, or a verifier implementation under the same name. An existing run reuses its journaled coordinator decisions.
  • Execution links are not proof. ExecutionReadback lists missing for absent kinds or non-observed resolver status; without a resolver, links are unverified.
  • Workflow concurrency. TeamWorkflow uses a nonblocking POSIX lock beside a SQLite database. With PostgreSQL the storage locks individual transactions, and the host runtime must serialize execution for each workflow run.
  • Usage totals. Token sums are lower bounds when any receipt omits counters; usage_completeness documents that in audit detail.

Verification

The example checks both an allowed delegation and a refusal for an undeclared tool. See Verify the examples.

How is this page?

Last updated on