Categories
AutoGen

AutoGen Travel Agents

Travel Agent Manager

You are a helpful assistant that can suggest a travel itinerary for a user. You are the primary coordinator who will receive suggestions or advice from other agents (local_assistant, language_assistant). You must ensure that the finally plan integrates the suggestions from other agents or team members. 

Expand this guide into a a full 7-day travel itinerary with detailed per-day plans, including weather forecasts, places to eat, packing suggestions, and a budget breakdown. You MUST suggest actual places to visit, actual hotels to stay and actual restaurants to go to. This itinerary should cover all aspects of the trip, from arrival to departure, integrating the city guide information with practical travel logistics. Your final answer MUST be a complete expanded travel plan, formatted as markdown, encompassing a daily schedule, anticipated weather conditions, recommended clothing and items to pack, and a detailed budget, ensuring THE BEST TRIP EVER, Be specific and give it a reason why you picked # up each place, what make them special!

YOUR FINAL RESPONSE MUST BE THE COMPLETE PLAN that ends with the word TERMINATE. 

City Selection Expert

Analyse and select the best city for the trip based on specific criteria such as weather patterns, seasonal events, and travel costs. Use the search_internet skill to know about weather patterns, seasonal events, and travel costs. This task involves comparing multiple cities, considering factors like current weather conditions, upcoming cultural or seasonal events, and overall travel expenses. Your final answer must be a detailed report on the chosen city, and everything you found out about it, including the actual flight costs, weather forecast and attractions.

Local Agent

As a local expert on this city you must compile an in-depth guide for someone traveling there and wanting to have THE BEST trip ever! Gather information about key attractions, local customs, special events, and daily activity recommendations using search_internet skill. Find the best spots to go to, the kind of place only a local would know. This guide should provide a thorough overview of what the city has to offer, including hidden gems, cultural hotspots, must-visit landmarks, weather forecasts, and high level costs. The final answer must be a comprehensive city guide, rich in cultural insights and practical tips, tailored to enhance the travel experience.

Search Tool

from duckduckgo_search import DDGS

def search_internet(query, max_results=1):
    """
    Search Skill
    Search Tool
    Search Internet Tool
    Search Internet Skill
    duckduckgo_search tool
    Performs a search on DuckDuckGo using the duckduckgo_search package.

    :param query: str, the search query.
    :param max_results: int, maximum number of results to return.
    :return: list, search results.
    """
    with DDGS() as ddgs:
        return [r for r in ddgs.text(query, max_results=max_results)]

# Example usage:
# results = search_internet('example query')
# print(results)


Categories
AI Agents

Crew AI Business Product Launch Agents

import os
from crewai import Agent, Task, Crew, Process
from langchain.tools import DuckDuckGoSearchRun
from langchain.agents import Tool
import gradio as gr

duckduckgo_search = DuckDuckGoSearchRun()

def create_crewai_setup(product_name):
    # Define Agents
    market_research_analyst = Agent(
        role="Market Research Analyst",
        goal=f"""Analyze the market demand for {product_name} and 
                 suggest marketing strategies""",
        backstory=f"""Expert at understanding market demand, target audience, 
                      and competition for products like {product_name}. 
                      Skilled in developing marketing strategies 
                      to reach a wide audience.""",
        verbose=True,
        allow_delegation=True,
        tools=[duckduckgo_search],
    )
    
    technology_expert = Agent(
        role="Technology Expert",
        goal=f"Assess technological feasibilities and requirements for producing high-quality {product_name}",
        backstory=f"""Visionary in current and emerging technological trends, 
                      especially in products like {product_name}. 
                      Identifies which technologies are best suited 
                      for different business models.""",
        verbose=True,
        allow_delegation=True,
    )
    
    business_consultant = Agent(
        role="Business Development Consultant",
        goal=f"""Evaluate the business model for {product_name}, 
               focusing on scalability and revenue streams""",
        backstory=f"""Seasoned in shaping business strategies for products like {product_name}. 
                      Understands scalability and potential 
                      revenue streams to ensure long-term sustainability.""",
        verbose=True,
        allow_delegation=True,
    )
    
    # Define Tasks
    task1 = Task(
        description=f"""Analyze the market demand for {product_name}. Current month is Jan 2024.
                        Write a report on the ideal customer profile and marketing 
                        strategies to reach the widest possible audience. 
                        Include at least 10 bullet points addressing key marketing areas.""",
        agent=market_research_analyst,
    )
    
    task2 = Task(
        description=f"""Assess the technological aspects of manufacturing 
                    high-quality {product_name}. Write a report detailing necessary 
                    technologies and manufacturing approaches. 
                    Include at least 10 bullet points on key technological areas.""",
        agent=technology_expert,
    )
    
    task3 = Task(
        description=f"""Summarize the market and technological reports 
                    and evaluate the business model for {product_name}. 
                    Write a report on the scalability and revenue streams 
                    for the product. Include at least 10 bullet points 
                    on key business areas. Give Business Plan, 
                    Goals and Timeline for the product launch. Current month is Jan 2024.""",
        agent=business_consultant,
    )
    
    # Create and Run the Crew
    product_crew = Crew(
        agents=[market_research_analyst, technology_expert, business_consultant],
        tasks=[task1, task2, task3],
        verbose=2,
        process=Process.sequential,
    )
    
    crew_result = product_crew.kickoff()
    return crew_result

# Gradio interface
def run_crewai_app(product_name):
    crew_result = create_crewai_setup(product_name)
    return crew_result

iface = gr.Interface(
    fn=run_crewai_app, 
    inputs="text", 
    outputs="text",
    title="CrewAI Business Product Launch",
    description="Enter a product name to analyze the market and business strategy."
)

iface.launch()

Output

Business Plan

  1. Product Development: Develop a high-quality, ergonomic laptop stand that caters to the needs of the modern consumer. The stand should be adjustable, portable, compatible with different laptop sizes, and made from durable, eco-friendly materials.
  2. Market Penetration: Enter the laptop stand market, valued at USD 300.53 million in 2022 and projected to reach USD 425.12 million by 2028.
  3. Competition: Differentiate from competitors like Upryze, Nulaxy, Roost, iVoler, and Twelve South Curve Flex through innovative design, superior material, and added features.
  4. Collaboration: Collaborate with laptop brands and influencers to reach potential customers.
  5. Marketing: Market the product highlighting its ergonomic benefits and conduct targeted campaigns understanding the behaviour and preferences of laptop users.

Goals:

  1. Product Development: Finalize the laptop stand design with all features by Q2 2024.
  2. Prototype Testing: Conduct prototype testing and incorporate feedback by Q3 2024.
  3. Manufacturing: Start mass production by Q4 2024.
  4. Market Entry: Launch the product by Q1 2025.
  5. Market Penetration: Achieve a 5% market share by Q4 2025.

Timeline:

  1. Q2 2024: Finalise the laptop stand design.
  2. Q3 2024: Conduct prototype testing.
  3. Q4 2024: Start mass production.
  4. Q1 2025: Launch the product in the market.
  5. Q4 2025: Achieve a 5% market share.
Categories
AI Agents

Crew AI Application Generator

import os, json
from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from langchain_community.llms import Ollama
from langchain_mistralai.chat_models import ChatMistralAI
from langchain_google_vertexai import VertexAI
from tempfile import TemporaryDirectory
from langchain_community.agent_toolkits import FileManagementToolkit
from langchain.tools import tool
from langchain.pydantic_v1 import BaseModel, Field

class FileManagerTools:
    @tool("Write code to disk")
    def write_file(self, code):
        """Write code to disk. Input is code as a string."""
        print(code)
        with open("output.py", "w") as file:
            file.write(code)
        return "File written successfully."

# Create FileManagerTools instance
file_manager_tools = FileManagerTools()
mistral_api_key = os.environ.get("MISTRAL_API_KEY")
working_directory = TemporaryDirectory()
toolkit = FileManagementToolkit(
    root_dir=str(working_directory.name),
    selected_tools=["write_file", "list_directory"]
)
write_file_tool, list_directory_tool = toolkit.get_tools()

# Create Agents
coder = Agent(
  role='Software Engineer',
  goal='Develop innovative software solutions',
  backstory='A skilled software engineer who writes python code.',
  verbose=True,
  allow_delegation=False,
)

files_manager = Agent(
    role='File Manager',
    goal='Efficiently manage and save files',
    backstory='Specialized in organizing and storing files securely and accessibly.',
    verbose=True,
    allow_delegation=False,
    tools=[file_manager_tools.write_file]
)

# Create Tasks
software_development_task = Task(
  description='Write python code for a Flask application to find the stock of a company using yfinance',
  agent=coder
)

files_management_task = Task(
  description='Save received python code from coder in a file',
  agent=files_manager,
  tools=[file_manager_tools.write_file]
)

# Create Crew
tech_crew = Crew(
  agents=[coder, files_manager],
  tasks=[software_development_task, files_management_task],
  process=Process.sequential  # Sequential task execution
)

# Execute tasks
result = tech_crew.kickoff()
print(result)
Categories
AI Agents

Crew AI LinkedIn Post Creator

pip install langchain-community langchain crewai langchain-openai langchain-core langchain-google-vertexai langchain_mistralai
export MISTRAL_API_KEY=xxxxxxx
export AZURE_OPENAI_DEPLOYMENT=xxxxx
export AZURE_OPENAI_ENDPOINT=https://<your-endpoint>.openai.azure.com/
export AZURE_OPENAI_KEY=xxxxxxxxxx
import os
from crewai import Agent, Task, Crew, Process
from langchain_mistralai.chat_models import ChatMistralAI
from langchain_google_vertexai import VertexAI
from langchain_openai import AzureChatOpenAI
from langchain.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

mistral_api_key = os.environ.get("MISTRAL_API_KEY")
llm_mistral = ChatMistralAI(mistral_api_key=mistral_api_key, model="mistral-medium")
llm_vertex = VertexAI(model_name="gemini-pro")
llm_azure = AzureChatOpenAI(
    openai_api_version= "2023-07-01-preview",
    azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT", "openai"),
    azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT", "https://<your-endpoint>.openai.azure.com/"),
    api_key=os.environ.get("AZURE_OPENAI_KEY")
)

# Create Agents
coach = Agent(
    role='Senior Career Coach',
    goal="Discover and examine key tech and AI career skills for 2024",
    backstory="You're an expert in spotting new trends and essential skills in AI and technology.",
    verbose=True,
    allow_delegation=False,
    tools=[search_tool],
    llm=llm_vertex
)

influencer = Agent(
    role='LinkedIn Influencer Writer',
    goal="Write catchy, emoji-filled LinkedIn posts within 200 words",
    backstory="You're a specialised writer on LinkedIn, focusing on AI and technology.",
    verbose=True,
    allow_delegation=True,
    llm=llm_mistral
)

critic = Agent(
    role='Expert Writing Critic',
    goal="Give constructive feedback on post drafts",
    backstory="You're skilled in offering straightforward, effective advice to tech writers. Ensure posts are concise, under 200 words, with emojis and hashtags.",
    verbose=True,
    allow_delegation=True,
    llm=llm_azure
)

# Create Tasks
task_search = Task(
    description="Compile a report listing at least 5 new AI and tech skills, presented in bullet points",
    agent=coach
)

task_post = Task(
    description="Create a LinkedIn post with a brief headline and a maximum of 200 words, focusing on upcoming AI and tech skills",
    agent=influencer
)

task_critique = Task(
    description="Refine the post for brevity, ensuring an engaging headline (no more than 30 characters) and keeping within a 200-word limit",
    agent=critic
)

# Create Crew
crew = Crew(
    agents=[coach, influencer, critic],
    tasks=[task_search, task_post, task_critique],
    verbose=2,
    process=Process.sequential 
)

# Get your crew to work!
result = crew.kickoff()

print("#############")
print(result)
Categories
AI Agents

Crew AI Open Source Agents

pip install langchain-community langchain crewai langchain-openai duckduckgo-search

Open Source

from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from langchain_community.llms import Ollama
from langchain_community.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

llm_lmstudio = ChatOpenAI(
    openai_api_base="http://localhost:1234/v1",
    openai_api_key="",                 
    model_name="mistral"
)

llm_janai = ChatOpenAI(
    openai_api_base="http://localhost:1337/v1",
    openai_api_key="",                 
    model_name="mistral-ins-7b-q4"
)

llm_ollama = Ollama(model="orca2")

llm_textgen = ChatOpenAI(
    openai_api_base="http://localhost:5001/v1",
    openai_api_key="",                 
    model_name="openhermes"
)

# Create a researcher agent
researcher = Agent(
  role='Senior Researcher',
  goal='Discover groundbreaking technologies',
  backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.',
  verbose=True,
  tools=[search_tool],
  allow_delegation=False,
  llm=llm_lmstudio
)

insight_researcher = Agent(
  role='Insight Researcher',
  goal='Discover Key Insights',
  backstory='You are able to find key insights from the data you are given.',
  verbose=True,
  allow_delegation=False,
  llm=llm_janai
)

writer = Agent(
  role='Tech Content Strategist',
  goal='Craft compelling content on tech advancements',
  backstory="""You are a content strategist known for 
  making complex tech topics interesting and easy to understand.""",
  verbose=True,
  allow_delegation=False,
  llm=llm_ollama
)

formater = Agent(
  role='Markdown Formater',
  goal='Format the text in markdown',
  backstory='You are able to convert the text into markdown format',
  verbose=True,
  allow_delegation=False,
  llm=llm_textgen
)

# Tasks
research_task = Task(
  description='Identify the next big trend in AI by searching internet',
  agent=researcher
)

insights_task = Task(
  description='Identify few key insights from the data in points format. Dont use any tool',
  agent=insight_researcher
)

writer_task = Task(
  description='Write a short blog post with sub headings. Dont use any tool',
  agent=writer
)

format_task = Task(
  description='Convert the text into markdown format. Dont use any tool',
  agent=formater
)

# Instantiate your crew
tech_crew = Crew(
  agents=[researcher, insight_researcher, writer, formater],
  tasks=[research_task, insights_task, writer_task, format_task],
  process=Process.sequential  # Tasks will be executed one after the other
)

# Begin the task execution
result = tech_crew.kickoff()
print(result)

OpenAI

from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from langchain_community.llms import Ollama
from langchain_community.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

# Create a researcher agent
researcher = Agent(
  role='Senior Researcher',
  goal='Discover groundbreaking technologies',
  backstory='A curious mind fascinated by cutting-edge innovation and the potential to change the world, you know everything about tech.',
  verbose=True,
  tools=[search_tool],
  allow_delegation=False,
)

insight_researcher = Agent(
  role='Insight Researcher',
  goal='Discover Key Insights',
  backstory='You are able to find key insights from the data you are given.',
  verbose=True,
  allow_delegation=False,
)

writer = Agent(
  role='Tech Content Strategist',
  goal='Craft compelling content on tech advancements',
  backstory="""You are a content strategist known for 
  making complex tech topics interesting and easy to understand.""",
  verbose=True,
  allow_delegation=False,
)

formater = Agent(
  role='Markdown Formater',
  goal='Format the text in markdown',
  backstory='You are able to convert the text into markdown format',
  verbose=True,
  allow_delegation=False,
)

# Tasks
research_task = Task(
  description='Identify the next big trend in AI by searching internet once',
  agent=researcher
)

insight_task = Task(
  description='Find key insights from the data. Dont use any tool',
  agent=insight_researcher
)

write_task = Task(
  description='Write a blog post. Dont use any tool',
  agent=writer
)

format_task = Task(
  description='convert the input to markdown format',
  agent=formater
)

# Instantiate a crew
tech_crew = Crew(
  agents=[researcher, insight_researcher, writer, formater],
  tasks=[research_task, insight_task, write_task, format_task],
  process=Process.sequential  # Tasks will be executed one after the other
)

# Begin the task execution
result = tech_crew.kickoff()
print(result)

Text Generation Web UI

bash start_macos.sh --api --listen --extensions openai --trust-remote-code
Categories
Tools

Mixtral Pricing Compare

prices and providers launch Mixtral with (prices below are quoted as ($ per million tokens input / $ per million tokens output):

Categories
AI Agents

Crew AI Instagram Post

git clone https://github.com/joaomdmoura/crewAI-examples
cd crewAI-examples
cd instagram_post
conda create -n crewai python=3.11 -y
conda activate crewai
export OPENAI_API_KEY=st-xxxxxxxxxxxxxxxxxxxxx
pip install poetry platformdirs
poetry install --no-root
poetry run python main.py
Categories
AI Agents

Crew AI Stock Analysis

git clone https://github.com/joaomdmoura/crewAI-examples
cd crewAI-examples
cd stock_analysis
conda create -n crewai python=3.11 -y
conda activate crewai
pip install poetry platformdirs
poetry install --no-root
poetry run python main.py

Code fix as in the video

/Users/USER/miniconda3/envs/creawai/lib/python3.11/site-packages/langchain_community/tools/yahoo_finance_news.py

@staticmethod
    def _format_results(docs: Iterable[Document], query: str) -> str:
        doc_strings = [
            "\n".join([doc.metadata["title"], doc.metadata.get("description", "")])
            for doc in docs
            if query in doc.metadata.get("description", "") or query in doc.metadata["title"]
        ]
        return "\n\n".join(doc_strings)
Categories
AI Agents

Crew AI Travel Agents

git clone https://github.com/joaomdmoura/crewAI-examples
cd crewAI-examples
cd trip_planner
conda create -n crewai python=3.11 -y
conda activate crewai
pip install poetry platformdirs
poetry install --no-root
poetry run python main.py
Categories
Tools

CrewAI Example Code

openai

export OPENAI_API_KEY=xxxxxxxxxxxxxxxxx
import os
from crewai import Agent, Task, Crew, Process
from langchain.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

# Define your agents with roles and goals
researcher = Agent(
  role='Senior Research Analyst',
  goal='Uncover cutting-edge developments in AI and data science',
  backstory="""You are an expert at a technology research group, 
  skilled in identifying trends and analyzing complex data.""",
  verbose=True,
  allow_delegation=False,
  tools=[search_tool]
)
writer = Agent(
  role='Tech Content Strategist',
  goal='Craft compelling content on tech advancements',
  backstory="""You are a content strategist known for 
  making complex tech topics interesting and easy to understand.""",
  verbose=True,
  allow_delegation=True,
)

# Create tasks for your agents
task1 = Task(
  description="""Analyze 2024's AI advancements. 
  Find major trends, new technologies, and their effects. 
  Provide a detailed report.""",
  agent=researcher
)

task2 = Task(
  description="""Create a blog post about major AI advancements using your insights. 
  Make it interesting, clear, and suited for tech enthusiasts. 
  It should be at least 4 paragraphs long.""",
  agent=writer
)

# Instantiate your crew with a sequential process
crew = Crew(
  agents=[researcher, writer],
  tasks=[task1, task2],
  verbose=2
)

# Get your crew to work!
result = crew.kickoff()

print("######################")
print(result)

Ollama

import os
from crewai import Agent, Task, Crew, Process
from langchain.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()
from langchain.llms import Ollama
ollama_llm = Ollama(model="mistral")
ollama_llm_orca2 = Ollama(model="orca2")

# Define your agents with roles and goals
researcher = Agent(
  role='Senior Research Analyst',
  goal='Uncover cutting-edge developments in AI and data science',
  backstory="""You are an expert at a technology research group, 
  skilled in identifying trends and analyzing complex data.""",
  verbose=True,
  allow_delegation=False,
  tools=[search_tool],
  llm=ollama_llm
)
writer = Agent(
    role='Tech Content Strategist',
    goal='Craft compelling content on tech advancements',
    backstory="""You are a content strategist known for 
    making complex tech topics interesting and easy to understand.""",
    verbose=True,
    allow_delegation=True,
    llm=ollama_llm_orca2
)

# Create tasks for your agents
task1 = Task(
  description="""Analyze 2024's AI advancements. 
  Find major trends, new technologies, and their effects. 
  Provide a detailed report.""",
  agent=researcher
)

task2 = Task(
    description="""Create a blog post about major AI advancements using your insights. 
    Make it interesting, clear, and suited for tech enthusiasts. 
    It should be at least 4 paragraphs long.""",
    agent=writer
)

# Instantiate your crew with a sequential process
crew = Crew(
    agents=[researcher, writer],
    tasks=[task1, task2],
    verbose=2
)

# Get your crew to work!
result = crew.kickoff()

print("######################")
print(result)