Skip to content

Add 11 new tools, verify_webhook, and iter_posts in retriever#22

Merged
jackparnell merged 1 commit intomainfrom
feature/missing-tools-iterators
Apr 9, 2026
Merged

Add 11 new tools, verify_webhook, and iter_posts in retriever#22
jackparnell merged 1 commit intomainfrom
feature/missing-tools-iterators

Conversation

@ColonistOne
Copy link
Copy Markdown
Collaborator

Summary

Brings langchain-colony's tool surface in line with what colony-sdk 1.4.0 / 1.5.0 actually ships, plus integrates the SDK iterators into ColonyRetriever.

New tools (auto-included in ColonyToolkit().get_tools())

Tool Purpose
ColonyFollowUser, ColonyUnfollowUser Manage your social graph
ColonyReactToPost, ColonyReactToComment Toggle emoji reactions
ColonyGetPoll, ColonyVotePoll Read poll options/votes; cast a vote
ColonyJoinColony, ColonyLeaveColony Join/leave colonies by name or UUID
ColonyCreateWebhook, ColonyGetWebhooks, ColonyDeleteWebhook Webhook management

ColonyToolkit goes from 16 tools (7 read + 9 write) to 27 tools (9 read + 18 write). read_only=True returns 9 (was 7).

Standalone tool

  • ColonyVerifyWebhookBaseTool wrapper around verify_webhook for agents that act as webhook receivers. Not in ColonyToolkit().get_tools() — instantiate directly when you need it. Same pattern as ColonyRegister in crewai-colony (verification doesn't need an authenticated client).

Re-exported from colony_sdk

  • verify_webhookfrom langchain_colony import verify_webhook. HMAC-SHA256, constant-time, sha256= prefix tolerance. Re-exported, not re-wrappedlangchain_colony.verify_webhook is colony_sdk.verify_webhook, so SDK security fixes apply automatically.

ColonyRetriever now uses iter_posts

# Before — single page only, k > ~20 silently capped:
data = self.client.get_posts(search=query, limit=self.k)

# After — k pages of arbitrary size:
posts = list(self.client.iter_posts(search=query, max_results=self.k))

The async path dispatches on inspect.isasyncgenfunction(self.client.iter_posts) so it works for both sync ColonyClient (sync generator → materialised in to_thread) and AsyncColonyClient (async generator → async for natively).

Test plan

  • pytest tests/ --ignore=tests/test_integration.py270 passed (was 237, +33 new tests)
  • ruff check clean
  • ruff format --check clean

New tests/test_new_tools.py (33 tests):

Section Tests
TestFollowUnfollow 4 — including a regression check that unfollow calls the right SDK method (crewai-colony 1.4.0 had a bug where it called follow again)
TestReactions 3
TestPolls 4 — including a text vs label fallback test
TestColonyMembership 3
TestWebhookTools 6 — covering wh-* list response and bare-list response shapes
TestVerifyWebhookReExport 5 — re-export identity, valid/invalid sigs, sha256= prefix, str payload
TestColonyVerifyWebhookTool 8 — sync + async, valid/invalid, sha256= prefix, defensive catch around verify_webhook
TestDirectConstruction 1 — package-surface compile check

tests/test_retriever.py rewritten to mock iter_posts (via side_effect=lambda **kw: iter([...]) so re-invocations get fresh iterators). tests/test_toolkit.py and tests/test_async_native.py updated for the new tool counts.

This is PR 3 of 4 heading toward v0.6.0. Last code PR — up next: PR 4 (release automation, dependabot, coverage on CI), then cut the release.

🤖 Generated with Claude Code

Brings langchain-colony's tool surface in line with crewai-colony by
adding all the SDK 1.4.0 tools that were previously missing, plus the
SDK 1.5.0 verify_webhook helper.

New tools (auto-included in ColonyToolkit().get_tools()):
- ColonyFollowUser, ColonyUnfollowUser (social graph)
- ColonyReactToPost, ColonyReactToComment (emoji reactions)
- ColonyGetPoll, ColonyVotePoll (polls)
- ColonyJoinColony, ColonyLeaveColony (membership)
- ColonyCreateWebhook, ColonyGetWebhooks, ColonyDeleteWebhook

ColonyToolkit goes from 16 tools (7 read + 9 write) to 27 tools
(9 read + 18 write).

Standalone (NOT in get_tools(), instantiate directly):
- ColonyVerifyWebhook — BaseTool wrapper around verify_webhook for
  agents that act as webhook receivers. Same pattern as ColonyRegister
  in crewai-colony.

Re-exported from colony_sdk:
- verify_webhook — pure-function HMAC-SHA256 verification, constant-
  time comparison, sha256= prefix tolerance. Re-exported (not
  re-wrapped) so SDK security fixes apply automatically.

ColonyRetriever now uses iter_posts:
- Replaces the single get_posts(limit=k) call with
  iter_posts(max_results=k). Lets callers ask for k larger than one
  API page (~20 posts) without hand-rolled pagination.
- Async path dispatches on inspect.isasyncgenfunction so it works for
  both sync ColonyClient (sync generator → materialise in to_thread)
  and AsyncColonyClient (async generator → async for).

Tests:
- New tests/test_new_tools.py — 33 tests covering all 11 new tools
  (sync + async paths), verify_webhook re-export identity and
  signature validation, ColonyVerifyWebhook tool sync + async.
- tests/test_retriever.py rewritten to mock iter_posts instead of
  get_posts (set side_effect=lambda **kw: iter([...]) so multiple
  invocations get fresh iterators). All 22 retriever tests still
  pass under the new dispatcher.
- tests/test_toolkit.py updated for new tool counts (16→27, 7→9,
  exclude=14→25, etc) and new write-tool tag membership.
- tests/test_async_native.py updated for the same counts and to mock
  iter_posts on the sync-fallback retriever test.

270 tests passing (was 237).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jackparnell jackparnell merged commit 3bd3f32 into main Apr 9, 2026
5 checks passed
@jackparnell jackparnell deleted the feature/missing-tools-iterators branch April 9, 2026 13:02
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