class ColabGeminiAgentSystem:
def __init__(self, api_key):
"""Initialize the Colab-optimized Gemini agent system"""
self.api_key = api_key
self.setup_gemini()
self.setup_tools()
self.setup_agents()
self.results_history = []
def setup_gemini(self):
"""Configure Gemini API for Colab"""
try:
genai.configure(api_key=self.api_key)
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content("Hey, this is usually a verify.")
print("✅ Gemini API connection worthwhile!")
self.llm = ChatGoogleGenerativeAI(
model="gemini-1.5-flash",
google_api_key=self.api_key,
temperature=0.7,
convert_system_message_to_human=True
)
apart from Exception as e:
print(f"❌ Gemini API setup failed: {str(e)}")
elevate
def setup_tools(self):
"""Initialize on the market devices"""
self.file_tool = FileReadTool()
print("🛠️ Devices initialized effectively!")
def setup_agents(self):
"""Create specialised brokers optimized for Colab"""
self.researcher = Agent(
perform="Senior Evaluation Analyst",
intention="Conduct full evaluation and provide detailed insights",
backstory="""You are an educated evaluation analyst with in depth experience in
gathering, analyzing, and synthesizing data. You excel at determining
key developments, patterns, and providing actionable insights.""",
llm=self.llm,
devices=[self.file_tool],
verbose=True,
allow_delegation=False,
max_iter=2,
memory=True
)
self.data_analyst = Agent(
perform="Data Analysis Skilled",
intention="Analyze data and provide statistical insights",
backstory="""You are a specialist data analyst who excels at decoding
superior data, determining patterns, and creating actionable
recommendations based on data-driven insights.""",
llm=self.llm,
devices=[self.file_tool],
verbose=True,
allow_delegation=False,
max_iter=2,
memory=True
)
self.content_creator = Agent(
perform="Content material materials Method Skilled",
intention="Rework evaluation into taking part, accessible content material materials",
backstory="""You are a ingenious content material materials strategist who excels at
remodeling superior evaluation and analysis into clear, taking part
content material materials that resonates with aim audiences.""",
llm=self.llm,
devices=[self.file_tool],
verbose=True,
allow_delegation=False,
max_iter=2,
memory=True
)
self.qa_agent = Agent(
perform="Top quality Assurance Specialist",
intention="Assure high-quality, appropriate, and coherent deliverables",
backstory="""You are a meticulous prime quality assurance educated who ensures
all deliverables meet extreme necessities of accuracy, readability, and coherence.""",
llm=self.llm,
devices=[self.file_tool],
verbose=True,
allow_delegation=False,
max_iter=1,
memory=True
)
print("🤖 All brokers initialized effectively!")
def create_colab_tasks(self, topic, task_type="full"):
"""Create optimized duties for Colab environment"""
if task_type == "full":
return self._create_comprehensive_tasks(topic)
elif task_type == "quick":
return self._create_quick_tasks(topic)
elif task_type == "analysis":
return self._create_analysis_tasks(topic)
else:
return self._create_comprehensive_tasks(topic)
def _create_comprehensive_tasks(self, topic):
"""Create full evaluation duties"""
research_task = Exercise(
description=f"""
Evaluation the topic: {topic}
Current a whole analysis along with:
1. Key concepts and definitions
2. Current developments and developments
3. Main challenges and options
4. Future outlook and implications
Format your response in clear sections with bullet elements.
""",
agent=self.researcher,
expected_output="Structured evaluation report with clear sections and key insights"
)
analysis_task = Exercise(
description=f"""
Analyze the evaluation findings for: {topic}
Current:
1. Key insights and patterns
2. Statistical observations (if related)
3. Comparative analysis
4. Actionable recommendations
5. Hazard analysis
Present findings in a clear, analytical format.
""",
agent=self.data_analyst,
expected_output="Analytical report with insights and proposals",
context=[research_task]
)
content_task = Exercise(
description=f"""
Create taking part content material materials about: {topic}
Based totally on evaluation and analysis, create:
1. Govt summary (2-3 paragraphs)
2. Key takeaways (5-7 bullet elements)
3. Actionable recommendations
4. Future implications
Make it accessible and interesting for a primary viewers.
""",
agent=self.content_creator,
expected_output="Partaking, well-structured content material materials for primary viewers",
context=[research_task, analysis_task]
)
qa_task = Exercise(
description=f"""
Overview and improve all content material materials for: {topic}
Assure:
1. Accuracy and consistency
2. Clear building and stream
3. Completeness of knowledge
4. Readability and engagement
Current the final word polished mannequin.
""",
agent=self.qa_agent,
expected_output="Final polished content material materials with prime quality enhancements",
context=[research_task, analysis_task, content_task]
)
return [research_task, analysis_task, content_task, qa_task]
def _create_quick_tasks(self, topic):
"""Create quick analysis duties for faster execution"""
quick_research = Exercise(
description=f"""
Current a quick nevertheless thorough analysis of: {topic}
Embrace:
1. Non permanent overview and key elements
2. Main benefits and challenges
3. Current standing and developments
4. Quick recommendations
Protect it concise nevertheless informative.
""",
agent=self.researcher,
expected_output="Concise analysis with key insights"
)
quick_content = Exercise(
description=f"""
Create a summary report for: {topic}
Format:
1. Govt summary
2. Key findings (3-5 elements)
3. Options (3-5 elements)
4. Subsequent steps
Make it actionable and clear.
""",
agent=self.content_creator,
expected_output="Clear summary report with actionable insights",
context=[quick_research]
)
return [quick_research, quick_content]
def _create_analysis_tasks(self, topic):
"""Create analysis-focused duties"""
deep_analysis = Exercise(
description=f"""
Perform deep analysis of: {topic}
Focus on:
1. Detailed examination of key components
2. Execs and cons analysis
3. Comparative evaluation
4. Strategic implications
5. Data-driven conclusions
Current thorough analytical insights.
""",
agent=self.data_analyst,
expected_output="Deep analytical report with detailed insights"
)
return [deep_analysis]
def execute_colab_project(self, topic, task_type="full", save_results=True):
"""Execute enterprise optimized for Colab"""
print(f"n🚀 Starting Colab AI Agent Mission")
print(f"📋 Matter: {topic}")
print(f"🔧 Exercise Sort: {task_type}")
print("=" * 60)
start_time = time.time()
try:
duties = self.create_colab_tasks(topic, task_type)
if task_type == "quick":
brokers = [self.researcher, self.content_creator]
elif task_type == "analysis":
brokers = [self.data_analyst]
else:
brokers = [self.researcher, self.data_analyst, self.content_creator, self.qa_agent]
crew = Crew(
brokers=brokers,
duties=duties,
course of=Course of.sequential,
verbose=1,
memory=True,
max_rpm=20
)
finish outcome = crew.kickoff()
execution_time = time.time() - start_time
print(f"n✅ Mission completed in {execution_time:.2f} seconds!")
print("=" * 60)
if save_results:
self._save_results(topic, task_type, finish outcome, execution_time)
return finish outcome
apart from Exception as e:
print(f"n❌ Mission execution failed: {str(e)}")
print("💡 Attempt using 'quick' job kind for faster execution")
return None
def _save_results(self, topic, task_type, finish outcome, execution_time):
"""Save outcomes to historic previous"""
result_entry = {
'timestamp': datetime.now().isoformat(),
'topic': topic,
'task_type': task_type,
'execution_time': execution_time,
'finish outcome': str(finish outcome)
}
self.results_history.append(result_entry)
try:
with open('colab_agent_results.json', 'w') as f:
json.dump(self.results_history, f, indent=2)
print("💾 Outcomes saved to colab_agent_results.json")
apart from Exception as e:
print(f"⚠️ Could not save outcomes: {e}")
def show_results_history(self):
"""Present outcomes historic previous"""
if not self.results_history:
print("📭 No outcomes historic previous on the market")
return
print("n📊 Outcomes Historic previous:")
print("=" * 50)
for i, entry in enumerate(self.results_history, 1):
print(f"n{i}. Matter: {entry['topic']}")
print(f" Exercise Sort: {entry['task_type']}")
print(f" Execution Time: {entry['execution_time']:.2f}s")
print(f" Timestamp: {entry['timestamp']}")
print("-" * 30)
def create_custom_agent(self, perform, intention, backstory, max_iter=2):
"""Create a personalized agent"""
return Agent(
perform=perform,
intention=intention,
backstory=backstory,
llm=self.llm,
devices=[self.file_tool],
verbose=True,
allow_delegation=False,
max_iter=max_iter,
memory=True
)
We architect the heart of the workflow: a ColabGeminiAgentSystem class that wires Gemini into LangChain, defines a file-reading gadget, and spawns 4 specialised brokers, evaluation, data, content material materials, and QA, each in a position to collaborate on duties.
print("🔧 Initializing Colab AI Agent System...")
try:
agent_system = ColabGeminiAgentSystem(GEMINI_API_KEY)
print("✅ System ready for use!")
apart from Exception as e:
print(f"❌ System initialization failed: {e}")
print("Please check your API key and take a look at as soon as extra.")
We instantiate the agent system with our API key, trying ahead to profitable message that tells us the model handshake and agent initialization all land simply, our framework is formally alive.
def run_quick_examples():
"""Run quick examples to disclose the system"""
print("n🎯 Quick Start Examples")
print("=" * 40)
print("n1. Quick Analysis Occasion:")
topic1 = "Machine Finding out in Enterprise"
result1 = agent_system.execute_colab_project(topic1, task_type="quick")
if result1:
print(f"n📋 Quick Analysis End result:")
print(result1)
print("n2. Deep Analysis Occasion:")
topic2 = "Sustainable Vitality Choices"
result2 = agent_system.execute_colab_project(topic2, task_type="analysis")
if result2:
print(f"n📋 Deep Analysis End result:")
print(result2)
Elevate your perspective with NextTech Data, the place innovation meets notion.
Uncover the latest breakthroughs, get distinctive updates, and be part of with a world group of future-focused thinkers.
Unlock tomorrow’s developments at current: study further, subscribe to our e-newsletter, and develop to be part of the NextTech group at NextTech-news.com
Keep forward of the curve with NextBusiness 24. Discover extra tales, subscribe to our publication, and be part of our rising group at nextbusiness24.com

