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.
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.
| Name | Kind | What it does |
|---|---|---|
OWNER | constant | Default escalation target string for roles ("owner"). |
TeamRefused | exception | Typed refusal with stable code and operator-safe detail. |
Permissions | dataclass | Allowed tools, effects, approval-required effects, and delegate targets per role. |
RoleSpec | dataclass | AgentRole plus permissions, knowledge partitions, escalation, and identity_hash. |
DelegationPolicy | dataclass | Per-round admission cap (max_parallel), hop limit, per-specialist Budget shares, max_attempts. |
TeamSpec | dataclass | Team id, version, coordinator, specialists, policy, owner principal, team Budget. |
DelegationRequest | dataclass | Bounded delegation proposal; authority is checked, never narrowed. |
SpecialistOutcome | dataclass | Specialist harness result: kind, refs, usage, nested delegations, proposed effects. |
DelegationIssue | dataclass | Failed or stalled attempt record for receipts. |
DelegationReceipt | dataclass | Status, attempts, output refs, usage, verdict, issues, pending effect ids. |
ConsolidationItem | dataclass | One consolidation line with citation refs. |
ConsolidationDraft | dataclass | Title and items for a proposed report. |
CoordinatorDecision | dataclass | Coordinator turn: delegations and/or consolidation plus usage. |
RoundView | dataclass | What the coordinator harness sees: prior receipts and refusals, not raw outputs. |
TeamHarness | protocol | Receives keyword arguments team and view. Returns a CoordinatorDecision or awaitable. |
SpecialistHarness | protocol | Receives keyword arguments role, request, and attempt. Returns a SpecialistOutcome or awaitable. |
admit | function | Permission, hop, budget, duplicate, and per-round admission checks. |
check_permissions | function | Same permission rules as admission; raises TeamRefused on violation. |
DelegationRunner | class | Runs admitted delegations for one round via Supervisor; builds receipts from store. |
OutcomeVerifier | class | Wraps an application check function into a goal Verifier. |
TeamWorkflow | class | Multi-round loop: journal coordinator decisions, admit, run, consolidate. |
TeamResult | dataclass | Finished or paused run: receipts, refusals, optional report, needs_input questions. |
StepResult | dataclass | step returns the next RoundState and may also return a TeamResult; a needs_input result is not terminal. |
RoundState | dataclass | Durable JSON-friendly state between rounds (refusals, which rounds ran). |
PlanScope | dataclass | Optional bounds on coordinator proposals for roles and record: input refs (outside_plan refusal). |
Consolidator | class | Runs check_consolidation and writes audit rows. |
ConsolidationReport | dataclass | Accepted report with digest and cited delegation ids. |
check_consolidation | function | Citation validation; refuses item_without_ref or unknown_ref. |
citable | function | Builds allowed ref map from verified receipts and input refs. |
progress_view | function | A round ProgressSnapshot plus decision items for pending definition approvals, and blockers for effects awaiting approval and stalled unverified delegations. |
DefinitionStore | class | Versioned role instruction files with human approval for activation. |
ActiveDefinition | dataclass | One active version: digest, text, parsed AgentDefinition. |
parse_definition | function | Parse skillpacks markdown; invalid frontmatter → definition_invalid. |
validate_definition | function | The 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_lines | function | Line-level diff for approval preview. |
request_from_json | function | Decode stored HumanRequest for definition proposals. |
ExecutionContext | dataclass | Scoped team, delegation, attempt, run for link registration. |
execution_context | context manager | Bind current execution for specialist/host code. |
current_execution | function | Read bound ExecutionContext or None. |
ExecutionLink | dataclass | Opaque native_run, sandbox, or artifact reference plus optional digest. |
ExecutionLinks | class | Register links as audit rows validated against persisted attempts. |
ExecutionReadback | class | Join attempts, run status, verdicts, and registered links. |
DelegationExecution | dataclass | Readback view for one delegation. |
AttemptExecution | dataclass | One attempt with links, verdict JSON, and missing kinds. |
LinkObservation | dataclass | Resolver result: observed, missing, unverified, or conflict. |
ResolvedLink | dataclass | Link paired with observation. |
RoleUsageLedger | class | Record UsageReceipt rows per role; optional JSONL mirror after commit. |
RoleUsage | dataclass | Aggregated counts and tokens; tracks unknown token receipts. |
iso_week | function | Default usage period label from UTC time. |
ActivityFeed | class | Paged team audit joined with RunStore status. |
ActivityPage | dataclass | One page of ActivityRow plus cursor and more flag. |
ActivityRow | dataclass | Single audit event with tokens and detail JSON. |
open_team_tables | function | Create 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):
| Concern | Packages |
|---|---|
| Harness core | recohut_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 approval | recohut_kit.human.checkpoints, recohut_kit.human.contracts, recohut_kit.human.preview |
| Roles and definitions | recohut_kit.multi_agent.roles, recohut_kit.skillpacks.contracts |
| JSON and usage | recohut_kit.json, recohut_kit.usage |
| Safety and I/O | recohut_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_permissionsandadmitreject requests that exceed declared tools, effects, partitions, hops, or budget share. The coordinator cannot be a delegation target. max_parallelis not concurrency. It limits admissions per round;DelegationRunnerawaits 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_approvalrows. - 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 viaunverified_delegationon the report id. - Coordinator proposals start at hop 1 from the coordinator role; otherwise
permission_denied. needs_inputoutcomes end a delegation without spending retry budget the same way as completion for verification shape; the workflow can returnreason="needs_input"with question payloads for the host.- Definition changes need
HumanRequestapproval:activatematches proposed digest and base version exactly.activatebefore approval raisesdefinition_unapproved; text whose digest differs from the approved digest raisesdefinition_stale. - Recovery binding is frozen. The binding covers team identity, scope, input refs, execution version, verifier names, and the round limit. Bump
execution_versionwhen 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.
ExecutionReadbacklistsmissingfor absent kinds or non-observed resolver status; without a resolver, links areunverified. - Workflow concurrency.
TeamWorkflowuses 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_completenessdocuments 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