Sunday, July 27, 2025
HomeArtificial IntelligenceConstruct an AI Agent from scratch with CrewAI and Clarifai

Construct an AI Agent from scratch with CrewAI and Clarifai

AI brokers are software program techniques designed to purpose, plan, and act towards reaching outlined objectives. They transfer past easy automation by making selections, adapting to altering data, and coordinating a number of steps to finish complicated duties.

The operational effectiveness of AI brokers is underpinned by a number of core ideas:

At their core, brokers use Giant Language Fashions (LLMs) as their reasoning engine. Nevertheless, the true functionality of an agent comes from combining this intelligence with these supporting elements, enabling them to behave successfully in dynamic, real-world environments.

Whereas LLMs present the reasoning energy for brokers, they want structured approaches to deal with complicated duties successfully. That is the place agentic design patterns are available. These are confirmed methods that information brokers to purpose, act, and enhance over time.

Listed below are three of the most typical and efficient patterns for constructing sensible brokers:

These patterns are sometimes mixed. For instance, a multi agent system might use ReAct for particular person brokers whereas using Reflection on the system stage to refine outputs. Collectively, they type a basis for constructing extra succesful, dependable, and clear brokers that may sort out more and more complicated duties.

Now, let’s construct a easy AI agent from scratch.

Constructing an AI Agent from Scratch

Let’s put the whole lot collectively by constructing a easy agent utilizing Crew AI. For this instance, we’ll create a blog-writing agent that may analysis matters, collect data, and generate well-structured content material.

Step 1: Outline Instruments

A software is a perform that an agent can name to carry out actions. Instruments develop what the mannequin can do — fetching real-time knowledge, querying APIs, summarizing paperwork, and even publishing outcomes.

Each agentic framework supplies some predefined instruments for widespread duties akin to net search or file operations, however for particular workflows you typically must outline customized instruments. Within the case of a blog-writing agent, step one is with the ability to collect analysis materials for a given matter.

Right here’s a easy customized software that does that:

This can be a easy instance for demonstration. In a real-world setup, the fetch_research_data perform would name an exterior API (like an online search service or data base) or scrape trusted sources to return precise, up-to-date analysis.

With this software in place, our blog-writing agent will be capable to accumulate background materials earlier than drafting any content material.

Step 2: Choose and Configure the Language Mannequin

Giant language mannequin (LLM) is the reasoning core of our agent. It processes inputs, breaks down duties, and generates structured outputs. For a blog-writing agent, this implies analyzing analysis materials, drafting outlines, and creating coherent content material that aligns with the subject.

Not all fashions are equally suited to this. For agentic workflows, it’s greatest to make use of fashions which can be optimized for reasoning and able to working with instruments. Whereas giant foundational fashions present robust normal efficiency, smaller or fine-tuned fashions may be extra environment friendly and cost-effective for particular duties like content material era.

Clarifai supplies a wide range of fashions accessible via an OpenAI-compatible API, making it simple to combine them into an agent’s workflow. For this blog-writing agent, we’ll use DeepSeek-R1-Distill-Qwen-7B.

Earlier than configuring the mannequin, you’ll must set your Clarifai Private Entry Token (PAT) as an surroundings variable so the API can authenticate your requests.

Right here’s the right way to configure it:

This configuration connects our agent to the DeepSeek-R1-Distill-Qwen-7B mannequin utilizing the OpenAI-compatible endpoint. In manufacturing, you might simply swap this mannequin for an additional relying in your content material wants — for instance, a bigger mannequin for extra complicated reasoning or a smaller one for sooner drafts.

With this setup, our blog-writing agent now has a purposeful core that may course of analysis inputs and switch them into structured, well-written content material.

Step 3: Create the Agent, Process, and Crew

With our analysis software outlined and the mannequin configured, we will now assemble the core elements of our system:

  • Agent: The clever entity with an outlined function, objective, and backstory.

  • Process: The particular work we would like the agent to perform.

  • Crew: The orchestrator that manages brokers and duties.

For our use case, we’ll create a blog-writing specialist who can collect analysis, analyze it, and generate a structured draft.

On this setup:

  • Agent: We outline a weblog writing specialist with a transparent function, objective, and backstory. This agent makes use of the fetch_research_data software to collect data earlier than drafting the weblog.
  • Process: We create a effectively scoped activity describing what must be produced: a complete weblog submit on “The Way forward for AI Brokers” that covers developments, breakthroughs, and actual world functions. The anticipated output is an entire markdown formatted draft.
  • Crew: We carry the agent and activity collectively right into a Crew that handles execution. Whereas this instance makes use of just one agent, the identical construction can simply scale to multi agent initiatives.

With these elements in place, the agent has the whole lot it wants: a transparent goal, the correct instruments, and an actionable activity to ship a effectively structured, top quality weblog draft.

Step 4: Run the Agent

To execute our setup, we name project_crew.kickoff(). This methodology triggers the complete workflow — the agent interprets the duty, makes use of the analysis software to collect insights, causes via the data, and generates an entire weblog draft.

Right here’s the whole code:

In case you are trying to construct and deploy your individual customized MCP servers, take a look at our detailed weblog tutorial right here. As soon as constructed, these MCP servers may be built-in as instruments inside your AI brokers, enabling you to create MCP-powered agentic functions. We’ll dive deeper into this integration in upcoming tutorials.

Conclusion

On this information, we lined what AI brokers are, their key elements and design patterns, and constructed a blog-writing agent utilizing a Clarifai-hosted reasoning mannequin, displaying how instruments, reminiscence, and reasoning work collectively to create dynamic, goal-driven techniques.

That mentioned, it’s vital to do not forget that brokers are usually not at all times the correct alternative. When constructing functions with LLMs, it’s greatest to start out easy and solely add complexity when it’s wanted. For a lot of use circumstances, workflows and even well-structured single LLM calls with retrieval and in-context examples may be sufficient.

Workflows are predictable and constant for well-defined duties, whereas brokers turn out to be precious once you want flexibility, adaptive reasoning, or model-driven decision-making at scale. Agentic techniques typically commerce off latency and price for higher activity efficiency, so think about the place that tradeoff is sensible to your software.

If you wish to dive deeper into constructing extra superior functions, discover extra AI agent examples within the GitHub repo. Try the documentation to study how one can construct with different agent frameworks akin to Google SDK, OpenAI SDK, and Vercel AI SDK.


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments