diff --git a/ai-agents/crew-ai-actions.mdx b/ai-agents/crew-ai-actions.mdx new file mode 100644 index 00000000..bb7ee7e1 --- /dev/null +++ b/ai-agents/crew-ai-actions.mdx @@ -0,0 +1,9 @@ +--- +title: "AI Agent Actions" +sidebarTitle: "Actions" +description: "Explore the various actions you can perform with your AI agent in CometChat." +--- + +import Actions from '/snippets/ai-agents/actions.mdx'; + + diff --git a/ai-agents/crew-ai-knowledge-agent.mdx b/ai-agents/crew-ai-knowledge-agent.mdx new file mode 100644 index 00000000..06bbd47b --- /dev/null +++ b/ai-agents/crew-ai-knowledge-agent.mdx @@ -0,0 +1,142 @@ +--- +title: "Build Your Knowledge Agent with CrewAI" +sidebarTitle: "Knowledge Agent" +description: "Create a CrewAI knowledge agent that answers from your docs, streams NDJSON to CometChat, and cites sources." +--- + +import { Steps, Step } from 'mintlify'; + +Based on the refreshed [`ai-agent-crew-ai-examples`](https://github.com/cometchat/ai-agent-crew-ai-examples) codebase, here’s how to run the `knowledge_agent` FastAPI service, ingest docs, and stream answers into CometChat. + +*** + +## What you’ll build + +- A **CrewAI** agent that grounds replies in your ingested docs (per namespace). +- A **FastAPI** service with ingest/search/generate endpoints plus a `/stream` SSE. +- **CometChat AI Agent** wiring that consumes newline-delimited JSON chunks (`text_start`, `text_delta`, `text_end`, `done`). + +*** + +## Prerequisites + +- Python 3.10+ with `pip` (or `uv`) +- `OPENAI_API_KEY` (optionally `OPENAI_BASE_URL`, `KNOWLEDGE_OPENAI_MODEL`, `KNOWLEDGE_EMBEDDING_MODEL`) +- A CometChat app + AI Agent entry + +*** + +## Run the updated sample + + + + In ai-agent-crew-ai-examples/: +
python3 -m venv .venv
+source .venv/bin/activate
+pip install -e .
+uvicorn knowledge_agent.main:app --host 0.0.0.0 --port 8000 --reload
+ Env supports .env at repo root or inside knowledge_agent/.env. +
+ + OPENAI_API_KEY is required. Optional: OPENAI_BASE_URL, KNOWLEDGE_OPENAI_MODEL (default gpt-4o-mini), KNOWLEDGE_EMBEDDING_MODEL (default text-embedding-3-small). + + + Ingested files land in knowledge_agent/data/knowledge/<namespace>/ and embeddings persist to knowledge_agent/data/chroma/<namespace>/. Duplicate hashes are skipped automatically. + +
+ +*** + +## API surface (FastAPI) + +- `POST /api/tools/ingest` — accept JSON or `multipart/form-data` with `sources` (text/markdown/url) and optional file uploads; returns `saved`, `skipped`, `errors`. +- `POST /api/tools/searchDocs` — semantic search via Chroma; accepts `namespace`, `query`, `max_results`. +- `POST /api/agents/knowledge/generate` — single, non-streaming completion (requires at least one message). +- `POST /stream` — newline-delimited JSON over SSE (`text_start`, `text_delta`, `text_end`, `done`; `error` on failure) ready for CometChat BYOA. +- Validation/behavior: `/ingest` dedupes by content hash (skips duplicates) and returns `207` when mixed `errors`/`saved`; `/stream` rejects empty `messages`. + +### Ingest examples + +```bash +curl -X POST http://localhost:8000/api/tools/ingest \ + -H "Content-Type: application/json" \ + -d '{ + "namespace": "default", + "sources": [ + { "type": "url", "value": "https://docs.crewai.com/" }, + { "type": "markdown", "title": "Notes", "value": "# CrewAI Rocks" } + ] + }' +``` + +Multipart uploads are also supported: + +```bash +curl -X POST http://localhost:8000/api/tools/ingest \ + -H "Accept: application/json" \ + -F "namespace=default" \ + -F "sources=[{\"type\":\"text\",\"value\":\"Hello\"}]" \ + -F "files=@/path/to/file.pdf" +``` + +### Search + answer + +```bash +curl -X POST http://localhost:8000/api/tools/searchDocs \ + -H "Content-Type: application/json" \ + -d '{"namespace":"default","query":"CrewAI agent lifecycle","max_results":4}' +``` + +```bash +curl -N http://localhost:8000/stream \ + -H "Content-Type: application/json" \ + -d '{ + "thread_id": "thread_1", + "run_id": "run_001", + "messages": [ + { "role": "user", "content": "Summarize the CrewAI agent lifecycle." } + ] + }' +``` + +Streaming payload shape: + +```json +{"type":"text_start","message_id":"...","thread_id":"...","run_id":"..."} +{"type":"text_delta","content":"...","message_id":"...","thread_id":"...","run_id":"..."} +{"type":"text_end","message_id":"...","thread_id":"...","run_id":"..."} +{"type":"done","thread_id":"...","run_id":"..."} +# errors (if thrown) look like: +{"type":"error","message":"...","message_id":"...","thread_id":"...","run_id":"..."} +``` + +*** + +## Crew internals (for reference) + +`knowledge_agent/knowledge_manager.py` builds a search tool per namespace, wired into a CrewAI agent: + +```python +search_tool = self._create_search_tool(normalised) +agent = Agent( + role="Knowledge Librarian", + goal="Answer user questions with relevant citations from the knowledge base.", + tools=[search_tool], + llm=model, +) +task = Task( + description="Use search_knowledge_base before answering.\nConversation: {conversation}\nLatest: {question}", + expected_output="A concise, cited answer grounded in ingested docs.", + agent=agent, +) +crew = Crew(agents=[agent], tasks=[task], process=Process.sequential) +``` + +*** + +## Wire it to CometChat + +- Dashboard → **AI Agent → BYO Agents** and then **Get Started / Integrate → Choose CrewAI**. → **Agent ID** (e.g., `knowledge`) → **Deployment URL** = your public `/stream`. +- The SSE stream is newline-delimited JSON; CometChat AG-UI adapters parse `text_start`/`text_delta`/`text_end` and stop on `done`. Message IDs, thread IDs, and run IDs are included for threading. +- Use namespaces to keep customer/workspace data separate; pass `namespace` in the payload or inside `tool_params.namespace` (either works; defaults to `default` if omitted). +- Keep secrets server-side; add auth headers on the FastAPI route if needed. diff --git a/ai-agents/crew-ai-product-hunt-agent.mdx b/ai-agents/crew-ai-product-hunt-agent.mdx new file mode 100644 index 00000000..7b57387b --- /dev/null +++ b/ai-agents/crew-ai-product-hunt-agent.mdx @@ -0,0 +1,103 @@ +--- +title: "Build a Product Hunt Agent with CrewAI" +sidebarTitle: "Product Hunt Agent" +description: "Create a CrewAI agent that fetches Product Hunt posts, answers launch questions, and can trigger frontend actions like confetti." +--- + +import { Steps, Step } from 'mintlify'; + +Refreshed for the latest [`ai-agent-crew-ai-examples`](https://github.com/cometchat/ai-agent-crew-ai-examples) codebase: run the `product_hunt_agent` FastAPI service, wire it to CometChat, and stream SSE updates (with optional confetti actions). + +--- + +## What you’ll build + +- A CrewAI agent with tools to **get top posts**, **search**, **timeframes**, and **trigger confetti**. +- A FastAPI `/stream` endpoint emitting newline-delimited JSON (`text_start`, `text_delta`, `text_end`, `done`). +- CometChat AI Agent wiring that consumes those SSE chunks; your UI listens for the confetti payload. +- Streaming events follow `text_start` → `text_delta` chunks → `text_end` → `done` (errors emit `type: "error"`). + +--- + +## Prerequisites + +- Python 3.10+ with `pip` +- `OPENAI_API_KEY` (optionally `OPENAI_BASE_URL`, `PRODUCT_OPENAI_MODEL`) +- Optional: `PRODUCTHUNT_API_TOKEN` for live GraphQL data (empty lists when missing) +- CometChat app + AI Agent entry + +--- + +## Run the updated sample + + + + In ai-agent-crew-ai-examples/: +
python3 -m venv .venv
+source .venv/bin/activate
+pip install -e .
+uvicorn product_hunt_agent.main:app --host 0.0.0.0 --port 8001 --reload
+
+ + Required: OPENAI_API_KEY. Optional: PRODUCTHUNT_API_TOKEN (GraphQL), PRODUCTHUNT_DEFAULT_TIMEZONE (default America/New_York). + +
+ +*** + +## API surface (FastAPI) + +- `GET /api/top` — top posts by votes (`limit` 1–10). +- `GET /api/top-week` — rolling window (default 7 days) with `limit` and `days`. +- `GET /api/top-range` — timeframe queries (`timeframe`, `tz`, `limit`); supports `"today"`, `"yesterday"`, `"last_week"`, `"last_month"`, or ISO dates. +- `GET /api/search` — Algolia search (`q`, `limit`). +- `POST /api/chat` — non-streaming CrewAI answer. +- `POST /stream` — SSE stream (`text_start`, `text_delta`, `text_end`, `done`) ready for CometChat. +- `POST /api/chat` payload: `{"message": "…", "messages": [{ "role": "user", "content": "…" }]}` (array is required if `message` is omitted). + +### Streaming example + +```bash +curl -N http://localhost:8001/stream \ + -H "Content-Type: application/json" \ + -d '{ + "messages": [ + { "role": "user", "content": "What were the top launches last week?" } + ] + }' +``` + +Streaming payload shape: + +```json +{"type":"text_start","message_id":"...","thread_id":"...","run_id":"..."} +{"type":"text_delta","content":"...","message_id":"...","thread_id":"...","run_id":"..."} +{"type":"text_end","message_id":"...","thread_id":"...","run_id":"..."} +{"type":"done","thread_id":"...","run_id":"..."} +# errors (when thrown) look like: +{"type":"error","message":"...","message_id":"...","thread_id":"...","run_id":"..."} +``` + +*** + +## Crew internals (for reference) + +Key tools in `product_hunt_agent/agent_builder.py`: + +```python +@tool("getTopProducts") # votes-ranked, clamps limit 1-10 +@tool("getTopProductsThisWeek") # rolling-week window, clamps days 1-31 and limit 1-10 +@tool("getTopProductsByTimeframe") # "today", "yesterday", "last_week", ISO, ranges; clamps limit 1-10 +@tool("searchProducts") # Algolia search (no token needed) +@tool("triggerConfetti") # returns payload: colors, particleCount, spread, startVelocity, origin, ticks, disableSound +``` + +All tools run server-side; if `PRODUCTHUNT_API_TOKEN` is missing, top/timeframe queries return empty arrays but still respond cleanly (search still works via Algolia defaults). + +*** + +## Wire it to CometChat + +- Dashboard → **AI Agent → BYO Agents** and then **Get Started / Integrate → Choose CrewAI**. → **Agent ID** (e.g., `product_hunt`) → **Deployment URL** = your public `/stream`. +- Listen for `text_start`/`text_delta`/`text_end` to render streaming text; stop on `done`. +- When `triggerConfetti` returns, map the payload to your UI handler (Widget/React UI Kit). Keep API tokens server-side. diff --git a/ai-agents/crew-ai-tools.mdx b/ai-agents/crew-ai-tools.mdx new file mode 100644 index 00000000..78f2f929 --- /dev/null +++ b/ai-agents/crew-ai-tools.mdx @@ -0,0 +1,9 @@ +--- +title: "AI Agent Tools" +sidebarTitle: "Tools" +description: "Explore the various tools you can use with your AI agent in CometChat." +--- + +import Tools from '/snippets/ai-agents/tools.mdx'; + + diff --git a/ai-agents/crew-ai.mdx b/ai-agents/crew-ai.mdx new file mode 100644 index 00000000..a686cbb8 --- /dev/null +++ b/ai-agents/crew-ai.mdx @@ -0,0 +1,160 @@ +--- +title: "Create an AI Agent with CrewAI" +sidebarTitle: "Create AI Agent" +description: "Connect a CrewAI agent to CometChat, customize it with UI Kit Builder, and ship it as React UI Kit code or a Chat Widget." +--- + +import { Steps, Step, CardGroup, Card } from 'mintlify'; + +## What you’ll build + +- A **CrewAI** agent exposed via a public endpoint (e.g., FastAPI `/kickoff`) that streams NDJSON. +- The same agent **connected to CometChat** (Agent ID + Deployment URL). +- A **customized chat experience** using **UI Kit Builder**. +- An export to **React UI Kit code** _or_ **Chat Widget** for integration. +- A streaming contract that emits `text_start` → `text_delta` → `text_end` → `done` (plus `error`), with `message_id`/`thread_id`/`run_id`. + +--- + +## Prerequisites + +- A CometChat account and an app: **[Create App](https://app.cometchat.com/apps)** +- A CrewAI agent endpoint (Python/FastAPI sample shown below) +- Python 3.10+ (3.11 recommended) with your preferred package manager (`uv` or `pip`) +- OpenAI (or Anthropic) API key for the agent +- Optional service-specific env vars (e.g., Product Hunt token) can live in repo root `.env` or service-level `.env`. + +--- + +## Step 1 - Create your CometChat app + + + + Sign in at app.cometchat.com. Create a new app or open an existing one. + + + Note your App ID, Region, and Auth Key (needed if you export the Chat Widget later). + + + +--- + +## Step 2 - Connect your CrewAI Agent + +Navigate to **AI Agent → BYO Agents** and then **Get Started / Integrate**. + + + + Select **CrewAI**. + + + Provide: +
    +
  • Name and optional Icon
  • +
  • (Optional) Greeting and Introductory Message
  • +
  • (Optional) Suggested messages
  • +
+
+ + Paste: +
    +
  • Agent ID — a unique handle that matches how you route traffic (e.g., support).
  • +
  • Deployment URL — the public HTTPS endpoint exposed by your CrewAI service (e.g., /kickoff).
  • +
  • (Optional) Headers — flat JSON auth headers your FastAPI deployment expects.
  • +
+
+ + Click **Save**, then ensure the agent’s toggle is **ON** in **AI Agents** list. + +
+ +> **Tip:** If you update your CrewAI agent later (prompts, tools, routing), you won’t need to re-connect it in CometChat—just keep the **Agent ID** and **Deployment URL** the same. + +--- + +## Step 3 - Define Frontend Actions (Optional) + + + + Go to AI Agent → Actions and click Add to create a frontend action your agent can call (e.g., “Open Product,” “Start Demo,” “Book Slot”). + + + Include: +
    +
  • Display Name — Shown to users (e.g., “Open Product Page”).
  • +
  • Execution Text — How the agent describes running it (e.g., “Opening product details for the user.”).
  • +
  • Name — A unique, code‑friendly key (e.g., open_product).
  • +
  • Description — What the tool does and when to use it.
  • +
  • Parameters — JSON Schema describing inputs (the agent will fill these).
  • +
+
+ + Example parameters JSON: + +```json +{ + "type": "object", + "required": ["productId"], + "properties": { + "productId": { + "type": "string", + "description": "The internal product ID to open" + }, + "utm": { + "type": "string", + "description": "Optional tracking code" + } + } +} +``` + + + At runtime, listen for tool calls and execute them client‑side (e.g., route changes, modals, highlights). + +
+ +--- + +## Step 4 - Customize in UI Kit Builder + + From AI Agents click the variant (or Get Started) to enter UI Kit Builder. + Select Customize and Deploy. + Theme, layout, features; ensure the CrewAI agent is attached. + Use live preview to validate responses & any tool triggers. + + + + } description="Embed / script" href="/ai-agents/chat-widget" horizontal /> + } href="https://www.cometchat.com/docs/ui-kit/react/ai-assistant-chat" horizontal>Pre Built UI Components + + +--- + +## Step 5 - Export & Integrate + +Choose how you’ll ship the experience (Widget or React UI Kit export). + + + Pick Chat Widget (fastest) or export React UI Kit for code-level customization. + Open UI Kit Builder → Get Embedded Code → copy script + credentials. + Export the variant as code (UI Kit) if you need deep theming or custom logic. + Preview: the CrewAI agent should appear without extra config. + + +--- + +## Step 6 - Deploy & Secure (Reference) + +If you need a starter CrewAI endpoint, you can reuse the `/kickoff` pattern from your CrewAI project. Stream newline-delimited JSON events in this order: `text_start` → `text_delta` chunks → `text_end` → `done` (emit `error` on failures). Include `message_id` plus optional `thread_id` and `run_id` for threading. + +```python +@app.post("/kickoff") +async def kickoff(request: KickoffRequest): + inputs = { + "user_message": request.messages[-1].content, + "conversation_history": "\n".join([f"{m.role}: {m.content}" for m in request.messages[:-1]]), + } + return StreamingResponse(stream_crew(inputs), media_type="application/x-ndjson") +``` + +Deploy behind HTTPS, add auth headers, and keep API keys server-side. Once live, update your CometChat agent’s **Deployment URL** to point at the public endpoint and keep the toggle **ON**. \ No newline at end of file diff --git a/docs.json b/docs.json index 2ccdf8f0..3404abbc 100644 --- a/docs.json +++ b/docs.json @@ -4870,6 +4870,27 @@ } ] }, + { + "dropdown": "CrewAI", + "icon": "/images/icons/crew-ai.svg", + "pages": [ + "/ai-agents/crew-ai", + "/ai-agents/crew-ai-actions", + "/ai-agents/crew-ai-tools", + { + "group": "Guides", + "pages": [ + "/ai-agents/crew-ai-knowledge-agent" + ] + }, + { + "group": "Tutorials", + "pages": [ + "/ai-agents/crew-ai-product-hunt-agent" + ] + } + ] + }, { "dropdown": "Agno", "icon": "/images/icons/agno.svg",