feat(slack-app phase 3b): Anthropic agent loop + read-only memory tools#28
Merged
feat(slack-app phase 3b): Anthropic agent loop + read-only memory tools#28
Conversation
Replaces the Phase 3a canned reply with the real agent. The bot now actually answers questions by reading + searching the requesting user's memories. New modules: - src/slack-conversation-service.ts: per-Slack-thread state in slack_conversation_state. 24h TTL. MAX 20 user/assistant turn pairs (older truncated). Stores text-only — tool-use turns aren't persisted across messages (they bloat fast and don't help the model). Lazy pruneExpiredConversations call on every save (cheap, indexed). - src/slack-agent-tools.ts: 8 read-only memory tools (get_memory_briefing, search_memories, read_memories, get_memories_by_tag, get_memory_by_id, read_team_memories, read_thread, get_graph_around). Each is a thin shim over the existing memory-service / memory-graph functions, scoped to the resolved Reflect user, vendor='slack', limits clamped to 25. - src/slack-agent.ts: runSlackAgentTurn. Builds the system prompt (mode + speaker), runs the Anthropic SDK loop, executes tool calls in parallel per step, caps at 6 steps. Default model RM_SLACK_AGENT_MODEL or claude-sonnet-4-7. Anthropic client is injectable for tests. Wiring: - slack-events-handler.ts: handleUserMessage now loads the LLM key for the workspace's scope, loads conversation history for the thread, runs the agent turn, persists the new history, posts the reply. Falls back to a polite "set an LLM key" message if no key is configured. Audit metadata gains tool_calls / agent_steps / stop_reason. Tests (+20, total 347 -> 367): - slack-conversation: roundtrip, update-not-duplicate, MAX_TURNS truncation, prune of expired rows, fail-closed on corrupted JSON, defensive filtering of bad shapes. - slack-agent: every tool's dispatch path against a real DB + end_turn + tool_use loop with a stubbed Anthropic client + empty-text fallback + system prompt encoding (DM vs channel, speaker). Refs: parent memory d959bc61. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 3b — replaces the Phase 3a canned reply with the actual agent. The bot now answers Slack messages by reading and searching the requesting user's Reflect memories.
Full design: `docs/eng-plan-slack-app-v1.md`. Parent memory `d959bc61`.
New modules
Wiring
`slack-events-handler.ts`: handler now loads the LLM key for the workspace's scope, loads conversation history for the thread, runs the agent turn, persists the new history, posts the reply. Falls back to a polite "set an LLM key in dashboard" message when no key is configured. Audit metadata gains `tool_calls` / `agent_steps` / `stop_reason`.
Tests (+20, 367/367 total)
slack-conversation: roundtrip, update-not-duplicate, MAX_TURNS truncation, prune of expired rows, fail-closed on corrupted JSON, defensive filtering of malformed message shapes.
slack-agent: every tool's dispatch path against a real DB + end_turn + tool_use loop with a stubbed Anthropic client + empty-text fallback + system prompt encoding (DM vs channel, speaker).
Manual prereq for end-to-end validation
Before the agent can reply on dev, you need to set the Anthropic API key:
Test plan
Made with Cursor