Skip to main content
Keep group chats clean: the agent replies only when explicitly tagged, includes mentions in its response, and keeps context short.

What you’ll build

  • A CrewAI agent that checks for mentions (e.g., @agent).
  • Backstory rules to ignore chatter unless addressed.
  • A /kickoff stream that returns concise answers and optional tool calls.

Prerequisites

  • CrewAI project and /kickoff endpoint from crew-ai.mdx
  • Client ability to pass conversation history and mention metadata

Steps

1

Set a mention keyword

Decide on a handle (e.g., @agent or @support) that users will type in group rooms.
2

Add mention logic

Pass a boolean or mention list into the task input so the agent knows when it is addressed.
3

Keep answers short

In the backstory, limit reply length and avoid re-quoting the entire thread.
4

Connect in CometChat

Point your AI Agent to the CrewAI /kickoff URL and set a friendly display name/icon.

Agent configuration

src/crew_demo/config/agents.yaml
group_agent:
  role: Group Chat Assistant
  goal: Reply only when mentioned and keep messages concise
  backstory: >
    Respond only if the latest message contains "@agent" (case-insensitive).
    Keep replies under 4 sentences. If not mentioned, politely stay silent.
src/crew_demo/config/tasks.yaml
group_task:
  description: >
    If mentioned: respond to {user_message}. Otherwise return an empty reply.
    Conversation: {conversation_history}
  expected_output: >
    A short answer or an empty string when not mentioned.
  agent: group_agent
In your FastAPI kickoff, include a flag:
inputs = {
  "user_message": request.messages[-1].content,
  "conversation_history": "\n".join([...]),
  "mentioned": "@agent" in request.messages[-1].content.lower(),
}
The task can check mentioned in its prompt and return an empty string to suppress replies.

CometChat setup

  • Provider: CrewAI
  • Agent ID: group_agent
  • Deployment URL: /kickoff
  • Suggested prompts: “@agent what is our refund policy?”