Skip to content

fix: Telegram files panel "unknown agent id" + task session chatId mismatch breaks conversation - #3

Merged
Secret297-CODER-SOURCE merged 3 commits into
mainfrom
copilot/add-telegram-agent-communication
Mar 5, 2026
Merged

fix: Telegram files panel "unknown agent id" + task session chatId mismatch breaks conversation#3
Secret297-CODER-SOURCE merged 3 commits into
mainfrom
copilot/add-telegram-agent-communication

Conversation

Copilot AI commented Mar 5, 2026

Copy link
Copy Markdown

Two independent bugs: Telegram "Files" panel called the wrong WS endpoints (returning INVALID_REQUEST: unknown agent id), and task sessions stored username chatIds that never matched incoming numeric peer IDs, so the agent went silent after the opening message.

Summary

  • Problem 1: Telegram files panel called agents.files.list/get/set with Telegram plugin UUIDs. Those endpoints only resolve against the main OpenClaw config — every call returned INVALID_REQUEST: unknown agent id.
  • Problem 2: assignTask stored the raw chatId (e.g. "@worker_297") in the session. Telegram delivers incoming messages with numeric peer IDs ("123456789"). getTaskSession lookup never matched → agent sent opening message then stopped responding.
  • What changed: Added telegram.agent.getCoreFileContent endpoint; added loadTelegramAgentFiles/Content/save adapters that route through telegram.agent.*; wired Telegram files panel to use them. Added resolveEntityId tool to both agent types; assignTask now resolves username → numeric peer ID before persisting the session, with opening-message result as fallback.
  • Scope boundary: Main agent file handling, task session lifecycle, and behavior configs are untouched.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Related #

User-visible / Behavior Changes

  • Telegram "Files" panel now loads, edits, and saves core workspace files without error.
  • Task sessions assigned with a username (e.g. @user) now maintain a full conversation — subsequent replies are handled by the AI engine.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? YesresolveEntityId calls bot.api.getChat() (grammy) or client.getEntity() (gramjs) once at assignment time to resolve username → numeric ID. Read-only; gramjs caches entities so subsequent lookups are free.
  • Command/tool execution surface changed? Yes — new resolveEntityId tool on both agent types. Read-only (no sends or mutations).
  • Data access scope changed? No
  • Risk: BotAgent getChat(username) only works for supergroups/channels or users who have started the bot. If resolution fails, catch block falls through to original chatId and the opening-message fallback still attempts recovery — worst case is pre-fix behavior.

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: Node 22+
  • Integration/channel: Telegram Manager extension
  • Relevant config: TG_API_ID/TG_API_HASH set; at least one bot or userbot configured

Steps

Bug 1

  1. Telegram Manager → select agent → "Files" tab

Bug 2

  1. Call telegram.agent.assignTask with chatId: "@someuser" + openingMessage
  2. Have target user reply

Expected

  • Files panel loads workspace files
  • Agent responds to every subsequent message in the session

Actual

  • INVALID_REQUEST: unknown agent id in WS log; panel shows error
  • Agent silent after opening message

Evidence

  • Trace/log snippets — problem statement shows the exact INVALID_REQUEST pattern this eliminates
  • Failing test/log before + passing after — pnpm tsgo clean, pnpm check 0 new errors/warnings

Human Verification (required)

  • Verified scenarios: TypeScript types consistent end-to-end across both fix paths; isNumericTelegramId helper used uniformly in all three regex-guarded spots; filename allowlist in getCoreFileContent matches setCoreFile.
  • Edge cases checked: chatId already numeric → resolveEntityId skipped; opening message fails → session persisted with best-effort chatId; file missing → getCoreFileContent returns empty string so editor opens blank.
  • What you did not verify: live Telegram delivery; BotAgent getChat behavior for private users who haven't messaged the bot.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • Revert resolveEntityId cases from BotAgent/UserBotAgent callTool; revert assignTask block in TelegramPlugin.ts; restore three loadAgentFiles/loadAgentFileContent/saveAgentFile calls in app-render.ts.
  • Files: extensions/telegram-manager/src/TelegramPlugin.ts, src/agents/BotAgent.ts, src/agents/UserBotAgent.ts, ui/src/ui/app-render.ts, ui/src/ui/controllers/telegram.ts
  • Bad symptoms: telegram.agent.getCoreFiles 404/error → files panel blank; resolveEntityId throws unexpectedly at task assignment time.

Risks and Mitigations

  • Risk: resolveEntityId adds a Telegram API round-trip to assignTask for username-style chatIds.
    • Mitigation: fully caught and non-fatal; original chatId kept as fallback; gramjs entity cache makes repeat calls free.
  • Risk: BotAgent getChat(username) limited to chats the bot can access.
    • Mitigation: opening-message result extraction provides a second resolution path covering any reachable user.
Original prompt

Overview

Two related features need to be added to the extensions/telegram-manager extension and the ui/src/ui frontend:


Feature 1: Telegram Agent-to-Agent Communication with Master-Controlled Goals

Implement a system where a master Telegram agent can assign a goal/task to one or more sub-agents, and those sub-agents communicate with each other via Telegram to accomplish the goal.

Backend (extensions/telegram-manager/)

1. New types in extensions/telegram-manager/src/types.ts

Add the following new types:

// ─── Inter-agent communication ────────────────────────────────────────────────

export interface AgentCommunicationMessage {
  id: string;
  fromAgentId: string;
  fromAgentName: string;
  toAgentId: string;
  content: string;
  /** The shared mission/goal this message relates to */
  missionId: string;
  timestamp: string;
  /** Optional reply to another message */
  replyToId?: string;
}

export interface AgentMission {
  id: string;
  /** The master agent that created and owns this mission */
  masterAgentId: string;
  /** Human-readable title */
  title: string;
  /** The goal/instructions all participating agents receive */
  goal: string;
  /** Optional system prompt override for sub-agents */
  systemPrompt?: string;
  /** Agents participating in this mission */
  participantAgentIds: string[];
  status: "active" | "completed" | "paused";
  createdAt: string;
  completedAt?: string;
}

export interface CommunicationBehavior {
  type: "communication";
  enabled: boolean;
  /** Missions this agent participates in */
  activeMissionIds: string[];
}

Update BehaviorConfig union to include CommunicationBehavior.

2. New storage methods in extensions/telegram-manager/src/storage/TelegramStorage.ts

Add SQLite table agent_missions and agent_communication_messages with appropriate schema. Add CRUD methods:

  • saveMission(mission: AgentMission): void
  • getMission(id: string): AgentMission | null
  • getAllMissions(): AgentMission[]
  • updateMissionStatus(id: string, status: string, completedAt?: string): void
  • deleteMission(id: string): void
  • saveCommMessage(msg: AgentCommunicationMessage): void
  • getCommMessages(missionId: string, limit?: number): AgentCommunicationMessage[]

3. New AgentCommunicationBus in extensions/telegram-manager/src/agents/AgentCommunicationBus.ts

Create a new class that:

  • Holds a reference to AgentManager and TelegramStorage
  • Has method createMission(masterAgentId, title, goal, participantIds, systemPrompt?): AgentMission
  • Has method completeMission(missionId: string): void
  • Has method sendAgentMessage(fromAgentId, toAgentId, missionId, content): Promise<AgentCommunicationMessage>
    • This stores the message in DB
    • It calls agentManager.callTool(toAgentId, "sendMessage", ...) to actually deliver the message via Telegram from the sending agent to a special internal channel
    • It emits an event so the receiving agent can process it as part of its context
  • Has method getMissionMessages(missionId, limit?): AgentCommunicationMessage[]
  • Has method getMissions(): AgentMission[]
  • Has method getMission(id): AgentMission | null

4. Wire into AgentManager in extensions/telegram-manager/src/agents/AgentManager.ts

Add a commBus: AgentCommunicationBus field (initialized in init()). Expose methods:

  • createMission(...) → delegates to commBus
  • completeMission(missionId) → delegates to commBus
  • sendAgentMessage(fromAgentId, toAgentId, missionId, content) → delegates to commBus
  • getMissionMessages(missionId, limit?) → delegates to commBus
  • getMissions() → delegates to commBus
  • getMission(id) → delegates to commBus

5. New WebSocket methods in extensions/telegram-manager/src/TelegramPlugin.ts

Add these new cases to the switch in handleMessage:

telegram.mission.create      — params: { masterAgentId, title, goal, participantIds, systemPrompt? }
telegram.mission.list        — no required params
telegram.mission.get         — params: { missionId }
telegram.mission.complete    — params: { missionId }
telegram.mission.messages    — params: { missionId, limit? }
telegram.agent.sendMessage_to_agent — params: { fromAgentId, toAgentId, missionId, content }

6. Register new methods in extensions/telegram-manager/index.ts

Add all the new telegram.mission.* and telegram.agent.sendMessage_to_agent methods to the TELEGRAM_METHODS array.

Also extend the telegramManagerTool description to document the new mission/communication actions.


Feature 2: Core Files Panel in Telegram Manager UI

The main OpenClaw agent UI has a "Core Files" panel (shown in the screenshot image1) that displays workspace files like AGENTS.md, SOUL.md, TOOLS.md, IDENTITY.md, USER.md, HEARTBEAT.md, BOOTSTRAP.md, and MEMORY.md. Each Telegram agent should have a similar Core Files panel in the Telegr...

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Telegram agent-to-agent communication feature feat: Telegram agent-to-agent missions + Core Files panel for telegram-manager Mar 5, 2026
…lution

- agents.files.list "unknown agent id": add telegram.agent.getCoreFileContent WS method;
  add loadTelegramAgentFiles/loadTelegramAgentFileContent/saveTelegramAgentFile adapters;
  fix app-render.ts Telegram files panel to use Telegram-specific endpoints

- One-message-no-conversation: add resolveEntityId tool to BotAgent + UserBotAgent;
  in TelegramPlugin.assignTask resolve username → numeric peer ID before storing session;
  extract resolved ID from opening-message result as belt-and-suspenders fallback

Co-authored-by: Secret297-CODER-SOURCE <73541046+Secret297-CODER-SOURCE@users.noreply.github.com>
Copilot AI changed the title feat: Telegram agent-to-agent missions + Core Files panel for telegram-manager fix: Telegram files panel "unknown agent id" + task session chatId mismatch breaks conversation continuity Mar 5, 2026
Copilot AI changed the title fix: Telegram files panel "unknown agent id" + task session chatId mismatch breaks conversation continuity fix: Telegram files panel "unknown agent id" + task session chatId mismatch breaks conversation Mar 5, 2026
@Secret297-CODER-SOURCE
Secret297-CODER-SOURCE merged commit eb782c0 into main Mar 5, 2026
1 check passed
@Secret297-CODER-SOURCE
Secret297-CODER-SOURCE deleted the copilot/add-telegram-agent-communication branch March 5, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants