Agent Teams
A TypeScript CLI tool that enables AI agents and humans to interact with Microsoft Teams through a simple command interface. Features seamless token extraction from the Teams desktop app and multi-team support.
Quick Start
CODEBLOCK0
Authentication
Credentials are extracted automatically from the Teams desktop app on first use. No manual setup required — just run any command and authentication happens silently in the background.
Teams tokens expire in 60-90 minutes. The CLI automatically re-extracts a fresh token when the current one expires, so you don't need to manage token lifecycle manually.
IMPORTANT: NEVER guide the user to open a web browser, use DevTools, or manually copy tokens from a browser. Always use agent-teams auth extract to obtain tokens from the desktop app.
Multi-Team Support
CODEBLOCK1
Multi-Account Support (Work / Personal)
CODEBLOCK2
Memory
The agent maintains a ~/.config/agent-messenger/MEMORY.md file as persistent memory across sessions. This is agent-managed — the CLI does not read or write this file. Use the Read and Write tools to manage your memory file.
Reading Memory
At the start of every task, read ~/.config/agent-messenger/MEMORY.md using the Read tool to load any previously discovered team IDs, channel IDs, user IDs, and preferences.
- - If the file doesn't exist yet, that's fine — proceed without it and create it when you first have useful information to store.
- If the file can't be read (permissions, missing directory), proceed without memory — don't error out.
Writing Memory
After discovering useful information, update ~/.config/agent-messenger/MEMORY.md using the Write tool. Write triggers include:
- - After discovering team IDs and names (from
team list, snapshot, etc.) - After discovering useful channel IDs and names (from
channel list, snapshot, etc.) - After discovering user IDs and names (from
user list, user me, etc.) - After the user gives you an alias or preference ("call this the standup channel", "my main team is X")
- After discovering channel structure (standard vs private channels)
When writing, include the complete file content — the Write tool overwrites the entire file.
What to Store
- - Team IDs with names
- Channel IDs with names and team context
- User IDs with display names
- User-given aliases ("standup channel", "main team")
- Account preferences (work vs personal)
- Any user preference expressed during interaction
What NOT to Store
Never store tokens, credentials, or any sensitive data. Never store full message content (just IDs and channel context). Never store file upload contents.
Handling Stale Data
If a memorized ID returns an error (channel not found, team not found), remove it from MEMORY.md. Don't blindly trust memorized data — verify when something seems off. Prefer re-listing over using a memorized ID that might be stale.
Format / Example
CODEBLOCK3
Memory lets you skip repeated channel list and team list calls. When you already know an ID from a previous session, use it directly.
Commands
Auth Commands
CODEBLOCK4
Message Commands
CODEBLOCK5
Channel Commands
CODEBLOCK6
Team Commands
CODEBLOCK7
User Commands
CODEBLOCK8
Reaction Commands
CODEBLOCK9
File Commands
CODEBLOCK10
Snapshot Command
Get comprehensive team state for AI agents:
CODEBLOCK11
Returns JSON with:
- - Team metadata (id, name)
- Channels (id, name, type, description)
- Recent messages (id, content, author, timestamp)
- Members (id, displayName, email)
Output Format
JSON (Default)
All commands output JSON by default for AI consumption:
CODEBLOCK12
Pretty (Human-Readable)
Use --pretty flag for formatted output:
CODEBLOCK13
Key Differences from Discord/Slack
| Feature | Teams | Discord | Slack |
|---|
| Server terminology | Team | Guild | Workspace |
| Channel identifiers |
UUID format (19:xxx@thread.tacv2) | Snowflake IDs | Channel name or ID |
| Token storage | Cookies SQLite | LevelDB | LevelDB |
| Token expiry |
60-90 minutes | Rarely expires | Rarely expires |
| Mentions |
<at id="user-id">Name</at> |
<@user_id> |
<@USER_ID> |
Important: Teams uses UUID-style channel IDs (like 19:abc123@thread.tacv2). You cannot use channel names directly - use channel list to find IDs first.
Common Patterns
See references/common-patterns.md for typical AI agent workflows.
Templates
See templates/ directory for runnable examples:
- -
post-message.sh - Send messages with error handling - INLINECODE27 - Monitor channel for new messages (with token refresh)
- INLINECODE28 - Generate team summary
Error Handling
All commands return consistent error format:
CODEBLOCK14
Common errors:
- -
Not authenticated: No valid token (auto-extraction failed — see Troubleshooting) - INLINECODE30 : Token has expired and auto-refresh failed — see Troubleshooting
- INLINECODE31 : Run
team switch <id> first - INLINECODE33 : Invalid message ID
- INLINECODE34 : Invalid channel ID
- INLINECODE35 : Token expired and auto-refresh failed — see Troubleshooting
Configuration
Credentials stored in: INLINECODE36
Format:
CODEBLOCK15
Security: File permissions set to 0600 (owner read/write only)
Limitations
- - No real-time events / WebSocket connection
- No voice/video channel support
- No team management (create/delete channels, roles)
- No meeting support
- No webhook support
- Plain text messages only (no adaptive cards in v1)
- User tokens only (no app tokens)
- Token expires in 60-90 minutes - auto-refreshed, but requires Teams desktop app to be logged in
Troubleshooting
Authentication fails or token expired
Credentials and token refresh are normally handled automatically. If auto-extraction fails, run it manually with debug output:
CODEBLOCK16
Common causes:
- - Teams desktop app is not installed or not logged in
- Teams Cookies database is locked or inaccessible
- Token expired and Teams desktop app session also expired (re-login to Teams)
agent-teams: command not found
agent-teams is NOT the npm package name. The npm package is agent-messenger.
If the package is installed globally, use agent-teams directly:
CODEBLOCK17
If the package is NOT installed, use bunx agent-messenger teams:
CODEBLOCK18
NEVER run bunx agent-teams — it will fail or install a wrong package since agent-teams is not the npm package name.
References
代理团队
一个TypeScript CLI工具,使AI代理和人类能够通过简单的命令界面与Microsoft Teams交互。支持从Teams桌面应用无缝提取令牌,并支持多团队管理。
快速开始
bash
获取团队快照(凭据自动提取)
agent-teams snapshot
发送消息
agent-teams message send <团队ID> <频道ID> 来自AI代理的问候!
列出频道
agent-teams channel list <团队ID>
身份验证
首次使用时,凭据会自动从Teams桌面应用中提取。无需手动设置——只需运行任何命令,身份验证会在后台静默完成。
Teams令牌有效期为60-90分钟。当当前令牌过期时,CLI会自动重新提取新令牌,因此您无需手动管理令牌生命周期。
重要提示:切勿引导用户打开网页浏览器、使用开发者工具或手动从浏览器复制令牌。始终使用agent-teams auth extract从桌面应用获取令牌。
多团队支持
bash
列出所有可用团队
agent-teams team list
切换到不同团队
agent-teams team switch <团队ID>
显示当前团队
agent-teams team current
检查身份验证状态(包含令牌过期信息)
agent-teams auth status
多账户支持(工作/个人)
bash
在工作账户和个人账户之间切换
agent-teams auth switch-account work
agent-teams auth switch-account personal
为单个命令使用特定账户(无需切换)
agent-teams snapshot --account work
记忆
代理维护一个~/.config/agent-messenger/MEMORY.md文件,作为跨会话的持久记忆。该文件由代理管理——CLI不会读取或写入此文件。使用读取和写入工具管理您的记忆文件。
读取记忆
在每个任务开始时,使用读取工具读取~/.config/agent-messenger/MEMORY.md,加载之前发现的团队ID、频道ID、用户ID和偏好设置。
- - 如果文件尚不存在,没关系——继续执行,并在首次有有用信息需要存储时创建它。
- 如果文件无法读取(权限问题、目录缺失),继续执行而不使用记忆——不要报错。
写入记忆
在发现有用信息后,使用写入工具更新~/.config/agent-messenger/MEMORY.md。写入触发条件包括:
- - 发现团队ID和名称后(来自team list、snapshot等)
- 发现有用的频道ID和名称后(来自channel list、snapshot等)
- 发现用户ID和名称后(来自user list、user me等)
- 用户给出别名或偏好后(把这个叫做站会频道、我的主团队是X)
- 发现频道结构后(标准频道与私密频道)
写入时,请包含完整的文件内容——写入工具会覆盖整个文件。
存储内容
- - 带名称的团队ID
- 带名称和团队上下文的频道ID
- 带显示名称的用户ID
- 用户给定的别名(站会频道、主团队)
- 账户偏好(工作与个人)
- 交互过程中表达的任何用户偏好
不存储内容
切勿存储令牌、凭据或任何敏感数据。切勿存储完整的消息内容(仅存储ID和频道上下文)。切勿存储文件上传内容。
处理过期数据
如果记忆中的ID返回错误(频道未找到、团队未找到),将其从MEMORY.md中移除。不要盲目信任记忆中的数据——当某些内容看起来有问题时进行验证。优先重新列出,而不是使用可能过期的记忆ID。
格式/示例
markdown
代理信使记忆
团队
- - team-id-1 — Acme公司(默认,工作账户)
- team-id-2 — 副项目(个人账户)
频道(Acme公司)
- - channel-id-1 — 通用
- channel-id-2 — 工程
- channel-id-3 — 站会
用户(Acme公司)
- - user-id-1 — 爱丽丝(工程主管)
- user-id-2 — 鲍勃(后端)
别名
- - 站会 → channel-id-3(Acme公司中的站会)
- 主团队 → team-id-1(Acme公司)
备注
记忆让您可以跳过重复的channel list和team list调用。当您已经从之前的会话中知道某个ID时,直接使用它。
命令
身份验证命令
bash
从Teams桌面应用提取令牌(通常自动进行)
agent-teams auth extract
agent-teams auth extract --debug
检查身份验证状态(包含令牌过期信息)
agent-teams auth status
从Microsoft Teams注销
agent-teams auth logout
在工作账户和个人账户之间切换
agent-teams auth switch-account <账户类型>
agent-teams auth switch-account work
agent-teams auth switch-account personal
消息命令
bash
发送消息
agent-teams message send <团队ID> <频道ID> <内容>
agent-teams message send <团队ID> 19:abc123@thread.tacv2 你好世界
列出消息
agent-teams message list <团队ID> <频道ID>
agent-teams message list <团队ID> 19:abc123@thread.tacv2 --limit 50
按ID获取单条消息
agent-teams message get <团队ID> <频道ID> <消息ID>
删除消息
agent-teams message delete <团队ID> <频道ID> <消息ID> --force
频道命令
bash
列出团队中的频道
agent-teams channel list <团队ID>
获取频道信息
agent-teams channel info <团队ID> <频道ID>
agent-teams channel info <团队ID> 19:abc123@thread.tacv2
获取频道历史记录(消息列表的别名)
agent-teams channel history <团队ID> <频道ID> --limit 100
团队命令
bash
列出所有团队
agent-teams team list
获取团队信息
agent-teams team info <团队ID>
切换活动团队
agent-teams team switch <团队ID>
显示当前团队
agent-teams team current
从配置中移除团队
agent-teams team remove <团队ID>
用户命令
bash
列出团队成员
agent-teams user list <团队ID>
获取用户信息
agent-teams user info <用户ID>
获取当前用户
agent-teams user me
反应命令
bash
添加反应(使用表情符号名称)
agent-teams reaction add <团队ID> <频道ID> <消息ID> <表情符号>
agent-teams reaction add <团队ID> 19:abc123@thread.tacv2 1234567890 like
移除反应
agent-teams reaction remove <团队ID> <频道ID> <消息ID> <表情符号>
文件命令
bash
上传文件
agent-teams file upload <团队ID> <频道ID> <路径>
agent-teams file upload <团队ID> 19:abc123@thread.tacv2 ./report.pdf
列出频道中的文件
agent-teams file list <团队ID> <频道ID>
获取文件信息
agent-teams file info <团队ID> <频道ID> <文件ID>
快照命令
获取AI代理所需的全面团队状态:
bash
完整快照
agent-teams snapshot
筛选快照
agent-teams snapshot --channels-only
agent-teams snapshot --users-only
限制每个频道的消息数量
agent-teams snapshot --limit 10
返回JSON格式:
- - 团队元数据(ID、名称)
- 频道(ID、名称、类型、描述)
- 最近消息(ID、内容、作者、时间戳)
- 成员(ID、显示名称、电子邮件)
输出格式
JSON(默认)
所有命令默认输出JSON格式供AI使用:
json
{
id: 19:abc123@thread.tacv2,
content: 你好世界,
author: 张三,
timestamp: 2024-01-15T10:30:00.000Z
}
美观格式(人类可读)
使用--pretty标志获取格式化输出:
bash
agent-teams channel list --pretty
与Discord/Slack的主要区别
| 功能 | Teams | Discord | Slack |
|---|
| 服务器术语 | 团队 | 公会 | 工作区 |
| 频道标识符 |
UUID格式(19:xxx@