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 drawAgents

From Leeroopedia
Knowledge Sources
Domains Visualization, Rendering
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete tool for rendering agent (member and lead) graph nodes to an HTML canvas with semantic zoom and focus-based opacity, provided by the Agent Teams agent-graph package.

Description

The drawAgents() function renders all member and lead nodes to a 2D canvas context. It uses semantic zoom to simplify rendering at low zoom levels, applies focus-based opacity to dim non-focused nodes, and derives colors from node visual state.

Key behaviors:

  • Node kind filtering: Only 'member' and 'lead' nodes are rendered; task nodes are handled by `drawTasks`.
  • Semantic zoom: At zoom < 0.19, rendering simplifies (less detail, hierarchy cards may be skipped).
  • Focus opacity: When `focusNodeIds` is set, nodes outside the focus set have reduced opacity via `getFocusOpacity()`.
  • Minimum visibility: Nodes with opacity below `MIN_VISIBLE_OPACITY` are skipped entirely.
  • State coloring: Node color comes from `node.color` or `getStateColor(node.state)` for state-based coloring (spawning, running, idle, error).
  • Selection/hover: Selected and hovered nodes receive additional visual effects (glow, highlight ring).
  • Error highlight: Nodes with `exceptionTone === 'error'` receive special error highlighting.
  • Card hierarchy: Nodes with `cardSize` (hierarchy cards) use `getHierarchyCardOpacity` and `getGraphSemanticZoomLevel` for overview-level culling.

Usage

  • Canvas render loop: Call `drawAgents()` once per animation frame after the simulation tick, passing the current nodes and interaction state.

Code Reference

Source Location

  • Repository: agent-teams
  • File: packages/agent-graph/src/canvas/draw-agents.ts

Signature

export function drawAgents(
  ctx: CanvasRenderingContext2D,
  nodes: GraphNode[],
  time: number,
  selectedId: string | null,
  hoveredId: string | null,
  focusNodeIds?: ReadonlySet<string> | null,
  zoom?: number
): void;

Import

import { drawAgents } from '@agent-graph/canvas/draw-agents';

I/O Contract

Inputs

Name Type Required Description
ctx CanvasRenderingContext2D Yes Canvas 2D rendering context
nodes GraphNode[] Yes All graph nodes (only member/lead are rendered)
time number Yes Animation time for effects
selectedId null Yes Currently selected node ID
hoveredId null Yes Currently hovered node ID
focusNodeIds null No Focused node IDs for opacity dimming
zoom number No (default 1) Current zoom level for semantic zoom

Outputs

Name Type Description
return void Renders hexagonal agent nodes to canvas

Usage Examples

Rendering in Animation Loop

import { drawAgents } from '@agent-graph/canvas/draw-agents';
import { drawEdges } from '@agent-graph/canvas/draw-edges';
import { drawTasks } from '@agent-graph/canvas/draw-tasks';

function renderFrame(ctx, simState, interaction, camera) {
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.save();
  ctx.translate(camera.x, camera.y);
  ctx.scale(camera.zoom, camera.zoom);

  // Draw layers in order: edges → tasks → agents
  drawEdges(ctx, simState.edges, simState.nodes);
  drawTasks(ctx, simState.nodes, simState.time, interaction.selectedId);
  drawAgents(
    ctx,
    simState.nodes,
    simState.time,
    interaction.selectedId,
    interaction.hoveredId,
    interaction.focusNodeIds,
    camera.zoom
  );

  ctx.restore();
}

With Focus Highlighting

// When the user selects a member, focus on that member's subgraph
const focusIds = new Set(['member-1', 'task-1', 'task-2']);
drawAgents(ctx, nodes, time, 'member-1', null, focusIds, 1.0);
// Non-focused agents will be dimmed

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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