Skip to content

docs: trim agent skills for token efficiency and extract Slack reference#126

Closed
benvinegar wants to merge 3 commits into
mainfrom
ben/audit-agent-skills
Closed

docs: trim agent skills for token efficiency and extract Slack reference#126
benvinegar wants to merge 3 commits into
mainfrom
ben/audit-agent-skills

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

Audit and optimize all pi agent skills based on Anthropic skill authoring best practices. Key principles applied: only add context the model doesn't already have, use progressive disclosure, keep SKILL.md under 500 lines.

control-agent/SKILL.md (476 → 303 lines, -36%)

  • Removed duplicate sentry agent section (model table + launch command appeared twice)
  • Extracted Slack integration details to SLACK.md (progressive disclosure — loaded only when needed)
  • Removed health checks section that duplicated HEARTBEAT.md (injected every 10 min by extension)
  • Trimmed external content security, self-modification, heartbeat, memory, and startup sections — cut explanations Claude already knows
  • Replaced hardcoded placeholder repo names with dynamic ls ~/workspace/ lookup

dev-agent/SKILL.md (225 → 186 lines, -17%)

  • Trimmed self-modification enforcement explanation to one-liner
  • Replaced placeholder workspace layout with generic pattern
  • Condensed worktree section to constraints only
  • Tightened code quality standards

sentry-agent/SKILL.md (121 → 113 lines, -7%)

  • Removed set -a env note (guidance for launcher, not this agent)
  • Trimmed tool reference to actually-used commands (removed start/stop which contradict on-demand model)
  • Simplified environment section

New: control-agent/SLACK.md (72 lines)

Progressive disclosure file containing: bridge API (send, react, fallback), known channels, message context format, response guidelines, manual bridge restart procedure.

Reduce control-agent SKILL.md from 476 to 303 lines (36%) by:
- Deduplicating sentry agent section
- Extracting Slack integration details to SLACK.md (progressive disclosure)
- Removing health checks section (duplicates HEARTBEAT.md)
- Trimming explanations Claude already knows
- Replacing placeholder repo names with dynamic lookup

Trim dev-agent (225->186) and sentry-agent (121->113) similarly.
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Feb 22, 2026

Greptile Summary

Trims all three agent SKILL.md files to reduce token usage, following Anthropic's skill authoring best practices (progressive disclosure, removing duplicate content, keeping under 500 lines). The control-agent SKILL.md sees the largest reduction (~36%), extracting Slack integration details into a new SLACK.md reference file loaded on demand, removing a duplicate sentry-agent section (model table + launch command that also appear under "Spawning sentry-agent"), and condensing sections where the model's prior knowledge makes detailed explanations redundant.

  • control-agent/SKILL.md: Removed duplicate sentry-agent block, extracted Slack details to SLACK.md, condensed heartbeat/memory/startup/security sections, replaced hardcoded repo table with dynamic ls ~/workspace/ lookup
  • control-agent/SLACK.md: New file with bridge API examples, known channels, message context format, response guidelines, and manual bridge restart procedure
  • dev-agent/SKILL.md: Condensed workspace layout, self-modification enforcement, worktree instructions, and code quality standards
  • sentry-agent/SKILL.md: Removed polling commands (start/stop/check) from tool reference to align with on-demand model; removed SLACK_BOT_TOKEN from documented env vars (but list action still requires it — see comment)

Confidence Score: 4/5

  • Documentation-only changes with low merge risk; one env var inconsistency in sentry-agent should be addressed.
  • All changes are to markdown documentation files (agent skills), so there's no runtime code risk. The trimming preserves all critical operational constraints and security boundaries. One concrete issue: removing SLACK_BOT_TOKEN from sentry-agent's environment section while keeping the list command that requires it creates a documentation inconsistency that could cause the agent to fail without understanding why.
  • pi/skills/sentry-agent/SKILL.mdSLACK_BOT_TOKEN removed from documented env vars but still required by the documented list action.

Important Files Changed

Filename Overview
pi/skills/control-agent/SKILL.md Major trim (~36%) extracting Slack details to SLACK.md, removing duplicate sentry-agent section, condensing memory/heartbeat/startup sections. All critical operational info preserved; progressive disclosure links added correctly.
pi/skills/control-agent/SLACK.md New progressive disclosure file for Slack integration. Contains API examples, response guidelines, and manual bridge restart. Message context example omits the SECURITY NOTICE preamble present in the actual bridge output.
pi/skills/dev-agent/SKILL.md ~17% trim condensing workspace layout, self-modification, worktree, and code quality sections. All essential constraints preserved; no behavioral changes.
pi/skills/sentry-agent/SKILL.md ~7% trim removing start/stop/check tool commands and SLACK_BOT_TOKEN from environment. SLACK_BOT_TOKEN removal creates an inconsistency since the still-documented list action requires it.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[control-agent/SKILL.md<br/>476 → 303 lines] -->|extracts Slack details| B[control-agent/SLACK.md<br/>NEW — 72 lines]
    A -->|removes duplicate| C[Sentry Agent Section<br/>model table + launch cmd]
    A -->|condenses| D[Memory / Heartbeat / Startup<br/>Security / Self-Mod sections]
    A -->|replaces hardcoded repos| E["Dynamic: ls ~/workspace/"]

    F[dev-agent/SKILL.md<br/>225 → 186 lines] -->|condenses| G[Workspace / Self-Mod / Worktree<br/>Code Quality sections]

    H[sentry-agent/SKILL.md<br/>121 → 113 lines] -->|removes| I["start/stop/check commands<br/>(polling contradicts on-demand)"]
    H -->|removes| J["SLACK_BOT_TOKEN + set -a note<br/>⚠️ list still needs SLACK_BOT_TOKEN"]

    style B fill:#d4edda,stroke:#28a745
    style J fill:#fff3cd,stroke:#ffc107
Loading

Last reviewed commit: 287d14d

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +109 to 112
Required env vars (injected via `varlock` at launch):
- `SENTRY_AUTH_TOKEN` — Sentry API bearer token
- `SENTRY_CHANNEL_ID` — Slack channel ID for Sentry alerts
- `SENTRY_ORG` — Sentry organization slug
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing SLACK_BOT_TOKEN env var

sentry_monitor list (still documented in the Tool Reference above) calls the Slack API directly and requires SLACK_BOT_TOKEN. With this env var removed from the documented environment, the agent won't know it's needed and will have no context when list fails with "SLACK_BOT_TOKEN not set." Either re-add SLACK_BOT_TOKEN here or remove list from the Tool Reference if it's not expected to be used by this agent.

Suggested change
Required env vars (injected via `varlock` at launch):
- `SENTRY_AUTH_TOKEN` — Sentry API bearer token
- `SENTRY_CHANNEL_ID` — Slack channel ID for Sentry alerts
- `SENTRY_ORG` — Sentry organization slug
Required env vars (injected via `varlock` at launch):
- `SENTRY_AUTH_TOKEN` — Sentry API bearer token
- `SENTRY_CHANNEL_ID` — Slack channel ID for Sentry alerts
- `SENTRY_ORG` — Sentry organization slug
- `SLACK_BOT_TOKEN` — Slack bot OAuth token (required by `list` action)
Prompt To Fix With AI
This is a comment left during a code review.
Path: pi/skills/sentry-agent/SKILL.md
Line: 109-112

Comment:
**Missing `SLACK_BOT_TOKEN` env var**

`sentry_monitor list` (still documented in the Tool Reference above) calls the Slack API directly and requires `SLACK_BOT_TOKEN`. With this env var removed from the documented environment, the agent won't know it's needed and will have no context when `list` fails with "SLACK_BOT_TOKEN not set." Either re-add `SLACK_BOT_TOKEN` here or remove `list` from the Tool Reference if it's not expected to be used by this agent.

```suggestion
Required env vars (injected via `varlock` at launch):
- `SENTRY_AUTH_TOKEN` — Sentry API bearer token
- `SENTRY_CHANNEL_ID` — Slack channel ID for Sentry alerts
- `SENTRY_ORG` — Sentry organization slug
- `SLACK_BOT_TOKEN` — Slack bot OAuth token (required by `list` action)
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread pi/skills/control-agent/SLACK.md Outdated
Comment on lines +38 to +48
Incoming Slack messages arrive wrapped with security boundaries. Extract **Channel** and **Thread** from the metadata:
```
<<<EXTERNAL_UNTRUSTED_CONTENT>>>
Source: Slack
From: <@UXXXXXXX>
Channel: <#C07ABCDEF>
Thread: 1739581234.567890
---
the actual user message here
<<<END_EXTERNAL_UNTRUSTED_CONTENT>>>
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message example omits the SECURITY NOTICE preamble

The actual output from slack-bridge/security.mjs (wrapExternalContent) prepends a multi-line SECURITY NOTICE: block before the <<<EXTERNAL_UNTRUSTED_CONTENT>>> boundary. This example only shows the boundary markers. While the agent can still parse Channel/Thread correctly, the mismatch between the documented format and real messages could cause confusion — especially for an agent encountering the format for the first time via progressive disclosure.

Consider adding the SECURITY NOTICE preamble (even abbreviated) to keep the example faithful to the real format:

Suggested change
Incoming Slack messages arrive wrapped with security boundaries. Extract **Channel** and **Thread** from the metadata:
```
<<<EXTERNAL_UNTRUSTED_CONTENT>>>
Source: Slack
From: <@UXXXXXXX>
Channel: <#C07ABCDEF>
Thread: 1739581234.567890
---
the actual user message here
<<<END_EXTERNAL_UNTRUSTED_CONTENT>>>
```
Incoming Slack messages arrive wrapped with security boundaries. Extract **Channel** and **Thread** from the metadata:

SECURITY NOTICE: The following content is from an EXTERNAL, UNTRUSTED source (Slack).
...

<<<EXTERNAL_UNTRUSTED_CONTENT>>>
Source: Slack
From: <@Uxxxxxxx>
Channel: <#C07ABCDEF>
Thread: 1739581234.567890

the actual user message here
<<<END_EXTERNAL_UNTRUSTED_CONTENT>>>

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: pi/skills/control-agent/SLACK.md
Line: 38-48

Comment:
**Message example omits the `SECURITY NOTICE` preamble**

The actual output from `slack-bridge/security.mjs` (`wrapExternalContent`) prepends a multi-line `SECURITY NOTICE:` block before the `<<<EXTERNAL_UNTRUSTED_CONTENT>>>` boundary. This example only shows the boundary markers. While the agent can still parse Channel/Thread correctly, the mismatch between the documented format and real messages could cause confusion — especially for an agent encountering the format for the first time via progressive disclosure.

Consider adding the `SECURITY NOTICE` preamble (even abbreviated) to keep the example faithful to the real format:
```suggestion
Incoming Slack messages arrive wrapped with security boundaries. Extract **Channel** and **Thread** from the metadata:
```
SECURITY NOTICE: The following content is from an EXTERNAL, UNTRUSTED source (Slack).
...

<<<EXTERNAL_UNTRUSTED_CONTENT>>>
Source: Slack
From: <@UXXXXXXX>
Channel: <#C07ABCDEF>
Thread: 1739581234.567890
---
the actual user message here
<<<END_EXTERNAL_UNTRUSTED_CONTENT>>>
```
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

- Re-add SLACK_BOT_TOKEN to sentry-agent env vars (required by list action)
- Restore SECURITY NOTICE preamble in SLACK.md message example
@benvinegar
Copy link
Copy Markdown
Member Author

Addressed both review comments in 683ce14:

  1. sentry-agent SLACK_BOT_TOKEN — re-added to the env vars section (required by the list action).
  2. SLACK.md security preamble — restored the SECURITY NOTICE preamble in the message context example to match the real bridge output.

Comment thread pi/skills/control-agent/SKILL.md Outdated
Pi agents load SKILL.md as a single document and cannot follow
markdown links to separate files. The progressive disclosure
pattern doesn't apply here — skills must be self-contained.
@benvinegar
Copy link
Copy Markdown
Member Author

Addressed in f4bf919: inlined all Slack content back into SKILL.md and deleted SLACK.md.

Pi agents load SKILL.md as a single document and can't follow markdown links to other files — progressive disclosure doesn't apply here. Skills must be self-contained.

Control-agent SKILL.md is now 360 lines (down from 476 originally, still a 24% reduction from dedup + trimming).

@benvinegar
Copy link
Copy Markdown
Member Author

No good.

@benvinegar benvinegar closed this Feb 22, 2026
Comment on lines +285 to 295
Run `list_sessions` to get live UUIDs, then run:
```bash
bash ~/.pi/agent/skills/control-agent/startup-cleanup.sh UUID1 UUID2 UUID3
```

The script:
- Removes any `.sock` file whose UUID is NOT in the live set
- Cleans stale `.alias` symlinks pointing to removed sockets
- Kills and restarts the `slack-bridge` tmux session with the current `control-agent` UUID
- Verifies the bridge is responsive (HTTP 400 from the API = healthy)
This removes stale `.sock` files, cleans dead aliases, and restarts the Slack bridge.

**WARNING**: Do NOT use `socat` or any socket-connect test to check liveness — pi sockets don't respond to raw connections and deleting a live socket is **unrecoverable** (the socket is only created at session start). Only remove sockets for sessions that are confirmed dead via `list_sessions`.
**WARNING**: Do NOT use `socat` or socket-connect tests to check liveness — pi sockets don't respond to raw connections and deleting a live socket is **unrecoverable**. Only remove sockets confirmed dead via `list_sessions`.

### Checklist

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: A reference in the control-agent startup checklist at pi/skills/control-agent/SKILL.md points to a non-existent section. The section was renamed, but the reference was not updated.
Severity: HIGH

Suggested Fix

In pi/skills/control-agent/SKILL.md, update the broken reference in the startup checklist. Change the text "(see Sentry Agent section)" to "(see Spawning sentry-agent section)" to correctly point to the renamed section.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: pi/skills/control-agent/SKILL.md#L266-L295

Potential issue: In `pi/skills/control-agent/SKILL.md`, the startup checklist for the AI
agent contains a reference to a "Sentry Agent section" for instructions on how to launch
the `sentry-agent`. However, this section was renamed to "Spawning sentry-agent" in the
new code, but the inline reference was not updated. Because the AI agent follows these
instructions literally, it will be unable to find the correct section. This could cause
the agent to fail its startup sequence, specifically the step where it needs to spawn
the `sentry-agent`, which is a critical component for handling production alerts.

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.

1 participant