A Step-by-Step Guide Using CrewAI and Capella AI Services
In this tutorial, you will learn how to build a sophisticated multi-agent AI system that generates creative content using Couchbase Capella AI Services for storing data, generating embeddings using embedding models and LLM inference. We will create a “Seinfeld Script Generator” that demonstrates:
- Multi-agent orchestration with CrewAI
- RAG (Retrieval Augmented Generation) with Couchbase Query Vector Search
- Couchbase Capella Model Service for hosting the embedding model and LLM
- Couchbase Vectorization Service for vectorizing data stored in Couchbase
By the end, you will have a working system where multiple specialized AI agents collaborate to generate authentic TV scripts.
What Are Multi-Agent Workflows?
Multi-agent workflows involve multiple AI agents working together, each specializing in a specific task — much like a TV writers’ room.
Agents and Their Roles
| Agente | Função | Specialty |
| Theme Analyzer | Breaks down the theme | Identifies comedic angles |
| Plot Architect | Designs story structure | Creates A/B/C threads |
| Character Voice Expert | Ensures authenticity | Matches character speech |
| Dialogue Writer | Writes scenes | Dialogue + stage directions |
| Quality Reviewer | Final editor | Ensures consistency |
Why Couchbase Capella AI Services?
Couchbase Capella AI Services provides:
- Unified platform: Database + Vectorization + Search + Models
- Vectorization for document embeddings
- Embeddings API
- LLM inference
- Vector Search for semantic matching
Setting up Couchbase Capella Services
Create a Cluster in Couchbase Capella
- Faça login em Couchbase Capella.
- Create a new cluster or use an existing one. Note that the Cluster needs to run the latest version of Couchbase Server (8.0) with the Data, Query, Index and the Eventing services.
- Create a bucket (e.g., seinfeld)
- Create a scope (e.g., episodes) and collection (e.g., roteiros) for your data
Enable AI Services
- Navigate to Capella’s AI Services section on the UI.
- Deploy the Embeddings and LLM models
- You need to launch an embedding & an LLM for this demo in the same region as the Capella cluster where the data will be stored.
- For this demo to work well, you need to deploy a large language model (LLM) that has tool calling capabilities such as mistralai/mistral-7b-instruct-v0.3. For embeddings, you can choose a model like the nvidia/llama-3.2-nv-embedqa-1b-v2.
- Note down the endpoint URL and generate API keys.
For more details on launching AI models, you can check the documentação oficial.
Load Your Data
For this tutorial, we are using the public dataset containing all the dialogues from Seinfeld from Kaggle. We can import this into our Couchbase Capella cluster using any of the supported import modes tais como cbimport or the UI.
Your documents should have this structure:
|
1 2 3 4 5 6 7 |
json { "Character": "JERRY", "Dialogue": "What's the deal with airline peanuts?", "Season": 3, "EpisodeNo": 15, } |
Vectorization & Creating Vector Search Index
We can use the Vectorization Service for structured data to vectorize the dialogues stored in the Couchbase collection.
In this case as our data is already in a structured format inside the Couchbase cluster, we can use the Vectorize from Structured Data workflow.
We need to embed the Dialogue field into a new field, dialogue_embedding.
During the Vectorization workflow, we can also create the highly performant Hyperscale Vector Index for vector search with good default values.
After the workflow is completed, we will see an additional field in all the documents containing the dialogue_embedding campo.
Building the Agent
We build out multiple agents using CrewAI for orchestrating the agents. Each agent has a dedicated function related to the overall task of generating the script. The agents communicate with each other using the shared context to achieve the overall goal.
The code for the agent can be found in this Github Repository para referência.
Key Concepts
RAG (Retrieval Augmented Generation)
RAG enhances LLM outputs by providing relevant context from a database. In this case, we provide dialogues similar to the user provided input.
Agent Collaboration
Agents pass information through task context:
Capella AI Model Services Integration
Couchbase Capella AI Services provides OpenAI-compatible endpoints that are used by the Agents. For embeddings, we are using the LangChain OpenAI package as it is used in association with the LangChain Couchbase integration. For the LLM, we are using the Capella model through LiteLLM in CrewAI.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
python # Embeddings de langchain_openai importação Aberturas do OpenAIEmbeddings incorporações = Aberturas do OpenAIEmbeddings( openai_api_key=CAPELLA_EMBEDDING_KEY, openai_api_base=CAPELLA_ENDPOINT, modelo=EMBEDDING_MODEL_NAME, ) # LLM de crewai importação LLM lm = LLM( modelo=LLM_NAME, chave api=CAPELLA_LLM_KEY, base_url=CAPELLA_ENDPOINT, ) |
Testing it Out
Input: Jerry gets a smart speaker that mishears everything
Saída:
# Seinfeld Episode: Jerry gets a smart speaker that mishears everything
**Title:** The Smart Speaker
—
### Cold Open – INT. JERRY’S APARTMENT
*(Jerry stands by his new smart speaker on the counter, trying to keep patience.)*
**JERRY:**
Play “Take Five” by Dave Brubeck.
**SPEAKER:**
Ordering five cans of decaf.
*(Jerry blinks, deadpan.)*
**JERRY:**
Well, at least my caffeine addiction’s been acknowledged.
*(Kramer bursts in, wild-eyed and waving his arms.)*
**KRAMER:**
Jerry! You gotta get one of these! It’s the future, buddy!
*(Elaine enters, arms crossed, scowling.)*
**ELAINE:**
It just called me “Helen.” Helen! Who’s Helen?
*(George frantically calls from next door.)*
**GEORGE (O.S.):**
Jerry, I think it’s spying on me!
*(Jerry shrugs.)*
**JERRY:**
Great, now the toaster’s taking sides.
*(He turns to camera.)*
**JERRY:**
For something called “smart,” this is the dumbest roommate I’ve ever had.
—
### Scene 2 – INT. JERRY’S APARTMENT
*(Jerry holds his phone, increasingly annoyed. The speaker sits innocently.)*
**JERRY:**
Set reminder: buy milk.
**SPEAKER:**
Playing “Don’t Cry for Me, Argentina.”
**JERRY:**
That’s not a reminder. That’s a musical betrayal.
*(Elaine storms in, glaring.)*
**ELAINE:**
Called me Helen again. Helen! Who’s Helen?
**JERRY:**
Maybe it’s trying to give you a new identity.
**ELAINE:** *(sarcastic)*
Wonderful. A witness protection program via electronics.
*(Kramer slides in proudly, holding a contraption hooked to the speaker.)*
**KRAMER:**
Relax! The Kramer upgrade! Predicts what you want before you know it!
**JERRY:** *(skeptical)*
Last time you fixed something, I ended up with a fountain show in my living room.
**KRAMER:**
Hey, artistry!
—
### Scene 3 – INT. GEORGE’S OFFICE
*(George paces nervously, whispering on phone.)*
**GEORGE:**
It’s spying, Jerry! I found recordings… conversations plotting against me!
*(Plays a garbled clip.)*
**GEORGE:**
Proof!
*(Coworker passes, smirks.)*
**COWORKER:**
Talking to your phone again? Chill, George.
**GEORGE:**
They want silence! That’s what they want!
—
### Scene 4 – INT. ELAINE’S OFFICE
*(Elaine on video call; speaker mispronounces.)*
**SPEAKER:**
Playing “Helen of Troy” audiobook.
**ELAINE:** *(shouting)*
No! Not Helen! Elaine!
*(Coworker offscreen whispers.)*
**COWORKER:**
Is her phone possessed or what?
—
### Scene 5 – INT. JERRY’S APARTMENT – NIGHT
*(Jerry’s on a date; suddenly goat noises blare from speaker.)*
**JERRY’S DATE:**
What was that?!
**JERRY:**
My smart speaker… less smart than me.
*(Elaine hears speaker loudly call out “Helen” nearby, folding arms.)*
**ELAINE:**
Helen strikes again.
*(Jerry and Elaine exchange a look.)*
—
### Scene 6 – INT. JERRY’S APARTMENT
*(Kramer unveils modded speaker.)*
**KRAMER:**
Trust me! This baby anticipates what you want!
*(Presses button; speaker erupts with goat bleats, random announcements; lights flicker.)*
**JERRY:**
Great. It’s a jazz club haunted house.
*(Elaine yells at device; George storms in frantic.)*
**GEORGE:**
Kramer! You’re involved! This is sabotage!
**KRAMER:**
No, just a little chaos for creativity!
*(Speaker blasts George’s conspiracy tape at full volume.)*
**GEORGE:**
No! Not the tape!
*(Lights go out; silence.)*
—
### Finale – INT. MONK’S CAFÉ
*(The group sits, exhausted.)*
**JERRY:**
For something called “smart,” this is the dumbest roommate I’ve ever had.
**ELAINE:**
It still calls me Helen. Helen! I don’t know any Helen!
**GEORGE:**
Lost my job, my date. If it listens one more time, I’m moving.
**KRAMER:** *(grinning)*
I’m working on the next version. It’s gonna be revolutionary!
**JERRY:** *(to camera, dry)*
Revolutions never go quietly.
—
### Tag – INT. JERRY’S APARTMENT – NIGHT
*(Jerry unplugs the speaker, sighs.)*
**SPEAKER:**
(static) Goodbye, Jerry.
*(Jerry looks to camera.)*
**JERRY:**
Even the dumb ones say goodbye.
*(Fade out.)*
—
**Quality Rating:** 9/10
**Notes:**
– Character voices ring true: Jerry’s sardonic, dry wit perfectly captures Seinfeld’s observational humor on tech failings. George’s paranoid neurosis sharply escalates in classic fashion. Elaine’s indignation about mistaken names is on point and amusingly personal. Kramer’s wild enthusiasm undercuts the chaos effectively.
– Plot threads interweave cleanly and resolve with escalating miscommunications coming to head in Kramer’s “upgrade” fiasco.
– Callbacks (“Helen!”, George’s “It’s spying!”, Kramer’s “revolutionary” fix) are well-timed and hit naturally.
– The humor is observational, grounded in very modern but mundane tech frustrations, avoiding slapstick or overly broad jokes.
– Scene pacing is brisk, with normal scene lengths reflecting classic sitcom rhythm; stage directions cue timing and reaction beats to maximize punchlines.
– Dialogue incrementally polished for tighter punchlines and clarity, retaining classic Seinfeld rhythm and pacing.
– Ending punchline and tag scene effectively mirror Seinfeld’s customary dry closing meta-commentary.
This episode would fit seamlessly into the original series, showcasing each character’s neurotic response to a simple modern annoyance blown hilariously out of proportion.
Resumo
In this tutorial, you learned how to:
- Build a multi-agent AI system with CrewAI
- Vectorize data using Couchbase Vectorization Workflows
- Use Couchbase Capella AI Services for embeddings and LLM
- Implement RAG with Couchbase Vector Search (Hyperscale Index)
The combination of Couchbase’s unified data platform with CrewAI’s multi-agent framework creates powerful AI applications that can generate high-quality, contextually-aware content.