Implementation:777genius Agent teams ai TeamGraphAdapter adapt
| Knowledge Sources | |
|---|---|
| Domains | Visualization, Team_Management |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for transforming live team state into graph data structures for canvas visualization, provided by the Agent Teams application.
Description
The TeamGraphAdapter class converts heterogeneous team state (members, tasks, messages, provisioning progress) into a GraphDataPort — a uniform structure of nodes, edges, and particles suitable for canvas rendering. The adapter is stateful: it tracks seen message IDs and comment counts to emit particle effects only for genuinely new activity, not for data already rendered on previous calls.
Key behaviors:
- Stateful particle emission: Maintains `#seenMessageIds` and `#seenCommentCounts` to detect new activity between calls. New messages generate particles; previously seen messages do not.
- Team-change reset: When the team name changes, all tracking state is reset to avoid cross-team particle pollution.
- Duplicate owner detection: Detects duplicate stable owner IDs and returns an empty result with an error log, preventing rendering of corrupted state.
- Multi-source enrichment: Merges spawn statuses, lead activity, pending approvals, tool activity, provisioning progress, and slot assignments into node visual state.
- Layout mode support: Accepts a `layoutMode` parameter ('grid' or 'force') to control how task nodes are positioned.
Usage
- Real-time graph rendering: Call `adapt()` on every team state update to produce the latest graph snapshot for canvas drawing.
- Particle effects: The adapter automatically generates particles for new messages; no manual diffing is needed.
- Multiple enrichments: Pass optional parameters (spawnStatuses, leadActivity, provisioningProgress, etc.) to enrich node visual state.
Code Reference
Source Location
- Repository: agent-teams
- File: src/features/agent-graph/renderer/adapters/TeamGraphAdapter.ts
Signature
export class TeamGraphAdapter {
static create(): TeamGraphAdapter;
adapt(
teamData: TeamGraphData | null,
teamName: string,
spawnStatuses?: Record<string, MemberSpawnStatusEntry>,
leadActivity?: LeadActivityState,
leadContext?: LeadContextUsage,
pendingApprovalAgents?: Set<string>,
activeTools?: Record<string, Record<string, ActiveToolCall>>,
finishedVisible?: Record<string, Record<string, ActiveToolCall>>,
toolHistory?: Record<string, ActiveToolCall[]>,
commentReadState?: Record<string, unknown>,
provisioningProgress?: TeamProvisioningProgress | null,
memberSpawnSnapshot?: MemberSpawnStatusesSnapshot,
slotAssignments?: Record<string, GraphOwnerSlotAssignment>,
layoutMode?: GraphLayoutMode,
gridOwnerOrder?: readonly string[],
activeTaskLogActivity?: Record<string, true>,
text?: TeamGraphAdapterText,
commentReadContextId?: string
): GraphDataPort;
}
Import
import { TeamGraphAdapter } from '@features/agent-graph/renderer/adapters/TeamGraphAdapter';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| teamData | null | Yes | Team state with members, tasks, messages |
| teamName | string | Yes | Current team name (must match teamData.teamName) |
| spawnStatuses | Record | No | Per-member spawn status entries |
| leadActivity | LeadActivityState | No | Lead process activity state |
| pendingApprovalAgents | Set<string> | No | Agents awaiting approval |
| provisioningProgress | null | No | Live provisioning progress |
| slotAssignments | Record | No | Owner slot geometry for layout |
| layoutMode | GraphLayoutMode | No (default 'grid') | Layout mode: 'grid' or 'force' |
Outputs
| Name | Type | Description |
|---|---|---|
| return | GraphDataPort | Graph snapshot with nodes, edges, particles, teamName, isAlive |
| GraphDataPort.nodes | GraphNode[] | Member, lead, and task nodes with positions and visual state |
| GraphDataPort.edges | GraphEdge[] | Connections between members and tasks |
| GraphDataPort.particles | GraphParticle[] | Particles for new messages (delta from previous call) |
Usage Examples
Basic Graph Adaptation
import { TeamGraphAdapter } from '@features/agent-graph/renderer/adapters/TeamGraphAdapter';
const adapter = TeamGraphAdapter.create();
// Adapt team data into graph structure for rendering
const graphData = adapter.adapt(
teamData,
'my-team',
spawnStatuses,
leadActivity,
undefined,
pendingApprovalAgents
);
// Pass to canvas rendering
drawAgents(ctx, graphData.nodes, time, selectedId, hoveredId);
drawEdges(ctx, graphData.edges, graphData.nodes);
With Provisioning Progress
// During team launch, pass provisioning progress to show
// live status on the graph
const graphData = adapter.adapt(
teamData,
'my-team',
spawnStatuses,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
provisioningProgress // Shows "spawning", "bootstrapping", "ready"
);
// Particles are automatically generated for new messages
// since the last adapt() call
console.log(`Particles: ${graphData.particles.length}`);
Handling Team Switch
// When switching teams, the adapter automatically resets its
// seen-message tracking — no manual reset needed
const graph1 = adapter.adapt(teamDataA, 'team-a');
// ... later ...
const graph2 = adapter.adapt(teamDataB, 'team-b');
// graph2.particles contains ALL messages in team-b (treated as new)