CrewAI Agents with Desearch

    CrewAI Agents with Desearch

    <Anchor label="CrewAI " target="_blank" href="https://www.crewai.com/">CrewAI </Anchor>coordinates multiple AI agents on a shared task. This page builds a two-agent crew that writes a Twitter news digest from Desearch search results.

    CrewAI Example: Twitter News Digest

    1. Install Required Packages

    bash
    pip install crewai 'crewai[tools]' desearch_py

    2. Custom Tool: Desearch for Twitter

    Create a <Anchor label="custom tool" target="_blank" href="https://docs.crewai.com/concepts/tools">custom tool</Anchor> with the CrewAI <Anchor label="@tool decorator" target="_blank" href="https://docs.crewai.com/concepts/tools#utilizing-the-tool-decorator">@tool decorator</Anchor>. Inside it, initialize the Desearch class from the <Anchor label="Desearch Python SDK" target="_blank" href="https://github.com/desearch-ai/desearch.py">Desearch Python SDK</Anchor>, send a query, and return the results.

    python
    from crewai.tools import tool from desearch_py import Desearch import os desearch_api_key = os.getenv("DESEARCH_API_KEY") @tool("Twitter Trend Search") def desearch_ai_search_tool(question: str) -> str: """Get trending Twitter posts on a topic using Desearch's Twitter source.""" desearch = Desearch(api_key=desearch_api_key) response = desearch.ai_search( prompt=question, tools=["twitter"], date_filter="PAST_24_HOURS", streaming=False, ) return str(response)

    📘 Select Desearch Methods to Use

    This example uses only the ai_search method from Desearch, connected directly to the agent's toolset.

    3. Create Agents

    Import the CrewAI modules.

    python
    from crewai import Task, Crew, Agent

    Create two agents: one gathers tweets with the Desearch tool, the other writes the digest.

    python
    twitter_analyst = Agent( role='Twitter Analyst', goal='Find the most interesting tweets and discussions about {topic} from the past 24 hours', verbose=True, memory=True, backstory="You're a social media researcher who specializes in Twitter trends.", tools=[desearch_ai_search_tool], allow_delegation=False ) digest_writer = Agent( role='Digest Writer', goal='Write a fun and engaging digest about what people are saying on Twitter about {topic}', verbose=True, memory=True, backstory="You craft lively daily digests from raw social buzz and trends.", tools=[desearch_ai_search_tool], allow_delegation=False )

    4. Create Tasks

    Assign <Anchor label="tasks" target="_blank" href="https://docs.crewai.com/concepts/Tasks/">tasks</Anchor> to each agent, then create the crew.

    python
    research_task = Task( description=( "Summarize the top Twitter conversations about {topic}." "Highlight key tweets and trends." ), expected_output='A list of 5–7 summarized tweets with short context on the {topic}.', tools=[desearch_ai_search_tool], agent=twitter_analyst, ) write_digest = Task( description=( "Write a Twitter news digest on {topic}." "Start with 'Hi folks!' and end with a playful sign-off like 'Catch you on the timeline!'" ), expected_output='A short, punchy 3-paragraph Twitter roundup article on the {topic}.', agent=digest_writer, ) crew = Crew( agents=[twitter_analyst, digest_writer], tasks=[research_task, write_digest], memory=True, cache=True, max_rpm=100, share_crew=True )

    5. Run the Crew

    Pass in a topic:

    python
    response = crew.kickoff(inputs={'topic': 'AI and robotics'}) print(response)

    6. Output

    Output

    Hi folks!

    In the latest buzz, AI and robotics are hitting the headlines with some exciting developments! Sam Altman, the pioneering brains behind OpenAI, is dreaming big about humanoid robots, forecasting their arrival within 5–10 years. But don’t get too excited just yet; the engineering challenges of creating a human-like body remain a tough nut to crack! (Check it out here).

    On the practical side of things, businesses are harnessing AI to supercharge their supply chains. One company recently reported a whopping 32% efficiency boost in just a week after deploying AI-driven models in their warehouses. Can you imagine robots darting around autonomously, optimizing inventory in real time? (Read more). And if that's not enough, firms like Hexagon Manufacturing have introduced groundbreaking platforms that revolutionize robotic motion and path planning: engineering magic in action! (More info here).

    As if that wasn’t enough, we have #Mech, the first AI-powered superhumanoid robot, tackling tough tasks in demanding environments. From cooking pancakes with custom-designed tools to handling serious warehouse chores, the future of robotics looks super fun! Robots are not just for factories anymore; they’re on their way to becoming part of our daily routines (See for yourself, and here).

    Catch you on the timeline!

    Desearch Tool Functions

    • ai_search_tool: AI-powered search across multiple sources, including web pages, research papers, and social media.
    • twitter_search_tool: retrieves links and tweets matching a search query, without AI models.
    • web_search_tool: plain web search, like a normal search engine.