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 TeamInboxWriter sendMessage

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

Overview

Concrete tool for persisting inter-agent messages to file-based inbox stores with atomic writes, file locking, and ownership guards, provided by the Agent Teams application.

Description

The TeamInboxWriter class writes messages to JSON inbox files (`inboxes/{member}.json`) under exclusive file locks. It supports attachment delivery (native and metadata-only), structured task references (`TaskRef[]`), and a `shouldStillWrite` ownership guard that runs inside the lock to prevent superseded launches from committing stale messages.

Key behaviors:

  • Inbox locking: `withInboxLock()` serializes all writes to the same inbox file, preventing interleaved writes.
  • Atomic writes: `atomicWriteInboxAsync()` writes the file atomically so a crash mid-write does not corrupt the inbox.
  • Group chat support: Validates group inbox rows via `assertValidGroupInboxRows()` and enforces a maximum inbox file size.
  • Ownership guard: The `shouldStillWrite` callback runs inside the lock, so a launch that has been superseded by a newer run can abort its write before commit.
  • Message identity: `getEffectiveInboxMessageId()` resolves message IDs using `randomUUID()` or deterministic fallbacks.

Usage

  • User → Teammate DM: Write to `inboxes/{member}.json` with `from: "user"`.
  • Teammate → User response: Write to `inboxes/user.json`.
  • Teammate → Teammate: Write to the recipient's inbox file.
  • OpenCode launch prompt: Write the lead prompt as a user message with `source: "user_sent"`.

Code Reference

Source Location

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

Signature

export interface SendInboxMessageOptions {
  shouldStillWrite?: () => boolean | Promise<boolean>;
}

export class TeamInboxWriter {
  async sendMessage(
    teamName: string,
    request: SendMessageRequest,
    options?: SendInboxMessageOptions
  ): Promise<SendMessageResult>;

  async sendNativeAttachmentMessage(
    teamName: string,
    request: SendNativeAttachmentMessageRequest,
    options?: SendInboxMessageOptions
  ): Promise<SendMessageResult>;
}

Import

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

I/O Contract

Inputs

Name Type Required Description
teamName string Yes Team identifier for resolving inbox directory
request.from string Yes Sender identity ('user' or member name)
request.to string Yes Recipient identity (member name or 'user')
request.member string Yes Inbox owner (same as 'to' for direct messages)
request.text string Yes Message body text
request.attachments AttachmentMeta[] No Attachment metadata (stripped of data before persistence)
request.taskRefs TaskRef[] No Structured task references for navigation
options.shouldStillWrite Promise<boolean> No Guard callback evaluated inside the lock before commit

Outputs

Name Type Description
return Promise<SendMessageResult> Contains messageId and delivery status
side effect File write Appends message to `~/.claude/teams/{teamName}/inboxes/{member}.json`

Usage Examples

User Direct Message to a Teammate

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

const writer = new TeamInboxWriter();

// User sends a direct message to agent "reviewer"
const result = await writer.sendMessage('my-team', {
  from: 'user',
  to: 'reviewer',
  member: 'reviewer',
  text: 'Please review the authentication module changes',
  source: 'user_sent',
  taskRefs: [{ taskId: 'task-123', displayId: '#5', teamName: 'my-team' }],
});

console.log(`Delivered message ${result.messageId}`);

Launch Prompt with Ownership Guard

// The shouldStillWrite guard runs inside the inbox lock.
// If a newer launch has taken over the team, the guard returns false
// and the write is aborted before commit.
const result = await writer.sendMessage(
  'my-team',
  {
    from: 'user',
    to: 'lead',
    member: 'lead',
    text: launchPrompt,
    source: 'user_sent',
  },
  {
    shouldStillWrite: () => currentLaunchId === activeLaunchId,
  }
);

Native Attachment Message

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

const writer = new TeamInboxWriter();

await writer.sendNativeAttachmentMessage('my-team', {
  from: 'user',
  to: 'developer',
  member: 'developer',
  text: 'Here is the test fixture file',
  attachments: [{ path: '/path/to/fixture.json', name: 'fixture.json' }],
  recipientRuntimeInstanceId: 'rt-instance-abc',
});

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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