Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:777genius Agent teams ai TeamProvisioningService launchTeam

From Leeroopedia
Knowledge Sources
Domains Process_Management, Team_Management
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for launching and provisioning multi-agent team CLI processes across Claude, Codex, and OpenCode runtimes, provided by the Agent Teams application.

Description

The TeamProvisioningService class is the stable facade for team lifecycle operations. It extends the OpenCode aggregate primary facade and delegates provider-specific provisioning to focused delegate layers. The service manages launch admission control (tracking pending launches that consume shared HTTP bridge resources), lead runtime restart assessment, OpenCode launch prompt delivery, and team change event emission.

Key behaviors:

  • Admission control: `withLaunchAdmission` wraps launch operations to track pending launches; `hasLiveOpenCodeMcpConsumers()` checks if any active run or pending launch is using the app-owned HTTP bridge.
  • Lead runtime restart: `assessLeadRuntimeRestart()` checks whether a running lead can be hot-swapped or must be relaunched; `restartLeadRuntime()` performs the swap.
  • OpenCode launch prompt delivery: Queues the lead prompt as a normal user inbox message so the inbox relay delivers it under the standard user-reply contract.
  • Runtime failure observation: A boundary layer observes and reports lead runtime failures to registered observers.

Usage

  • New team launch: Call `launchTeam()` with a `TeamLaunchRequest` containing team name, members, and provider config.
  • Runtime restart: Call `assessLeadRuntimeRestart()` then `restartLeadRuntime()` to hot-swap provider/model/effort on a running Claude or Codex team.
  • OpenCode launch prompt: Call `deliverOpenCodeLaunchPromptToLead()` to queue the initial prompt for the lead via inbox.
  • Shutdown: Call `killTeamProcessAndWait()` (from `TeamProvisioningRunProgress`) to terminate the process tree.

Code Reference

Source Location

  • Repository: agent-teams
  • File: src/main/services/team/TeamProvisioningService.ts

Signature

export class TeamProvisioningService extends TeamProvisioningOpenCodeAggregatePrimaryFacade {
  constructor(
    configReader?: TeamConfigReader,
    inboxReader?: TeamInboxReader,
    membersMetaStore?: TeamMembersMetaStore,
    sentMessagesStore?: TeamSentMessagesStore,
    mcpConfigBuilder?: TeamMcpConfigBuilder,
    teamMetaStore?: TeamMetaStore,
    inboxWriter?: TeamInboxWriter,
    openCodeTaskLogAttributionStore?: OpenCodeTaskLogAttributionStore,
    memberWorktreeManager?: TeamMemberWorktreeManager,
    attachmentStore?: TeamAttachmentStore,
    groupChats?: ProvisioningGroupChatCallbacks,
    resolveOpenCodeInputDeclaration?: ResolveOpenCodeInputDeclaration,
    memberGatewayRuntimeSeams?: MemberGatewayRuntimeSeams | null
  );

  // Admission control
  hasLiveOpenCodeMcpConsumers(): boolean;
  setLaunchAdmissionGuard(guard: () => void): void;

  // Team change events
  setTeamChangeEmitter(emitter: ((event: TeamChangeEvent) => void) | null): void;

  // Runtime failure observation
  setRuntimeRecoveryFailureObserver(
    observer: ((failure: LeadRuntimeFailureObservation) => void) | null
  ): void;

  // OpenCode launch prompt delivery
  async deliverOpenCodeLaunchPromptToLead(input: {
    teamName: string;
    leadName: string;
    prompt: string;
    isLaunchStillCurrent: () => boolean;
  }): Promise<void>;

  // Lead runtime restart (Claude/Codex only)
  async assessLeadRuntimeRestart(input: {
    teamName: string;
    providerId: Exclude<TeamProviderId, 'opencode'>;
    model: string | null;
    effort: EffortLevel | null;
  }): Promise<
    { outcome: 'ready'; token: string } | { outcome: 'busy' } | { outcome: 'relaunch_required' }
  >;

  async restartLeadRuntime(input: {
    teamName: string;
    expectedRunId: string;
    before: { providerId: Exclude<TeamProviderId, 'opencode'>; model: string | null; effort: EffortLevel | null };
    after: { providerId: Exclude<TeamProviderId, 'opencode'>; model: string | null; effort: EffortLevel | null };
  }): Promise<void>;
}

Import

import { TeamProvisioningService } from '@main/services/team/TeamProvisioningService';

I/O Contract

Inputs

Name Type Required Description
teamName string Yes Unique team identifier
members MemberConfig[] Yes Team member definitions with name, role, provider
providerId TeamProviderId Yes Runtime provider: 'claude', 'codex', or 'opencode'
model null No Model selection for the team
effort null No Effort level for the lead runtime

Outputs

Name Type Description
return (assessLeadRuntimeRestart) Promise<AssessResult> 'ready' with run token, 'busy', or 'relaunch_required'
return (restartLeadRuntime) Promise<void> Resolves when the lead runtime has been swapped
return (deliverOpenCodeLaunchPromptToLead) Promise<void> Resolves when prompt is queued in lead inbox
side effect Process handle Spawns CLI process for the team lead

Usage Examples

Assessing and Restarting Lead Runtime

import { TeamProvisioningService } from '@main/services/team/TeamProvisioningService';

const service = new TeamProvisioningService();

// Check if we can hot-swap the model on a running Claude team
const assessment = await service.assessLeadRuntimeRestart({
  teamName: 'my-team',
  providerId: 'claude',
  model: 'claude-sonnet-4-20250514',
  effort: 'high',
});

if (assessment.outcome === 'ready') {
  // Safe to restart with the new settings
  await service.restartLeadRuntime({
    teamName: 'my-team',
    expectedRunId: assessment.token,
    before: { providerId: 'claude', model: null, effort: null },
    after: { providerId: 'claude', model: 'claude-sonnet-4-20250514', effort: 'high' },
  });
} else if (assessment.outcome === 'relaunch_required') {
  // Must kill and relaunch from scratch
  console.log('Full relaunch required');
}

Delivering OpenCode Launch Prompt

// OpenCode leads read inbox messages (not stdin), so the launch prompt
// is queued as a user message that the relay delivers
await service.deliverOpenCodeLaunchPromptToLead({
  teamName: 'my-opencode-team',
  leadName: 'lead',
  prompt: 'Review the codebase and create tasks for the team',
  isLaunchStillCurrent: () => currentLaunchId === activeLaunchId,
});

Checking OpenCode MCP Consumers

// Before shutting down the app-owned HTTP bridge, check if any
// team is actively using it
if (service.hasLiveOpenCodeMcpConsumers()) {
  console.warn('Cannot shut down: OpenCode teams are using the HTTP bridge');
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment