CrewAI is a powerful Python framework for orchestrating autonomous AI agents. It helps you build sophisticated multi-agent systems that can collaborate to accomplish complex tasks. Because CrewAI is built on top of LangChain, it seamlessly integrates with any OpenAI-compatible API, including Voidon.
In this tutorial, we will create a simple research "crew" consisting of two agents: 1. A Researcher Agent that uses a search tool to find information. 2. A Writer Agent that takes the researcher's findings and writes a brief report.
Why use a framework like CrewAI?
Instead of manually managing the conversation history and the tool-calling loop, CrewAI abstracts this complexity away. You simply define the agents, their tools, and their tasks, and the framework orchestrates the entire workflow.
First, we need to configure CrewAI to use the Voidon API endpoint. We do this by instantiating a ChatOpenAI object and passing our base_url and api_key.
importosfromcrewaiimportAgent,Task,Crew,Processfromlangchain_openaiimportChatOpenAIfromcrewai_toolsimportSerperDevTool# Set your Voidon API Key# It is recommended to set this as an environment variableos.environ["VOIDON_API_KEY"]="your-voidon-api-key"os.environ["SERPER_API_KEY"]="Your Serper API Key"# serper.dev API key# Configure the LLM to use the Voidon endpointvoidon_llm=ChatOpenAI(model="auto",base_url="https://api.voidon.astramind.ai/v1",api_key=os.environ.get("VOIDON_API_KEY"))
Now, we define our agents. Each agent has a role, a goal, a backstory, and the tools it can access. We must also assign the LLM instance to each agent.
# Create a researcher agentresearcher=Agent(role='Senior Research Analyst',goal='Uncover cutting-edge developments in AI and data science',backstory="""You work at a leading tech think tank. Your expertise lies in identifying emerging trends. You have a knack for dissecting complex data and presenting actionable insights.""",verbose=True,allow_delegation=False,tools=[search_tool],llm=voidon_llm)# Create a writer agentwriter=Agent(role='Tech Content Strategist',goal='Craft compelling content on tech advancements',backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles. You transform complex concepts into compelling narratives.""",verbose=True,allow_delegation=True,llm=voidon_llm)
# Create tasks for the agentsresearch_task=Task(description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024. Identify key trends, breakthrough technologies, and potential industry impacts. Your final answer MUST be a full analysis report.""",expected_output='A comprehensive 3-paragraph summary of the latest AI advancements.',agent=researcher)write_task=Task(description="""Using the research analyst's report, develop an engaging blog post that highlights the most significant AI advancements. Your post should be informative yet accessible, catering to a tech-savvy audience. Make it sound cool, avoid complex words so it doesn't sound like AI.""",expected_output='A 4-paragraph blog post on the latest AI advancements.',agent=writer)
# Instantiate your crew with a sequential processcrew=Crew(agents=[researcher,writer],tasks=[research_task,write_task],process=Process.sequential,verbose=2# You can set it to 1 or 2 for different logging levels)# Get your crew to work!result=crew.kickoff()print("######################")print("Crew Final Result:")print(result)