Skip to content

Crewai integration#77

Merged
yatharthk2 merged 6 commits intousemoss:mainfrom
staru09:crewai_integration
Apr 10, 2026
Merged

Crewai integration#77
yatharthk2 merged 6 commits intousemoss:mainfrom
staru09:crewai_integration

Conversation

@staru09
Copy link
Copy Markdown
Contributor

@staru09 staru09 commented Mar 27, 2026

Pull Request Checklist

Please ensure that your PR meets the following requirements:

  • I have read the CONTRIBUTING guide.
  • I have updated the documentation (if applicable).
  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Description

Add CrewAI integration for Moss semantic search.

Tested with Gemini (gemini-3.1-flash-lite-preview) as the LLM, using FAQ data from the existing examples.
All tools verified against the live Moss platform.

Fixes #76

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Open with Devin

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Mar 27, 2026

@staru09 is attempting to deploy a commit to the Moss Team Team on Vercel.

A member of the Team first needs to authorize it.

@@ -0,0 +1,40 @@
from __future__ import annotations
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Per #76, let's keep this cookbook-only - please drop packages/crewai-moss/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cool thing

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new crewai-moss integration package so CrewAI agents can use Moss for semantic search and basic index/document management, plus a cookbook example and top-level docs update to surface the integration.

Changes:

  • Introduces crewai-moss Python package with 8 CrewAI BaseTool wrappers and a moss_tools() factory.
  • Adds demo/cookbook example scripts and documentation for using CrewAI + Moss together.
  • Updates the repo root README to include the new CrewAI cookbook entry.

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
packages/crewai-moss/tests/test.py Adds live (credentialed) test script for the CrewAI tool wrappers.
packages/crewai-moss/tests/init.py Initializes the tests package (empty).
packages/crewai-moss/src/crewai_moss/tools.py Implements CrewAI BaseTool wrappers for Moss search, docs, and index operations.
packages/crewai-moss/src/crewai_moss/init.py Exposes the tools and selected Moss SDK types from the package root.
packages/crewai-moss/pyproject.toml Defines package metadata, dependencies, and ruff config for crewai-moss.
packages/crewai-moss/examples/demo.py Provides an example CrewAI + Moss script using FAQ data.
packages/crewai-moss/README.md Documents installation, available tools, and usage patterns.
packages/crewai-moss/LICENSE Adds a license file for the new package.
packages/crewai-moss/.gitignore Adds Python/package build ignores for the new package.
examples/cookbook/crewai/example_usage.py Adds a cookbook example script demonstrating CrewAI + Moss.
examples/cookbook/crewai/README.md Adds cookbook documentation for setup and running the CrewAI example.
README.md Updates root docs to list the CrewAI cookbook integration and adjusts formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/crewai-moss/examples/demo.py Outdated
Comment on lines +25 to +27
faqs_path = os.path.join(
os.path.dirname(__file__), "..", "..", "python", "faqs.json"
)
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

faqs_path resolves to packages/python/faqs.json from this file location, but the FAQ data lives at examples/python/faqs.json in this repo. As written, the demo will raise FileNotFoundError unless a different file layout exists. Update the path calculation to point at the repo’s examples/python/faqs.json (or accept a path via env/CLI to avoid brittle relative paths).

Suggested change
faqs_path = os.path.join(
os.path.dirname(__file__), "..", "..", "python", "faqs.json"
)
faqs_path = os.getenv("MOSS_FAQ_PATH")
if not faqs_path:
faqs_path = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"examples",
"python",
"faqs.json",
)

Copilot uses AI. Check for mistakes.
client = MossClient(os.getenv("MOSS_PROJECT_ID"), os.getenv("MOSS_PROJECT_KEY"))

faqs_path = os.path.join(
os.path.dirname(__file__), "..", "..", "python", "faqs.json"
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

faqs_path is computed by going up only two directories, which targets examples/cookbook/python/faqs.json. In this repo the file is examples/python/faqs.json, so the example will fail with FileNotFoundError. Adjust the relative path (or make it configurable) so it consistently finds examples/python/faqs.json.

Suggested change
os.path.dirname(__file__), "..", "..", "python", "faqs.json"
os.path.dirname(__file__), "..", "..", "..", "python", "faqs.json"

Copilot uses AI. Check for mistakes.
Comment thread README.md Outdated
| [Next.js](https://nextjs.org) | Available | [`apps/next-js/`](apps/next-js/) |
| [VitePress](https://vitepress.dev) | Available | [`packages/vitepress-plugin-moss/`](packages/vitepress-plugin-moss/) |
| [Vercel AI SDK](https://sdk.vercel.ai) | Coming soon | — |
| [CrewAI](https://github.com/crewAIInc/crewAI) | Coming soon | — |
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The integration table lists CrewAI twice (one row says Available and another says Coming soon). This is contradictory and will confuse users; remove the outdated entry so CrewAI appears only once with the correct status.

Suggested change
| [CrewAI](https://github.com/crewAIInc/crewAI) | Coming soon | — |

Copilot uses AI. Check for mistakes.
Comment thread packages/crewai-moss/README.md Outdated
Comment on lines +181 to +184
python -m pytest tests/test_tools.py -v

# Live platform tests (needs MOSS_PROJECT_ID & MOSS_PROJECT_KEY in .env)
python tests/test_live.py
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

This package README instructs running tests/test_tools.py and tests/test_live.py, but neither file exists in this package (only tests/test.py is present). Update the README commands to match the actual filenames and/or rename the test files to match the documented commands.

Suggested change
python -m pytest tests/test_tools.py -v
# Live platform tests (needs MOSS_PROJECT_ID & MOSS_PROJECT_KEY in .env)
python tests/test_live.py
python -m pytest tests/test.py -v
# Live platform tests (needs MOSS_PROJECT_ID & MOSS_PROJECT_KEY in .env)
python tests/test.py

Copilot uses AI. Check for mistakes.
Comment thread examples/cookbook/crewai/moss_crewai.py Outdated
Comment on lines +40 to +41
_client: Any = None
_index_loaded: bool = False
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

_client and _index_loaded are declared as normal model fields. In this repo’s LangChain integration, these are marked as PrivateAttr to avoid leaking into the tool schema/serialization. Consider switching these to PrivateAttr here as well (and similarly for _client in the other tool classes in this file).

Copilot uses AI. Check for mistakes.
Comment thread examples/cookbook/crewai/moss_crewai.py Outdated
Comment on lines +107 to +112
project_id: str = Field(description="Moss project ID")
project_key: str = Field(description="Moss project key")
index_name: str = Field(description="Name of the Moss index")

_client: Any = None

Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

_client is defined as a standard field; per existing integrations in this repo, internal clients are modeled as PrivateAttr so they don’t become part of the pydantic schema/tool args. Update _client in this class (and the other tool classes below) to use PrivateAttr.

Copilot uses AI. Check for mistakes.
Comment thread packages/crewai-moss/LICENSE Outdated
@@ -0,0 +1,26 @@
BSD 2-Clause License

Copyright (c) 2024–2025, Daily
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The copyright holder in this LICENSE file is Daily, but pyproject.toml lists InferEdge Inc. as the author and the repo root license is Moss Team. Please confirm the intended copyright holder for this package and update the header to match, to avoid licensing ambiguity.

Suggested change
Copyright (c) 2024–2025, Daily
Copyright (c) 2024–2025, Moss Team

Copilot uses AI. Check for mistakes.
Comment thread packages/crewai-moss/.gitignore Outdated
examples/.env
__pycache__/
*.pyc
src/pipecat_moss.egg-info/
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

This .gitignore entry appears copy/pasted from pipecat-moss and ignores src/pipecat_moss.egg-info/. For this package it should ignore the egg-info directory for crewai_moss instead, otherwise local build artifacts won’t be ignored.

Suggested change
src/pipecat_moss.egg-info/
src/crewai_moss.egg-info/

Copilot uses AI. Check for mistakes.
Comment on lines +43 to +48
async def run_tests():
if not PROJECT_ID or not PROJECT_KEY:
print("ERROR: MOSS_PROJECT_ID and MOSS_PROJECT_KEY must be set.")
sys.exit(1)

print("Running live tests against Moss platform...\n")
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

This file is a live/integration test that requires real Moss credentials, but it’s named generically (test.py) and sits under tests/. Consider renaming it to test_live.py (matching the README) and/or marking it clearly so it’s not mistaken for a unit test suite.

Copilot uses AI. Check for mistakes.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 29, 2026

CLA assistant check
All committers have signed the CLA.

@staru09 staru09 force-pushed the crewai_integration branch from 84d042a to 0ec391f Compare March 29, 2026 15:02
@yatharthk2
Copy link
Copy Markdown
Collaborator

Hi @staru09 , can you please properly resolve the comments from co-pilot ?

@staru09
Copy link
Copy Markdown
Contributor Author

staru09 commented Mar 30, 2026

Hi @staru09 , can you please properly resolve the comments from co-pilot ?

I think most of these were for the package that I had added, the recent changes has all these addressed

@yatharthk2
Copy link
Copy Markdown
Collaborator

Can you please remove quick start and changes made to main read me ?

@yatharthk2
Copy link
Copy Markdown
Collaborator

please add .env.example

"""Create a Moss index with the first 10 FAQ documents."""
client = MossClient(os.getenv("MOSS_PROJECT_ID"), os.getenv("MOSS_PROJECT_KEY"))

faqs_path = os.path.join(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the directory has changed a lot, this path wont work

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cool

docs = [
DocumentInfo(
id=faq["id"],
text=faq["text"],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Simple FAQ.json example does not seem to be the best integration showcase between the Moss and Crew.

Please try adding more agents which handle multiple index from moss and they are inter collaborating to reach final conclusion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

umm, let me add a different usecase then

Comment thread examples/cookbook/crewai/moss_crewai.py Outdated
self._index_loaded = True

def _run(self, query: str) -> str:
"""Synchronous search -- wraps the async implementation."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why sync ? what is the use ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The sync _run() is there because CrewAI's BaseTool marks it as abstractmethod, so I had to implement sync and async both for it.

Comment thread examples/cookbook/crewai/moss_crewai.py Outdated
index_name: str = Field(description="Name of the Moss index to search")
top_k: int = Field(default=5, description="Number of results to return")
alpha: float = Field(
default=0.5,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

change to 0.8

Comment thread examples/cookbook/crewai/moss_crewai.py Outdated

def model_post_init(self, __context: Any) -> None:
"""Initialize the MossClient after model construction."""
self._client = MossClient(self.project_id, self.project_key)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

every class instantiates its own mossclient, this is too redundunt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, fixed this one

@staru09 staru09 force-pushed the crewai_integration branch from f6dff4a to 622f75b Compare April 2, 2026 05:57
@yatharthk2
Copy link
Copy Markdown
Collaborator

please let me know when this is ready to review

@staru09 staru09 force-pushed the crewai_integration branch from a06995e to 0f49947 Compare April 5, 2026 06:29
@staru09 staru09 requested a review from yatharthk2 April 5, 2026 06:33
devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 5 additional findings in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 test_live.py is a credentials-required script, not a pytest-compatible test suite

Unlike the langchain cookbook which has test_integration.py using unittest.IsolatedAsyncioTestCase with mocked clients (no credentials needed), the crewai cookbook's test_live.py is a standalone script using global state (passed/failed counters) and sys.exit(1). It requires real API credentials and cannot run as part of pytest tests/. This means the tool logic in moss_crewai.py has no offline-runnable unit tests. The langchain example (examples/cookbook/langchain/test_integration.py) provides a better pattern to follow here — mocking MossClient to verify tool behavior without hitting the real API.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@staru09 staru09 force-pushed the crewai_integration branch from 7265b3f to 3d517ba Compare April 8, 2026 08:18
devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Collaborator

@yatharthk2 yatharthk2 left a comment

Choose a reason for hiding this comment

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

Over all looks good, will approve after these fixes

crew = Crew(
agents=specialists + [writer],
tasks=search_tasks + [write_task],
verbose=True,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please do verbose=False,

Comment on lines +1 to +3
MOSS_PROJECT_ID=your-project-id
MOSS_PROJECT_KEY=your-project-key
GEMINI_API_KEY=your-gemini-key
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add CREWAI_TRACING_ENABLED=false

class MossListIndexesInput(BaseModel):
"""Input schema for MossListIndexesTool."""

pass # No input needed
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can we remove ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's there to match the schema required by crewai for tools even if it doesn't need any params
We need it cause the BaseTool needs an args_schema and without this, it'll fallback to default and the code can break

@@ -0,0 +1,3 @@
MOSS_PROJECT_ID=your-project-id
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you also please add pyproject.toml file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I dont see pyproject.toml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It got ignored by the git, please check now

@staru09 staru09 force-pushed the crewai_integration branch from 3d517ba to 21cecc1 Compare April 9, 2026 09:02
devin-ai-integration[bot]

This comment was marked as resolved.

@staru09 staru09 force-pushed the crewai_integration branch from 21cecc1 to 67bca81 Compare April 9, 2026 09:15
devin-ai-integration[bot]

This comment was marked as resolved.

@staru09 staru09 requested a review from yatharthk2 April 9, 2026 09:35
devin-ai-integration[bot]

This comment was marked as resolved.

"crewai",
"moss>=1.0.0",
"pydantic",
"python-dotenv",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you please add "crewai[google-genai]"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we keep it vendor neutral add let user add any vendor uv add 'vendor_package' directly?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

for your example to run there should be as less friction as possible

@staru09 staru09 force-pushed the crewai_integration branch from 178947d to 7111f96 Compare April 10, 2026 17:21
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 9 additional findings in Devin Review.

Open in Devin Review

Comment on lines +8 to +16
from moss_crewai import (
MossAddDocsTool,
MossCreateIndexTool,
MossDeleteDocsTool,
MossDeleteIndexTool,
MossGetDocsTool,
MossListIndexesTool,
MossSearchTool,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 MossGetIndexTool has no test coverage in test_live.py

MossGetIndexTool is one of 8 tool classes defined in moss_crewai.py:187, documented in README.md:134, and returned by the moss_tools() factory at moss_crewai.py:313. However, test_live.py imports only 7 of the 8 tools (lines 8–16) and has no test scenario for MossGetIndexTool. Every other tool class has at least one test. This violates the CONTRIBUTING.md guideline: "If you've added code that should be tested, add tests." The existing langchain cookbook example (examples/cookbook/langchain/test_integration.py) demonstrates the expected practice of testing all added tool classes.

Prompt for agents
MossGetIndexTool is missing from test_live.py. It is one of 8 tool classes defined in moss_crewai.py, but the test file imports and tests only 7 of them. Add an import of MossGetIndexTool to the import block at lines 8-16 of test_live.py, and add a test section (e.g. between the list_indexes test and the add_docs test) that creates a MossGetIndexTool instance and calls _arun(index_name=TEST_INDEX), verifying the returned string contains the index name. Follow the same pattern as the other tests in the file (try/except with report() calls).
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread examples/cookbook/crewai/pyproject.toml Outdated
version = "0.1.0"
description = "CrewAI integration for Moss semantic search"
readme = "README.md"
requires-python = ">=3.11"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

your dependency dont build for python 3.14 , please cap it here

@staru09 staru09 force-pushed the crewai_integration branch from 6e4c9f8 to d41edc2 Compare April 10, 2026 17:49
@yatharthk2
Copy link
Copy Markdown
Collaborator

Approved and Thanks for the PR :)

@yatharthk2 yatharthk2 merged commit 8cfa9da into usemoss:main Apr 10, 2026
12 of 14 checks passed
Atulsingh1155 pushed a commit to Atulsingh1155/moss that referenced this pull request Apr 30, 2026
## Pull Request Checklist

Please ensure that your PR meets the following requirements:

- [x] I have read the [CONTRIBUTING](CONTRIBUTING.md) guide.
- [x] I have updated the documentation (if applicable).
- [x] My code follows the style guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] New and existing unit tests pass locally with my changes.

## Description

Add CrewAI integration for Moss semantic search.

Tested with Gemini (gemini-3.1-flash-lite-preview) as the LLM, using FAQ
data from the existing examples.
 All tools verified against the live Moss platform.

Fixes usemoss#76 

## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/usemoss/moss/pull/77"
target="_blank">
  <picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img
src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open with Devin">
  </picture>
</a>
<!-- devin-review-badge-end -->
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.

[Feature]: CrewAI Integration with Moss

5 participants